Skip to content

Commit

Permalink
Fixing a bug where the focus trap may not have been set before it is …
Browse files Browse the repository at this point in the history
…unmounted (#184)

Co-authored-by: Clint Goodman <clintgoodman@workfront.com>
  • Loading branch information
cgood92 and Clint Goodman authored Nov 17, 2020
1 parent e414308 commit 0836c6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hip-bottles-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'focus-trap-react': patch
---

Fixing a bug where the focus trap may not have been set before it is unmounted #184
5 changes: 4 additions & 1 deletion src/focus-trap-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ class FocusTrap extends React.Component {

componentWillUnmount() {
// NOTE: we never let the trap return the focus since we do that ourselves
this.focusTrap.deactivate({ returnFocus: false });
if (this.focusTrap) {
this.focusTrap.deactivate({ returnFocus: false });
}

if (this.returnFocusOnDeactivate) {
this.returnFocus();
}
Expand Down

0 comments on commit 0836c6d

Please sign in to comment.