1
+ import warning from "warning" ;
2
+
1
3
let globalElement = null ;
2
4
3
5
export function assertNodeList ( nodeList , selector ) {
@@ -19,42 +21,41 @@ export function setElement(element) {
19
21
return globalElement ;
20
22
}
21
23
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
-
31
24
export function validateElement ( appElement ) {
32
- if ( ! appElement && ! globalElement && ! tryForceFallback ( ) ) {
33
- throw new Error (
25
+ if ( ! appElement && ! globalElement ) {
26
+ warning (
27
+ false ,
34
28
[
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}`."
39
34
] . join ( " " )
40
35
) ;
36
+
37
+ return false ;
41
38
}
39
+
40
+ return true ;
42
41
}
43
42
44
43
export 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
+ }
47
47
}
48
48
49
49
export function show ( appElement ) {
50
- validateElement ( appElement ) ;
51
- ( appElement || globalElement ) . removeAttribute ( "aria-hidden" ) ;
50
+ if ( validateElement ( appElement ) ) {
51
+ ( appElement || globalElement ) . removeAttribute ( "aria-hidden" ) ;
52
+ }
52
53
}
53
54
54
55
export function documentNotReadyOrSSRTesting ( ) {
55
56
globalElement = null ;
56
57
}
57
58
58
59
export function resetForTesting ( ) {
59
- globalElement = document . body ;
60
+ globalElement = null ;
60
61
}
0 commit comments