@@ -62,14 +62,16 @@ module.exports = _react2['default'].createClass({
6262
6363 getInitialState : function getInitialState ( ) {
6464 return {
65- isOpen : this . props . isOpen ,
65+ isClosing : false ,
6666 revealed : false
6767 } ;
6868 } ,
6969
7070 componentDidMount : function componentDidMount ( ) {
7171 var _this = this ;
7272
73+ console . log ( '!!! window.activeElement !!! ' , document . activeElement ) ;
74+ this . setState ( { returnFocusTo : document . activeElement } ) ;
7375 if ( ! this . state . revealed ) {
7476 setTimeout ( function ( ) {
7577 _this . setState ( { revealed : true } ) ;
@@ -78,12 +80,14 @@ module.exports = _react2['default'].createClass({
7880 this . updateBodyScroll ( ) ;
7981 } ,
8082
81- openModal : function openModal ( ) {
82- this . setState ( { isOpen : true } ) ;
83- } ,
84-
8583 closeModal : function closeModal ( ) {
86- this . setState ( { isOpen : false } ) ;
84+ this . setState ( { isClosing : true } ) ;
85+ if ( this . state . returnFocusTo && this . state . returnFocusTo . focus ) {
86+ this . state . returnFocusTo . focus ( ) ;
87+ }
88+ if ( this . props . onRequestClose ) {
89+ this . props . onRequestClose ( ) ;
90+ }
8791 } ,
8892
8993 handleSubmitModal : function handleSubmitModal ( ) {
@@ -92,7 +96,7 @@ module.exports = _react2['default'].createClass({
9296
9397 updateBodyScroll : function updateBodyScroll ( ) {
9498 if ( window && document && document . body ) {
95- if ( this . state . isOpen ) {
99+ if ( ! this . state . isClosing ) {
96100 document . body . style . overflow = 'hidden' ;
97101 } else {
98102 document . body . style . overflow = 'inherit' ;
@@ -147,7 +151,7 @@ module.exports = _react2['default'].createClass({
147151 return _react2 [ 'default' ] . createElement (
148152 _reactModal2 [ 'default' ] ,
149153 {
150- isOpen : this . state . isOpen ,
154+ isOpen : this . props . isOpen ,
151155 onRequestClose : this . closeModal ,
152156 style : customStyles ,
153157 overlayClassName : 'slds-modal-backdrop' + ( this . state . revealed ? ' slds-modal-backdrop--open' : '' ) } ,
@@ -157,14 +161,13 @@ module.exports = _react2['default'].createClass({
157161
158162 componentDidUpdate : function componentDidUpdate ( prevProps , prevState ) {
159163
160- if ( this . state . isOpen !== prevState . isOpen ) {
164+ if ( this . state . isClosing !== prevState . isClosing ) {
161165
162166 this . updateBodyScroll ( ) ;
163167
164- if ( ! this . state . isOpen ) {
165- if ( this . props . returnFocusTo && this . props . returnFocusTo . focus ) {
166- this . props . returnFocusTo . focus ( ) ;
167- }
168+ if ( this . state . isClosing ) {
169+ console . log ( 'CLOSING: ' ) ;
170+
168171 if ( this . isMounted ( ) ) {
169172 var el = this . getDOMNode ( ) . parentNode ;
170173 if ( el && el . getAttribute ( 'data-slds-modal' ) ) {
0 commit comments