@@ -6,6 +6,7 @@ import Modal from "react-modal";
6
6
import * as ariaAppHider from "react-modal/helpers/ariaAppHider" ;
7
7
import {
8
8
isBodyWithReactModalOpenClass ,
9
+ isHtmlWithReactModalOpenClass ,
9
10
contentAttribute ,
10
11
mcontent ,
11
12
moverlay ,
@@ -253,32 +254,49 @@ export default () => {
253
254
( document . body . className . indexOf ( "custom-modal-open" ) > - 1 ) . should . be . ok ( ) ;
254
255
} ) ;
255
256
256
- it ( "don't append class to document.body if modal is not open" , ( ) => {
257
+ it ( "supports overriding react modal open class in html." , ( ) => {
258
+ renderModal ( { isOpen : true , htmlOpenClassName : "custom-modal-open" } ) ;
259
+ (
260
+ document
261
+ . getElementsByTagName ( "html" ) [ 0 ]
262
+ . className . indexOf ( "custom-modal-open" ) > - 1
263
+ ) . should . be . ok ( ) ;
264
+ } ) ;
265
+
266
+ // eslint-disable-next-line max-len
267
+ it ( "don't append class to document.body and html if modal is not open" , ( ) => {
257
268
renderModal ( { isOpen : false } ) ;
258
269
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
270
+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
259
271
unmountModal ( ) ;
260
272
} ) ;
261
273
262
- it ( "append class to document.body if modal is open" , ( ) => {
274
+ it ( "append class to document.body and html if modal is open" , ( ) => {
263
275
renderModal ( { isOpen : true } ) ;
264
276
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
277
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
265
278
unmountModal ( ) ;
266
279
} ) ;
267
280
268
- it ( "removes class from document.body when unmounted without closing" , ( ) => {
281
+ // eslint-disable-next-line max-len
282
+ it ( "removes class from document.body and html when unmounted without closing" , ( ) => {
269
283
renderModal ( { isOpen : true } ) ;
270
284
unmountModal ( ) ;
271
285
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
286
+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
272
287
} ) ;
273
288
274
- it ( "remove class from document.body when no modals opened" , ( ) => {
289
+ it ( "remove class from document.body and html when no modals opened" , ( ) => {
275
290
renderModal ( { isOpen : true } ) ;
276
291
renderModal ( { isOpen : true } ) ;
277
292
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
293
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
278
294
unmountModal ( ) ;
279
295
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
296
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
280
297
unmountModal ( ) ;
281
298
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
299
+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
282
300
} ) ;
283
301
284
302
it ( "supports adding/removing multiple document.body classes" , ( ) => {
@@ -328,6 +346,59 @@ export default () => {
328
346
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
329
347
} ) ;
330
348
349
+ it ( "supports adding/removing multiple html classes" , ( ) => {
350
+ renderModal ( {
351
+ isOpen : true ,
352
+ htmlOpenClassName : "A B C"
353
+ } ) ;
354
+ document
355
+ . getElementsByTagName ( "html" ) [ 0 ]
356
+ . classList . contains ( "A" , "B" , "C" )
357
+ . should . be . ok ( ) ;
358
+ unmountModal ( ) ;
359
+ document
360
+ . getElementsByTagName ( "html" ) [ 0 ]
361
+ . classList . contains ( "A" , "B" , "C" )
362
+ . should . not . be . ok ( ) ;
363
+ } ) ;
364
+
365
+ it ( "does not remove shared classes if more than one modal is open" , ( ) => {
366
+ renderModal ( {
367
+ isOpen : true ,
368
+ htmlOpenClassName : "A"
369
+ } ) ;
370
+ renderModal ( {
371
+ isOpen : true ,
372
+ htmlOpenClassName : "A B"
373
+ } ) ;
374
+
375
+ isHtmlWithReactModalOpenClass ( "A B" ) . should . be . ok ( ) ;
376
+ unmountModal ( ) ;
377
+ isHtmlWithReactModalOpenClass ( "A B" ) . should . not . be . ok ( ) ;
378
+ isHtmlWithReactModalOpenClass ( "A" ) . should . be . ok ( ) ;
379
+ unmountModal ( ) ;
380
+ isHtmlWithReactModalOpenClass ( "A" ) . should . not . be . ok ( ) ;
381
+ } ) ;
382
+
383
+ it ( "should not add classes to html for unopened modals" , ( ) => {
384
+ renderModal ( { isOpen : true } ) ;
385
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
386
+ renderModal ( { isOpen : false , htmlOpenClassName : "testHtmlClass" } ) ;
387
+ isHtmlWithReactModalOpenClass ( "testHtmlClass" ) . should . not . be . ok ( ) ;
388
+ } ) ;
389
+
390
+ it ( "should not remove classes from html if modal is closed" , ( ) => {
391
+ renderModal ( { isOpen : true } ) ;
392
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
393
+ renderModal ( { isOpen : false , htmlOpenClassName : "testHtmlClass" } ) ;
394
+ renderModal ( { isOpen : false } ) ;
395
+ isHtmlWithReactModalOpenClass ( "testHtmlClass" ) . should . not . be . ok ( ) ;
396
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
397
+ renderModal ( { isOpen : false } ) ;
398
+ renderModal ( { isOpen : false } ) ;
399
+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
400
+ } ) ;
401
+
331
402
it ( "additional aria attributes" , ( ) => {
332
403
const modal = renderModal (
333
404
{ isOpen : true , aria : { labelledby : "a" } } ,
0 commit comments