File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,28 @@ export default () => {
8484 ReactDOM . unmountComponentAtNode ( node ) ;
8585 } ) ;
8686
87+ it ( "allow setting appElement of type string" , ( ) => {
88+ const node = document . createElement ( "div" ) ;
89+ class App extends Component {
90+ render ( ) {
91+ return (
92+ < div >
93+ < Modal isOpen >
94+ < span > hello</ span >
95+ </ Modal >
96+ </ div >
97+ ) ;
98+ }
99+ }
100+ const appElement = "body" ;
101+ Modal . setAppElement ( appElement ) ;
102+ ReactDOM . render ( < App /> , node ) ;
103+ document . body
104+ . querySelector ( ".ReactModalPortal" )
105+ . parentNode . should . be . eql ( document . body ) ;
106+ ReactDOM . unmountComponentAtNode ( node ) ;
107+ } ) ;
108+
87109 it ( "default parentSelector should be document.body." , ( ) => {
88110 const modal = renderModal ( { isOpen : true } ) ;
89111 modal . props . parentSelector ( ) . should . be . eql ( document . body ) ;
Original file line number Diff line number Diff line change 11import warning from "warning" ;
2+ import { canUseDOM } from "./safeHTMLElement" ;
23
34let globalElement = null ;
45
@@ -12,7 +13,7 @@ export function assertNodeList(nodeList, selector) {
1213
1314export function setElement ( element ) {
1415 let useElement = element ;
15- if ( typeof useElement === "string" ) {
16+ if ( typeof useElement === "string" && canUseDOM ) {
1617 const el = document . querySelectorAll ( useElement ) ;
1718 assertNodeList ( el , useElement ) ;
1819 useElement = "length" in el ? el [ 0 ] : el ;
You can’t perform that action at this time.
0 commit comments