Merge pull request #822 from t3chguy/BaseDialog_restore_focus

Remember element that was in focus before rendering dialog
This commit is contained in:
Matthew Hodgson 2017-04-22 16:05:34 +01:00 committed by GitHub
commit 0ac836919d

View file

@ -47,6 +47,16 @@ export default React.createClass({
children: React.PropTypes.node,
},
componentWillMount: function() {
this.priorActiveElement = document.activeElement;
},
componentWillUnmount: function() {
if (this.priorActiveElement !== null) {
this.priorActiveElement.focus();
}
},
_onKeyDown: function(e) {
if (e.keyCode === KeyCode.ESCAPE) {
e.stopPropagation();
@ -67,7 +77,7 @@ export default React.createClass({
render: function() {
const TintableSvg = sdk.getComponent("elements.TintableSvg");
return (
<div onKeyDown={this._onKeyDown} className={this.props.className}>
<AccessibleButton onClick={this._onCancelClick}