From 2c7e47e9507ce54b4a6f08b52063a5d06783ca04 Mon Sep 17 00:00:00 2001 From: ibogdanov Date: Wed, 30 Sep 2015 18:40:01 -0700 Subject: [PATCH] v0.0.8 build --- lib/SLDSModal/index.js | 29 ++++++++++++++++------------- lib/SLDSModal/trigger.js | 1 - package.json | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/SLDSModal/index.js b/lib/SLDSModal/index.js index d7d3419293..41187083ab 100644 --- a/lib/SLDSModal/index.js +++ b/lib/SLDSModal/index.js @@ -62,7 +62,7 @@ module.exports = _react2['default'].createClass({ getInitialState: function getInitialState() { return { - isOpen: this.props.isOpen, + isClosing: false, revealed: false }; }, @@ -70,6 +70,8 @@ module.exports = _react2['default'].createClass({ componentDidMount: function componentDidMount() { var _this = this; + console.log('!!! window.activeElement !!! ', document.activeElement); + this.setState({ returnFocusTo: document.activeElement }); if (!this.state.revealed) { setTimeout(function () { _this.setState({ revealed: true }); @@ -78,12 +80,14 @@ module.exports = _react2['default'].createClass({ this.updateBodyScroll(); }, - openModal: function openModal() { - this.setState({ isOpen: true }); - }, - closeModal: function closeModal() { - this.setState({ isOpen: false }); + this.setState({ isClosing: true }); + if (this.state.returnFocusTo && this.state.returnFocusTo.focus) { + this.state.returnFocusTo.focus(); + } + if (this.props.onRequestClose) { + this.props.onRequestClose(); + } }, handleSubmitModal: function handleSubmitModal() { @@ -92,7 +96,7 @@ module.exports = _react2['default'].createClass({ updateBodyScroll: function updateBodyScroll() { if (window && document && document.body) { - if (this.state.isOpen) { + if (!this.state.isClosing) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = 'inherit'; @@ -147,7 +151,7 @@ module.exports = _react2['default'].createClass({ return _react2['default'].createElement( _reactModal2['default'], { - isOpen: this.state.isOpen, + isOpen: this.props.isOpen, onRequestClose: this.closeModal, style: customStyles, overlayClassName: 'slds-modal-backdrop' + (this.state.revealed ? ' slds-modal-backdrop--open' : '') }, @@ -157,14 +161,13 @@ module.exports = _react2['default'].createClass({ componentDidUpdate: function componentDidUpdate(prevProps, prevState) { - if (this.state.isOpen !== prevState.isOpen) { + if (this.state.isClosing !== prevState.isClosing) { this.updateBodyScroll(); - if (!this.state.isOpen) { - if (this.props.returnFocusTo && this.props.returnFocusTo.focus) { - this.props.returnFocusTo.focus(); - } + if (this.state.isClosing) { + console.log('CLOSING: '); + if (this.isMounted()) { var el = this.getDOMNode().parentNode; if (el && el.getAttribute('data-slds-modal')) { diff --git a/lib/SLDSModal/trigger.js b/lib/SLDSModal/trigger.js index 8b4aa0e304..3e234ceba0 100644 --- a/lib/SLDSModal/trigger.js +++ b/lib/SLDSModal/trigger.js @@ -31,7 +31,6 @@ var SLDSModalTrigger = { { title: cfg.title, footer: cfg.footer, - returnFocusTo: cfg.returnFocusTo, isOpen: true }, cfg.content ); diff --git a/package.json b/package.json index efc53ac2c8..529bd97420 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "design-system-react", - "version": "0.0.7", + "version": "0.0.8", "description": "Salesforce Lightning Design System React components", "scripts": { "start": "node server.js",