Skip to content

Commit

Permalink
fix: modal focus (#277)
Browse files Browse the repository at this point in the history
* chore: fix docs deploy

* fix: modal focus

This is an annoying bug that deserves a better solution but i've no time for that :P

What happens is that in the stacked case the lower modal's enforceFocus runs before the new modal is added to the modal stack so the lower one still thinks it's on top.

* fix dep
  • Loading branch information
jquense authored Jan 8, 2019
1 parent 687832d commit d348903
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Modal extends React.Component {
this.props.onShow();
}
// autofocus after onShow, to not trigger a focus event for previous
// modals before this own is shown.
// modals before this one is shown.
this.autoFocus();
};

Expand All @@ -280,7 +280,14 @@ class Modal extends React.Component {
this.handleDocumentKeyDown,
);

this.removeFocusListener = listen(doc, 'focus', this.enforceFocus, true);
this.removeFocusListener = listen(
doc,
'focus',
// the timeout is necessary b/c this will run before the new modal is mounted
// and so steals focus from it
() => setTimeout(this.enforceFocus),
true,
);
};

onHide = () => {
Expand Down
4 changes: 1 addition & 3 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
"gatsby-plugin-css-literal-loader": "^1.0.0",
"gatsby-plugin-emotion": "next",
"gatsby-plugin-less": "^2.0.0-rc.1",
"gatsby-plugin-sorted-assets": "^1.0.2",
"gatsby-remark-prismjs": "^1.2.17",
"gatsby-source-filesystem": "2.0.1-rc.1",
"gatsby-transformer-react-docgen": "^2.1.1-rc.1",
"gatsby-transformer-remark": "^2.1.1-rc.1",
"react-emotion": "^9.2.8"
},
"dependencies": {
"gatsby-plugin-sorted-assets": "^1.0.2"
}
}

0 comments on commit d348903

Please sign in to comment.