@@ -7,6 +7,7 @@ import * as ariaAppHider from "react-modal/helpers/ariaAppHider";
7
7
import {
8
8
isBodyWithReactModalOpenClass ,
9
9
isHtmlWithReactModalOpenClass ,
10
+ htmlClassList ,
10
11
contentAttribute ,
11
12
mcontent ,
12
13
moverlay ,
@@ -254,46 +255,45 @@ export default () => {
254
255
( document . body . className . indexOf ( "custom-modal-open" ) > - 1 ) . should . be . ok ( ) ;
255
256
} ) ;
256
257
257
- it ( "supports overriding react modal open class in html." , ( ) => {
258
+ it ( "supports setting react modal open class in < html /> ." , ( ) => {
258
259
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 ( ) ;
260
+ isHtmlWithReactModalOpenClass ( "custom-modal-open" ) . should . be . ok ( ) ;
264
261
} ) ;
265
262
266
263
// eslint-disable-next-line max-len
267
- it ( "don't append class to document.body and html if modal is not open " , ( ) => {
264
+ it ( "don't append class to document.body if modal is closed. " , ( ) => {
268
265
renderModal ( { isOpen : false } ) ;
269
266
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
267
+ } ) ;
268
+
269
+ it ( "don't append class to <html /> if modal is closed." , ( ) => {
270
+ renderModal ( { isOpen : false , htmlOpenClassName : "custom-modal-open" } ) ;
270
271
isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
271
- unmountModal ( ) ;
272
272
} ) ;
273
273
274
- it ( "append class to document.body and html if modal is open" , ( ) => {
274
+ it ( "append class to document.body if modal is open. " , ( ) => {
275
275
renderModal ( { isOpen : true } ) ;
276
276
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
277
- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
278
- unmountModal ( ) ;
277
+ } ) ;
278
+
279
+ it ( "don't append class to <html /> if not defined." , ( ) => {
280
+ renderModal ( { isOpen : true } ) ;
281
+ htmlClassList ( ) . should . be . empty ( ) ;
279
282
} ) ;
280
283
281
284
// eslint-disable-next-line max-len
282
- it ( "removes class from document.body and html when unmounted without closing" , ( ) => {
285
+ it ( "removes class from document.body when unmounted without closing" , ( ) => {
283
286
renderModal ( { isOpen : true } ) ;
284
287
unmountModal ( ) ;
285
288
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
286
- isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
287
289
} ) ;
288
290
289
- it ( "remove class from document.body and html when no modals opened" , ( ) => {
291
+ it ( "remove class from document.body when no modals opened" , ( ) => {
290
292
renderModal ( { isOpen : true } ) ;
291
293
renderModal ( { isOpen : true } ) ;
292
294
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
293
- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
294
295
unmountModal ( ) ;
295
296
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
296
- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
297
297
unmountModal ( ) ;
298
298
isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
299
299
isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
@@ -346,57 +346,18 @@ export default () => {
346
346
isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
347
347
} ) ;
348
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 ( {
349
+ it ( "should not remove classes from <html /> if modal is closed" , ( ) => {
350
+ const modalA = renderModal ( { isOpen : false } ) ;
351
+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
352
+ const modalB = renderModal ( {
371
353
isOpen : true ,
372
- htmlOpenClassName : "A B "
354
+ htmlOpenClassName : "testHtmlClass "
373
355
} ) ;
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 } ) ;
356
+ modalA . portal . close ( ) ;
357
+ isHtmlWithReactModalOpenClass ( "testHtmlClass" ) . should . be . ok ( ) ;
358
+ modalB . portal . close ( ) ;
359
+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
398
360
renderModal ( { isOpen : false } ) ;
399
- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
400
361
} ) ;
401
362
402
363
it ( "additional aria attributes" , ( ) => {
0 commit comments