File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,45 @@ describe('Drawer', () => {
215
215
} ) ;
216
216
} ) ;
217
217
218
+ it ( 'calls onRequestClose when closeOnOverlayClick is not defined' , async ( ) => {
219
+ const onRequestClose = jest . fn ( ) ;
220
+
221
+ const { container } = render (
222
+ < SetupDrawerWithChildren
223
+ visible
224
+ onRequestClose = { onRequestClose }
225
+ /> ,
226
+ ) ;
227
+
228
+ const [ overlay ] = Array . from ( container . getElementsByClassName ( 'DrawerBackgroundOverlay' ) ) ;
229
+
230
+ userEvent . click ( overlay ) ;
231
+
232
+ await waitFor ( ( ) => {
233
+ expect ( onRequestClose ) . toHaveBeenCalled ( ) ;
234
+ } ) ;
235
+ } ) ;
236
+
237
+ it ( 'does not call onRequestClose when closeOnOverlayClick is set to false' , async ( ) => {
238
+ const onRequestClose = jest . fn ( ) ;
239
+
240
+ const { container } = render (
241
+ < SetupDrawerWithChildren
242
+ closeOnOverlayClick = { false }
243
+ visible
244
+ onRequestClose = { onRequestClose }
245
+ /> ,
246
+ ) ;
247
+
248
+ const [ overlay ] = Array . from ( container . getElementsByClassName ( 'DrawerBackgroundOverlay' ) ) ;
249
+
250
+ userEvent . click ( overlay ) ;
251
+
252
+ await waitFor ( ( ) => {
253
+ expect ( onRequestClose ) . not . toHaveBeenCalled ( ) ;
254
+ } ) ;
255
+ } ) ;
256
+
218
257
it ( 'body tag has Drawer--open' , ( ) => {
219
258
const { container } = render ( < SetupDrawerWithChildren visible /> ) ;
220
259
const body = container . closest ( 'body' ) ;
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ type DrawerProps = {
28
28
behindNav ?: boolean ;
29
29
children ?: React . ReactNode ;
30
30
className ?: string ;
31
+ closeOnOverlayClick ?: boolean ;
31
32
defaultExpanded ?: boolean ;
32
33
expandable ?: boolean ;
33
34
hasBackgroundOverlay ?: boolean ;
@@ -42,6 +43,7 @@ function Drawer({
42
43
children,
43
44
className = '' ,
44
45
defaultExpanded = false ,
46
+ closeOnOverlayClick = true ,
45
47
expandable = false ,
46
48
hasBackgroundOverlay = true ,
47
49
visible,
@@ -122,7 +124,7 @@ function Drawer({
122
124
} )
123
125
}
124
126
role = "presentation"
125
- onClick = { onRequestClose }
127
+ onClick = { closeOnOverlayClick ? onRequestClose : undefined }
126
128
onKeyDown = { handleEscKeyPress }
127
129
/>
128
130
)
You can’t perform that action at this time.
0 commit comments