File tree 2 files changed +15
-34
lines changed
2 files changed +15
-34
lines changed Original file line number Diff line number Diff line change @@ -349,30 +349,6 @@ describe('functionality', () => {
349
349
assertFocus ( el , true ) ;
350
350
} ) ;
351
351
352
- it ( 'traps focus' , async ( ) => {
353
- const { container } = render ( (
354
- < Modal >
355
- < ModalBody >
356
- < ModalContent >
357
- < input id = "first" />
358
- < input id = "second" />
359
- </ ModalContent >
360
- </ ModalBody >
361
- </ Modal >
362
- ) ) ;
363
-
364
- const firstEl = within ( container ) . getByTestId ( 'first' ) ;
365
- const secondEl = within ( container ) . getByTestId ( 'second' ) ;
366
-
367
- assertFocus ( firstEl , true ) ;
368
- await userEvent . tab ( ) ;
369
- assertFocus ( secondEl , true ) ;
370
- await userEvent . tab ( ) ;
371
- assertFocus ( firstEl , true ) ;
372
- await userEvent . tab ( { shift : true } ) ;
373
- assertFocus ( secondEl , true ) ;
374
- } ) ;
375
-
376
352
it ( 'prevents body from scrolling by default' , ( ) => {
377
353
render ( (
378
354
< Modal />
Original file line number Diff line number Diff line change @@ -5,19 +5,24 @@ export const dialogOnKeyDownHandler = (
5
5
allowCloseOnEscapeKey ,
6
6
allowPrimaryActionOnEnterKey ,
7
7
) => {
8
- // Prevent closing the modal using the Escape key when one of the following conditions is met:
9
- // 1. The close button is not present
10
- // 2. The close button is disabled
11
- // 3. `allowCloseOnEscapeKey` is set to `false`
12
- if (
13
- e . key === 'Escape'
14
- && (
8
+ if ( e . key === 'Escape' ) {
9
+ // Prevent closing the modal using the Escape key when one of the following conditions is met:
10
+ // 1. The close button is not present
11
+ // 2. The close button is disabled
12
+ // 3. `allowCloseOnEscapeKey` is set to `false`
13
+ //
14
+ // ⚠️ Else-if statement calling `closeButtonRef.current.click()` is necessary due to missing support
15
+ // of close event in happy-dom library. When this is fixed, the `else` statement can be removed
16
+ // as the `closeButtonRef.current.click()` will be handled by `dialogOnCancelHandler.js`.
17
+ if (
15
18
closeButtonRef ?. current == null
16
19
|| closeButtonRef ?. current ?. disabled === true
17
20
|| ! allowCloseOnEscapeKey
18
- )
19
- ) {
20
- e . preventDefault ( ) ;
21
+ ) {
22
+ e . preventDefault ( ) ;
23
+ } else if ( process ?. env ?. NODE_ENV === 'test' ) {
24
+ closeButtonRef . current . click ( ) ;
25
+ }
21
26
}
22
27
23
28
// Trigger the primary action when the Enter key is pressed and the following conditions are met:
You can’t perform that action at this time.
0 commit comments