@@ -47,6 +47,10 @@ export interface ModalProps extends HTMLAttributes<HTMLDivElement> {
47
47
* Modal does not have a max width.
48
48
*/
49
49
fullWidth ?: boolean ;
50
+ /**
51
+ * Do not unmount the modal when it is closed.
52
+ */
53
+ noUnmount ?: boolean ;
50
54
/**
51
55
* Class for the outermost wrapper
52
56
*/
@@ -71,6 +75,7 @@ export const Modal: FC<ModalProps> = ({
71
75
open,
72
76
onClose,
73
77
fullWidth,
78
+ noUnmount,
74
79
wrapperClassName,
75
80
closeLabel = 'Close' ,
76
81
children,
@@ -82,6 +87,8 @@ export const Modal: FC<ModalProps> = ({
82
87
} ) => {
83
88
const { mounted } = useUnmountDelay ( open ) ;
84
89
90
+ const unlocked = noUnmount && ! mounted ;
91
+
85
92
const headingId = useMemo ( ( ) => getStringId ( 'modal_heading' ) , [ ] ) ;
86
93
const bodyId = useMemo ( ( ) => getStringId ( 'modal_body' ) , [ ] ) ;
87
94
@@ -96,7 +103,7 @@ export const Modal: FC<ModalProps> = ({
96
103
return ;
97
104
} , [ closeOnEscape , onClose , open ] ) ;
98
105
99
- const backgroundIsButton = ! ! ( closeOnBackgroundClick && onClose ) ;
106
+ const backgroundIsButton = ! ! ( open && closeOnBackgroundClick && onClose ) ;
100
107
101
108
const modalWrapperClass = classnames (
102
109
'ui__base ui__modal__wrapper' ,
@@ -107,7 +114,13 @@ export const Modal: FC<ModalProps> = ({
107
114
wrapperClassName ,
108
115
) ;
109
116
110
- const modalClass = classnames ( 'ui__modal' , className ) ;
117
+ const modalClass = classnames (
118
+ 'ui__modal' ,
119
+ {
120
+ 'ui__modal--hidden' : unlocked ,
121
+ } ,
122
+ className ,
123
+ ) ;
111
124
112
125
const bodyClass = classnames ( 'ui__modal__body' , {
113
126
'ui__modal__body--noButton' : ! buttonGroup ,
@@ -120,9 +133,9 @@ export const Modal: FC<ModalProps> = ({
120
133
className = { modalWrapperClass }
121
134
onClick = { backgroundIsButton ? onClose : undefined }
122
135
>
123
- { mounted ? (
136
+ { noUnmount || mounted ? (
124
137
< div className = "ui__modal__paddingFix" >
125
- < FocusTrap focusLastOnUnlock locked >
138
+ < FocusTrap focusLastOnUnlock locked = { ! unlocked } >
126
139
< div
127
140
aria-labelledby = { heading ? headingId : undefined }
128
141
aria-describedby = { bodyId }
0 commit comments