Skip to content

Commit d348903

Browse files
authored
fix: modal focus (#277)
* 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
1 parent 687832d commit d348903

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Modal.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Modal extends React.Component {
264264
this.props.onShow();
265265
}
266266
// autofocus after onShow, to not trigger a focus event for previous
267-
// modals before this own is shown.
267+
// modals before this one is shown.
268268
this.autoFocus();
269269
};
270270

@@ -280,7 +280,14 @@ class Modal extends React.Component {
280280
this.handleDocumentKeyDown,
281281
);
282282

283-
this.removeFocusListener = listen(doc, 'focus', this.enforceFocus, true);
283+
this.removeFocusListener = listen(
284+
doc,
285+
'focus',
286+
// the timeout is necessary b/c this will run before the new modal is mounted
287+
// and so steals focus from it
288+
() => setTimeout(this.enforceFocus),
289+
true,
290+
);
284291
};
285292

286293
onHide = () => {

www/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
"gatsby-plugin-css-literal-loader": "^1.0.0",
2121
"gatsby-plugin-emotion": "next",
2222
"gatsby-plugin-less": "^2.0.0-rc.1",
23+
"gatsby-plugin-sorted-assets": "^1.0.2",
2324
"gatsby-remark-prismjs": "^1.2.17",
2425
"gatsby-source-filesystem": "2.0.1-rc.1",
2526
"gatsby-transformer-react-docgen": "^2.1.1-rc.1",
2627
"gatsby-transformer-remark": "^2.1.1-rc.1",
2728
"react-emotion": "^9.2.8"
28-
},
29-
"dependencies": {
30-
"gatsby-plugin-sorted-assets": "^1.0.2"
3129
}
3230
}

0 commit comments

Comments
 (0)