File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ var modalInstance = (
77 < Modal title = "Modal title"
88 backdrop = { false }
99 animation = { false }
10+ container = { mountNode }
1011 onRequestHide = { handleHide } >
1112 < div className = "modal-body" >
1213 One fine body...
Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ var Modal = React.createClass({
124124 this . _onDocumentKeyupListener =
125125 EventListener . listen ( document , 'keyup' , this . handleDocumentKeyUp ) ;
126126
127+ var container = ( this . props . container && this . props . container . getDOMNode ( ) ) || document . body ;
128+ container . className += container . className . length ? ' modal-open' : 'modal-open' ;
129+
127130 if ( this . props . backdrop ) {
128131 this . iosClickHack ( ) ;
129132 }
@@ -137,6 +140,8 @@ var Modal = React.createClass({
137140
138141 componentWillUnmount : function ( ) {
139142 this . _onDocumentKeyupListener . remove ( ) ;
143+ var container = ( this . props . container && this . props . container . getDOMNode ( ) ) || document . body ;
144+ container . className = container . className . replace ( / ? m o d a l - o p e n / , '' ) ;
140145 } ,
141146
142147 handleBackdropClick : function ( e ) {
Original file line number Diff line number Diff line change @@ -16,6 +16,39 @@ describe('Modal', function () {
1616 assert . ok ( ReactTestUtils . findRenderedDOMComponentWithTag ( instance , 'strong' ) ) ;
1717 } ) ;
1818
19+ it ( 'Should add modal-open class to the modal container while open' , function ( done ) {
20+
21+ var Container = React . createClass ( {
22+ getInitialState : function ( ) {
23+ return { modalOpen : true } ;
24+ } ,
25+ handleCloseModal : function ( ) {
26+ this . setState ( { modalOpen : false } ) ;
27+ } ,
28+ render : function ( ) {
29+ if ( this . state . modalOpen ) {
30+ return < Modal onRequestHide = { this . handleCloseModal } container = { this } >
31+ < strong > Message</ strong >
32+ </ Modal > ;
33+ } else {
34+ return < span /> ;
35+ }
36+ }
37+ } ) ;
38+ var instance = ReactTestUtils . renderIntoDocument (
39+ < Container />
40+ ) ;
41+ assert . ok ( instance . getDOMNode ( ) . className . match ( / \m o d a l - o p e n \b / ) ) ;
42+
43+ var backdrop = instance . getDOMNode ( ) . getElementsByClassName ( 'modal-backdrop' ) [ 0 ] ;
44+ ReactTestUtils . Simulate . click ( backdrop ) ;
45+ setTimeout ( function ( ) {
46+ assert . equal ( instance . getDOMNode ( ) . className . length , 0 ) ;
47+ done ( ) ;
48+ } , 0 ) ;
49+
50+ } ) ;
51+
1952 it ( 'Should close the modal when the backdrop is clicked' , function ( done ) {
2053 var doneOp = function ( ) { done ( ) ; } ;
2154 var instance = ReactTestUtils . renderIntoDocument (
You can’t perform that action at this time.
0 commit comments