@@ -7,6 +7,7 @@ import * as ariaAppHider from "react-modal/helpers/ariaAppHider";
77import {
88 isBodyWithReactModalOpenClass ,
99 isHtmlWithReactModalOpenClass ,
10+ htmlClassList ,
1011 contentAttribute ,
1112 mcontent ,
1213 moverlay ,
@@ -254,46 +255,45 @@ export default () => {
254255 ( document . body . className . indexOf ( "custom-modal-open" ) > - 1 ) . should . be . ok ( ) ;
255256 } ) ;
256257
257- it ( "supports overriding react modal open class in html." , ( ) => {
258+ it ( "supports setting react modal open class in < html /> ." , ( ) => {
258259 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 ( ) ;
264261 } ) ;
265262
266263 // 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. " , ( ) => {
268265 renderModal ( { isOpen : false } ) ;
269266 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" } ) ;
270271 isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
271- unmountModal ( ) ;
272272 } ) ;
273273
274- it ( "append class to document.body and html if modal is open" , ( ) => {
274+ it ( "append class to document.body if modal is open. " , ( ) => {
275275 renderModal ( { isOpen : true } ) ;
276276 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 ( ) ;
279282 } ) ;
280283
281284 // 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" , ( ) => {
283286 renderModal ( { isOpen : true } ) ;
284287 unmountModal ( ) ;
285288 isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
286- isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
287289 } ) ;
288290
289- it ( "remove class from document.body and html when no modals opened" , ( ) => {
291+ it ( "remove class from document.body when no modals opened" , ( ) => {
290292 renderModal ( { isOpen : true } ) ;
291293 renderModal ( { isOpen : true } ) ;
292294 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
293- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
294295 unmountModal ( ) ;
295296 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
296- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
297297 unmountModal ( ) ;
298298 isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
299299 isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
@@ -346,57 +346,18 @@ export default () => {
346346 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
347347 } ) ;
348348
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 ( {
371353 isOpen : true ,
372- htmlOpenClassName : "A B "
354+ htmlOpenClassName : "testHtmlClass "
373355 } ) ;
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 ( ) ;
398360 renderModal ( { isOpen : false } ) ;
399- isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
400361 } ) ;
401362
402363 it ( "additional aria attributes" , ( ) => {
0 commit comments