Skip to content

Commit

Permalink
[fixed] ensure last focused item can be focused
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jul 24, 2015
1 parent 596f40c commit e5155c6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,14 @@ const Modal = React.createClass({
let current = domUtils.activeElement(this);
let focusInModal = current && domUtils.contains(modalContent, current);

if (this.props.autoFocus && !focusInModal) {
if (modalContent && this.props.autoFocus && !focusInModal) {
this.lastFocus = current;

modalContent.focus();
}
},

restoreLastFocus () {
if (this.lastFocus) {
if (this.lastFocus && this.lastFocus.focus) {
this.lastFocus.focus();
this.lastFocus = null;
}
Expand All @@ -382,7 +381,7 @@ const Modal = React.createClass({
let active = domUtils.activeElement(this);
let modal = React.findDOMNode(this.refs.dialog);

if (modal !== active && !domUtils.contains(modal, active)){
if (modal && modal !== active && !domUtils.contains(modal, active)){
modal.focus();
}
},
Expand Down

0 comments on commit e5155c6

Please sign in to comment.