1+ import warning from "warning" ;
2+
13let globalElement = null ;
24
35export function assertNodeList ( nodeList , selector ) {
@@ -19,42 +21,41 @@ export function setElement(element) {
1921 return globalElement ;
2022}
2123
22- export function tryForceFallback ( ) {
23- if ( document && document . body ) {
24- // force fallback to document.body
25- setElement ( document . body ) ;
26- return true ;
27- }
28- return false ;
29- }
30-
3124export function validateElement ( appElement ) {
32- if ( ! appElement && ! globalElement && ! tryForceFallback ( ) ) {
33- throw new Error (
25+ if ( ! appElement && ! globalElement ) {
26+ warning (
27+ false ,
3428 [
35- "react-modal: Cannot fallback to `document.body`, because it is not" ,
36- "ready or available. If you are doing server-side rendering, use this" ,
37- "function to defined an element. `Modal.setAppElement(el)` to make" ,
38- "this accessible"
29+ "react-modal: App element is not defined." ,
30+ "Please use `Modal.setAppElement(el)` or set `appElement={el}`." ,
31+ "This is needed so screen reades don't see main content" ,
32+ "when modal is opened. It is not recommended, but you can opt-out" ,
33+ "by setting `ariaHideApp={false}`."
3934 ] . join ( " " )
4035 ) ;
36+
37+ return false ;
4138 }
39+
40+ return true ;
4241}
4342
4443export function hide ( appElement ) {
45- validateElement ( appElement ) ;
46- ( appElement || globalElement ) . setAttribute ( "aria-hidden" , "true" ) ;
44+ if ( validateElement ( appElement ) ) {
45+ ( appElement || globalElement ) . setAttribute ( "aria-hidden" , "true" ) ;
46+ }
4747}
4848
4949export function show ( appElement ) {
50- validateElement ( appElement ) ;
51- ( appElement || globalElement ) . removeAttribute ( "aria-hidden" ) ;
50+ if ( validateElement ( appElement ) ) {
51+ ( appElement || globalElement ) . removeAttribute ( "aria-hidden" ) ;
52+ }
5253}
5354
5455export function documentNotReadyOrSSRTesting ( ) {
5556 globalElement = null ;
5657}
5758
5859export function resetForTesting ( ) {
59- globalElement = document . body ;
60+ globalElement = null ;
6061}
0 commit comments