Skip to content

Commit

Permalink
feat(Modal): return focus after modal closes (reactstrap#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSharpieOne authored Aug 16, 2018
1 parent 77e7beb commit 1b27c49
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ class Modal extends React.Component {
}

init() {
try {
this._triggeringElement = document.activeElement;
} catch (err) {
this._triggeringElement = null;
}
this._element = document.createElement('div');
this._element.setAttribute('tabindex', '-1');
this._element.style.position = 'relative';
Expand All @@ -259,6 +264,11 @@ class Modal extends React.Component {
this._element = null;
}

if (this._triggeringElement) {
this._triggeringElement.focus();
this._triggeringElement = null;
}

if (this.bodyClassAdded) {
const modalOpenClassName = mapToCssModules('modal-open', this.props.cssModule);
// Use regex to prevent matching `modal-open` as part of a different class, e.g. `my-modal-opened`
Expand Down

0 comments on commit 1b27c49

Please sign in to comment.