@@ -16,7 +16,7 @@ import {
16
16
} from "./helper" ;
17
17
18
18
export default ( ) => {
19
- afterEach ( "check if test cleaned up rendered modals" , emptyDOM ) ;
19
+ afterEach ( "cleaned up all rendered modals" , emptyDOM ) ;
20
20
21
21
it ( "scopes tab navigation to the modal" ) ;
22
22
it ( "focuses the last focused element when tabbing in from browser chrome" ) ;
@@ -352,6 +352,104 @@ export default () => {
352
352
should ( el . getAttribute ( "aria-hidden" ) ) . not . be . ok ( ) ;
353
353
} ) ;
354
354
355
+ // eslint-disable-next-line max-len
356
+ it ( "removes aria-hidden when closed and another modal with ariaHideApp set to false is open" , ( ) => {
357
+ const rootNode = document . createElement ( "div" ) ;
358
+ document . body . appendChild ( rootNode ) ;
359
+
360
+ const appElement = document . createElement ( "div" ) ;
361
+ document . body . appendChild ( appElement ) ;
362
+
363
+ Modal . setAppElement ( appElement ) ;
364
+
365
+ const initialState = (
366
+ < div >
367
+ < Modal isOpen = { true } ariaHideApp = { false } id = "test-1-modal-1" />
368
+ < Modal isOpen = { true } ariaHideApp = { true } id = "test-1-modal-2" />
369
+ </ div >
370
+ ) ;
371
+
372
+ ReactDOM . render ( initialState , rootNode ) ;
373
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
374
+
375
+ const updatedState = (
376
+ < div >
377
+ < Modal isOpen = { true } ariaHideApp = { false } id = "test-1-modal-1" />
378
+ < Modal isOpen = { false } ariaHideApp = { true } id = "test-1-modal-2" />
379
+ </ div >
380
+ ) ;
381
+
382
+ ReactDOM . render ( updatedState , rootNode ) ;
383
+ should ( appElement . getAttribute ( "aria-hidden" ) ) . not . be . ok ( ) ;
384
+
385
+ ReactDOM . unmountComponentAtNode ( rootNode ) ;
386
+ } ) ;
387
+
388
+ // eslint-disable-next-line max-len
389
+ it ( "maintains aria-hidden when closed and another modal with ariaHideApp set to true is open" , ( ) => {
390
+ const rootNode = document . createElement ( "div" ) ;
391
+ document . body . appendChild ( rootNode ) ;
392
+
393
+ const appElement = document . createElement ( "div" ) ;
394
+ document . body . appendChild ( appElement ) ;
395
+
396
+ Modal . setAppElement ( appElement ) ;
397
+
398
+ const initialState = (
399
+ < div >
400
+ < Modal isOpen = { true } ariaHideApp = { true } id = "test-1-modal-1" />
401
+ < Modal isOpen = { true } ariaHideApp = { true } id = "test-1-modal-2" />
402
+ </ div >
403
+ ) ;
404
+
405
+ ReactDOM . render ( initialState , rootNode ) ;
406
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
407
+
408
+ const updatedState = (
409
+ < div >
410
+ < Modal isOpen = { true } ariaHideApp = { true } id = "test-1-modal-1" />
411
+ < Modal isOpen = { false } ariaHideApp = { true } id = "test-1-modal-2" />
412
+ </ div >
413
+ ) ;
414
+
415
+ ReactDOM . render ( updatedState , rootNode ) ;
416
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
417
+
418
+ ReactDOM . unmountComponentAtNode ( rootNode ) ;
419
+ } ) ;
420
+
421
+ // eslint-disable-next-line max-len
422
+ it ( "removes aria-hidden when unmounted without close and second modal with ariaHideApp=false is open" , ( ) => {
423
+ const appElement = document . createElement ( "div" ) ;
424
+ document . body . appendChild ( appElement ) ;
425
+ Modal . setAppElement ( appElement ) ;
426
+
427
+ renderModal ( { isOpen : true , ariaHideApp : false , id : "test-2-modal-1" } ) ;
428
+ should ( appElement . getAttribute ( "aria-hidden" ) ) . not . be . ok ( ) ;
429
+
430
+ renderModal ( { isOpen : true , ariaHideApp : true , id : "test-2-modal-2" } ) ;
431
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
432
+
433
+ unmountModal ( ) ;
434
+ should ( appElement . getAttribute ( "aria-hidden" ) ) . not . be . ok ( ) ;
435
+ } ) ;
436
+
437
+ // eslint-disable-next-line max-len
438
+ it ( "maintains aria-hidden when unmounted without close and second modal with ariaHideApp=true is open" , ( ) => {
439
+ const appElement = document . createElement ( "div" ) ;
440
+ document . body . appendChild ( appElement ) ;
441
+ Modal . setAppElement ( appElement ) ;
442
+
443
+ renderModal ( { isOpen : true , ariaHideApp : true , id : "test-3-modal-1" } ) ;
444
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
445
+
446
+ renderModal ( { isOpen : true , ariaHideApp : true , id : "test-3-modal-2" } ) ;
447
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
448
+
449
+ unmountModal ( ) ;
450
+ appElement . getAttribute ( "aria-hidden" ) . should . be . eql ( "true" ) ;
451
+ } ) ;
452
+
355
453
it ( "adds --after-open for animations" , ( ) => {
356
454
const modal = renderModal ( { isOpen : true } ) ;
357
455
const rg = / - - a f t e r - o p e n / i;
0 commit comments