focus-trap-react 8.8.0 → 8.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - a2806a0: Fix SSR issues when accessing `document` object (#482)
8
+
3
9
  ## 8.8.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # focus-trap-react [![CI](https://github.com/focus-trap/focus-trap-react/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/focus-trap/focus-trap-react/actions?query=workflow:CI+branch:master) [![Codecov](https://img.shields.io/codecov/c/github/focus-trap/focus-trap-react)](https://codecov.io/gh/focus-trap/focus-trap-react) [![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)
2
2
 
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
 
7
7
  A React component that traps focus.
@@ -205,6 +205,7 @@ In alphabetical order:
205
205
  <td align="center"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler Hawkins</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=thawkin3" title="Documentation">📖</a> <a href="#example-thawkin3" title="Examples">💡</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=thawkin3" title="Tests">⚠️</a> <a href="#tool-thawkin3" title="Tools">🔧</a></td>
206
206
  <td align="center"><a href="https://github.com/wandroll"><img src="https://avatars.githubusercontent.com/u/4492317?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Wandrille Verlut</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=wandroll" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=wandroll" title="Tests">⚠️</a></td>
207
207
  <td align="center"><a href="https://github.com/krikienoid"><img src="https://avatars3.githubusercontent.com/u/8528227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>krikienoid</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Akrikienoid" title="Bug reports">🐛</a></td>
208
+ <td align="center"><a href="https://github.com/syntactic-salt"><img src="https://avatars.githubusercontent.com/u/9385662?v=4?s=100" width="100px;" alt=""/><br /><sub><b>syntactic-salt</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Asyntactic-salt" title="Bug reports">🐛</a></td>
208
209
  </tr>
209
210
  </table>
210
211
 
@@ -129,7 +129,8 @@ var FocusTrap = /*#__PURE__*/function (_React$Component) {
129
129
  }, {
130
130
  key: "updatePreviousElement",
131
131
  value: function updatePreviousElement() {
132
- var currentDocument = this.props.focusTrapOptions.document || document;
132
+ // SSR: careful to check if `document` exists before accessing it as a variable
133
+ var currentDocument = this.props.focusTrapOptions.document || (typeof document !== 'undefined' ? document : undefined);
133
134
 
134
135
  if (currentDocument) {
135
136
  this.previouslyFocusedElement = currentDocument.activeElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "focus-trap-react",
3
- "version": "8.8.0",
3
+ "version": "8.8.1",
4
4
  "description": "A React component that traps focus.",
5
5
  "main": "dist/focus-trap-react.js",
6
6
  "types": "index.d.ts",
@@ -87,7 +87,10 @@ class FocusTrap extends React.Component {
87
87
 
88
88
  /** Update the previously focused element with the currently focused element. */
89
89
  updatePreviousElement() {
90
- const currentDocument = this.props.focusTrapOptions.document || document;
90
+ // SSR: careful to check if `document` exists before accessing it as a variable
91
+ const currentDocument =
92
+ this.props.focusTrapOptions.document ||
93
+ (typeof document !== 'undefined' ? document : undefined);
91
94
  if (currentDocument) {
92
95
  this.previouslyFocusedElement = currentDocument.activeElement;
93
96
  }