@@ -62,14 +62,16 @@ module.exports = _react2['default'].createClass({
62
62
63
63
getInitialState : function getInitialState ( ) {
64
64
return {
65
- isOpen : this . props . isOpen ,
65
+ isClosing : false ,
66
66
revealed : false
67
67
} ;
68
68
} ,
69
69
70
70
componentDidMount : function componentDidMount ( ) {
71
71
var _this = this ;
72
72
73
+ console . log ( '!!! window.activeElement !!! ' , document . activeElement ) ;
74
+ this . setState ( { returnFocusTo : document . activeElement } ) ;
73
75
if ( ! this . state . revealed ) {
74
76
setTimeout ( function ( ) {
75
77
_this . setState ( { revealed : true } ) ;
@@ -78,12 +80,14 @@ module.exports = _react2['default'].createClass({
78
80
this . updateBodyScroll ( ) ;
79
81
} ,
80
82
81
- openModal : function openModal ( ) {
82
- this . setState ( { isOpen : true } ) ;
83
- } ,
84
-
85
83
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
+ }
87
91
} ,
88
92
89
93
handleSubmitModal : function handleSubmitModal ( ) {
@@ -92,7 +96,7 @@ module.exports = _react2['default'].createClass({
92
96
93
97
updateBodyScroll : function updateBodyScroll ( ) {
94
98
if ( window && document && document . body ) {
95
- if ( this . state . isOpen ) {
99
+ if ( ! this . state . isClosing ) {
96
100
document . body . style . overflow = 'hidden' ;
97
101
} else {
98
102
document . body . style . overflow = 'inherit' ;
@@ -147,7 +151,7 @@ module.exports = _react2['default'].createClass({
147
151
return _react2 [ 'default' ] . createElement (
148
152
_reactModal2 [ 'default' ] ,
149
153
{
150
- isOpen : this . state . isOpen ,
154
+ isOpen : this . props . isOpen ,
151
155
onRequestClose : this . closeModal ,
152
156
style : customStyles ,
153
157
overlayClassName : 'slds-modal-backdrop' + ( this . state . revealed ? ' slds-modal-backdrop--open' : '' ) } ,
@@ -157,14 +161,13 @@ module.exports = _react2['default'].createClass({
157
161
158
162
componentDidUpdate : function componentDidUpdate ( prevProps , prevState ) {
159
163
160
- if ( this . state . isOpen !== prevState . isOpen ) {
164
+ if ( this . state . isClosing !== prevState . isClosing ) {
161
165
162
166
this . updateBodyScroll ( ) ;
163
167
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
+
168
171
if ( this . isMounted ( ) ) {
169
172
var el = this . getDOMNode ( ) . parentNode ;
170
173
if ( el && el . getAttribute ( 'data-slds-modal' ) ) {
0 commit comments