Skip to content

Commit 08a9449

Browse files
authored
Use preventScroll option on deactivation (#499)
* Use preventScroll option on deactivation * Add changeset * Implement PR feedback * Format code
1 parent 105808f commit 08a9449

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/big-baboons-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'focus-trap-react': patch
3+
---
4+
5+
Use preventScroll option on deactivation

src/focus-trap-react.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class FocusTrap extends React.Component {
9797
}
9898

9999
deactivateTrap() {
100-
const { checkCanReturnFocus } = this.tailoredFocusTrapOptions;
100+
const { checkCanReturnFocus, preventScroll = false } =
101+
this.tailoredFocusTrapOptions;
101102

102103
if (this.focusTrap) {
103104
// NOTE: we never let the trap return the focus since we do that ourselves
@@ -111,7 +112,9 @@ class FocusTrap extends React.Component {
111112

112113
if (canReturnFocus) {
113114
/** Returns focus to the element that had focus when the trap was activated. */
114-
returnFocusNode.focus();
115+
returnFocusNode.focus({
116+
preventScroll,
117+
});
115118
}
116119

117120
if (this.onPostDeactivate) {

0 commit comments

Comments
 (0)