@@ -6,6 +6,7 @@ import Modal from "react-modal";
66import * as ariaAppHider from "react-modal/helpers/ariaAppHider" ;
77import {
88 isBodyWithReactModalOpenClass ,
9+ isHtmlWithReactModalOpenClass ,
910 contentAttribute ,
1011 mcontent ,
1112 moverlay ,
@@ -253,32 +254,49 @@ export default () => {
253254 ( document . body . className . indexOf ( "custom-modal-open" ) > - 1 ) . should . be . ok ( ) ;
254255 } ) ;
255256
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" , ( ) => {
257268 renderModal ( { isOpen : false } ) ;
258269 isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
270+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
259271 unmountModal ( ) ;
260272 } ) ;
261273
262- it ( "append class to document.body if modal is open" , ( ) => {
274+ it ( "append class to document.body and html if modal is open" , ( ) => {
263275 renderModal ( { isOpen : true } ) ;
264276 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
277+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
265278 unmountModal ( ) ;
266279 } ) ;
267280
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" , ( ) => {
269283 renderModal ( { isOpen : true } ) ;
270284 unmountModal ( ) ;
271285 isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
286+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
272287 } ) ;
273288
274- it ( "remove class from document.body when no modals opened" , ( ) => {
289+ it ( "remove class from document.body and html when no modals opened" , ( ) => {
275290 renderModal ( { isOpen : true } ) ;
276291 renderModal ( { isOpen : true } ) ;
277292 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
293+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
278294 unmountModal ( ) ;
279295 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
296+ isHtmlWithReactModalOpenClass ( ) . should . be . ok ( ) ;
280297 unmountModal ( ) ;
281298 isBodyWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
299+ isHtmlWithReactModalOpenClass ( ) . should . not . be . ok ( ) ;
282300 } ) ;
283301
284302 it ( "supports adding/removing multiple document.body classes" , ( ) => {
@@ -328,6 +346,59 @@ export default () => {
328346 isBodyWithReactModalOpenClass ( ) . should . be . ok ( ) ;
329347 } ) ;
330348
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+
331402 it ( "additional aria attributes" , ( ) => {
332403 const modal = renderModal (
333404 { isOpen : true , aria : { labelledby : "a" } } ,
0 commit comments