diff --git a/.changeset/big-baboons-count.md b/.changeset/big-baboons-count.md new file mode 100644 index 00000000..a412f76d --- /dev/null +++ b/.changeset/big-baboons-count.md @@ -0,0 +1,5 @@ +--- +'focus-trap-react': patch +--- + +Use preventScroll option on deactivation diff --git a/src/focus-trap-react.js b/src/focus-trap-react.js index af98dc76..c5e79fc1 100644 --- a/src/focus-trap-react.js +++ b/src/focus-trap-react.js @@ -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 @@ -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) {