Skip to content

Commit

Permalink
Use preventScroll option on deactivation (#499)
Browse files Browse the repository at this point in the history
* Use preventScroll option on deactivation

* Add changeset

* Implement PR feedback

* Format code
  • Loading branch information
jhnns authored Oct 14, 2021
1 parent 105808f commit 08a9449
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-baboons-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'focus-trap-react': patch
---

Use preventScroll option on deactivation
7 changes: 5 additions & 2 deletions src/focus-trap-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class FocusTrap extends React.Component {
}

deactivateTrap() {
const { checkCanReturnFocus } = this.tailoredFocusTrapOptions;
const { checkCanReturnFocus, preventScroll = false } =
this.tailoredFocusTrapOptions;

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

if (canReturnFocus) {
/** Returns focus to the element that had focus when the trap was activated. */
returnFocusNode.focus();
returnFocusNode.focus({
preventScroll,
});
}

if (this.onPostDeactivate) {
Expand Down

0 comments on commit 08a9449

Please sign in to comment.