focus-trap-react 8.7.0 → 8.8.2
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 +25 -0
- package/README.md +5 -2
- package/dist/focus-trap-react.js +14 -5
- package/package.json +22 -22
- package/src/focus-trap-react.js +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 8.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 08a9449: Use `preventScroll` option on deactivation if returning focus.
|
|
8
|
+
|
|
9
|
+
## 8.8.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- a2806a0: Fix SSR issues when accessing `document` object (#482)
|
|
14
|
+
|
|
15
|
+
## 8.8.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- c8e46c2: Support new `document` option introduced in focus-trap v6.7.0 (#460)
|
|
20
|
+
- 5ee587c: Bump focus-trap dependency to v6.7.1
|
|
21
|
+
|
|
22
|
+
## 8.7.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 111a27f: Update focus-trap to v6.6.1, to get tabbable at v5.2.1, to get bug fix for disabled fieldsets.
|
|
27
|
+
|
|
3
28
|
## 8.7.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# focus-trap-react [](https://github.com/focus-trap/focus-trap-react/actions?query=workflow:CI+branch:master) [](https://codecov.io/gh/focus-trap/focus-trap-react) [](./LICENSE)
|
|
2
2
|
|
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
4
|
-
[](#contributors)
|
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
6
6
|
|
|
7
7
|
A React component that traps focus.
|
|
@@ -191,19 +191,22 @@ In alphabetical order:
|
|
|
191
191
|
<td align="center"><a href="https://github.com/features/security"><img src="https://avatars1.githubusercontent.com/u/27347476?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dependabot</b></sub></a><br /><a href="#maintenance-dependabot" title="Maintenance">🚧</a></td>
|
|
192
192
|
</tr>
|
|
193
193
|
<tr>
|
|
194
|
+
<td align="center"><a href="https://github.com/jhnns"><img src="https://avatars.githubusercontent.com/u/781746?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Johannes Ewald</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=jhnns" title="Code">💻</a></td>
|
|
194
195
|
<td align="center"><a href="http://josuzuki.me"><img src="https://avatars1.githubusercontent.com/u/9583920?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan Suzuki</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3AJoSuzuki" title="Bug reports">🐛</a></td>
|
|
195
196
|
<td align="center"><a href="http://kathleenmcmahon.dev/"><img src="https://avatars1.githubusercontent.com/u/11621935?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kathleen McMahon</b></sub></a><br /><a href="#maintenance-resource11" title="Maintenance">🚧</a></td>
|
|
196
197
|
<td align="center"><a href="https://marais.io/"><img src="https://avatars2.githubusercontent.com/u/599459?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marais Rossouw</b></sub></a><br /><a href="#infra-maraisr" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
|
197
198
|
<td align="center"><a href="https://github.com/liunate"><img src="https://avatars2.githubusercontent.com/u/38996291?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nate Liu</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=liunate" title="Tests">⚠️</a></td>
|
|
198
199
|
<td align="center"><a href="https://www.linkedin.com/in/rivajunior/"><img src="https://avatars1.githubusercontent.com/u/11370172?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rivaldo Junior</b></sub></a><br /><a href="#maintenance-rivajunior" title="Maintenance">🚧</a></td>
|
|
199
200
|
<td align="center"><a href="https://scottrippey.github.io/"><img src="https://avatars3.githubusercontent.com/u/430608?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Scott Rippey</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=scottrippey" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Ascottrippey" title="Bug reports">🐛</a></td>
|
|
200
|
-
<td align="center"><a href="https://seanmcp.com/"><img src="https://avatars1.githubusercontent.com/u/6360367?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sean McPherson</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=SeanMcP" title="Code">💻</a></td>
|
|
201
201
|
</tr>
|
|
202
202
|
<tr>
|
|
203
|
+
<td align="center"><a href="https://seanmcp.com/"><img src="https://avatars1.githubusercontent.com/u/6360367?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sean McPherson</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=SeanMcP" title="Code">💻</a></td>
|
|
203
204
|
<td align="center"><a href="https://recollectr.io"><img src="https://avatars2.githubusercontent.com/u/6835891?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Slapbox</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=Slapbox" title="Documentation">📖</a></td>
|
|
204
205
|
<td align="center"><a href="https://stefancameron.com/"><img src="https://avatars3.githubusercontent.com/u/2855350?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stefan Cameron</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Astefcameron" title="Bug reports">🐛</a> <a href="#infra-stefcameron" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Tests">⚠️</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Documentation">📖</a> <a href="#maintenance-stefcameron" title="Maintenance">🚧</a></td>
|
|
205
206
|
<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>
|
|
207
|
+
<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>
|
|
206
208
|
<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>
|
|
209
|
+
<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>
|
|
207
210
|
</tr>
|
|
208
211
|
</table>
|
|
209
212
|
|
package/dist/focus-trap-react.js
CHANGED
|
@@ -14,7 +14,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
14
14
|
|
|
15
15
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
16
|
|
|
17
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
18
|
|
|
19
19
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
20
|
|
|
@@ -129,8 +129,11 @@ var FocusTrap = /*#__PURE__*/function (_React$Component) {
|
|
|
129
129
|
}, {
|
|
130
130
|
key: "updatePreviousElement",
|
|
131
131
|
value: function updatePreviousElement() {
|
|
132
|
-
if
|
|
133
|
-
|
|
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);
|
|
134
|
+
|
|
135
|
+
if (currentDocument) {
|
|
136
|
+
this.previouslyFocusedElement = currentDocument.activeElement;
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
}, {
|
|
@@ -138,7 +141,10 @@ var FocusTrap = /*#__PURE__*/function (_React$Component) {
|
|
|
138
141
|
value: function deactivateTrap() {
|
|
139
142
|
var _this2 = this;
|
|
140
143
|
|
|
141
|
-
var
|
|
144
|
+
var _this$tailoredFocusTr = this.tailoredFocusTrapOptions,
|
|
145
|
+
checkCanReturnFocus = _this$tailoredFocusTr.checkCanReturnFocus,
|
|
146
|
+
_this$tailoredFocusTr2 = _this$tailoredFocusTr.preventScroll,
|
|
147
|
+
preventScroll = _this$tailoredFocusTr2 === void 0 ? false : _this$tailoredFocusTr2;
|
|
142
148
|
|
|
143
149
|
if (this.focusTrap) {
|
|
144
150
|
// NOTE: we never let the trap return the focus since we do that ourselves
|
|
@@ -154,7 +160,9 @@ var FocusTrap = /*#__PURE__*/function (_React$Component) {
|
|
|
154
160
|
|
|
155
161
|
if (canReturnFocus) {
|
|
156
162
|
/** Returns focus to the element that had focus when the trap was activated. */
|
|
157
|
-
returnFocusNode.focus(
|
|
163
|
+
returnFocusNode.focus({
|
|
164
|
+
preventScroll: preventScroll
|
|
165
|
+
});
|
|
158
166
|
}
|
|
159
167
|
|
|
160
168
|
if (_this2.onPostDeactivate) {
|
|
@@ -283,6 +291,7 @@ FocusTrap.propTypes = {
|
|
|
283
291
|
active: PropTypes.bool,
|
|
284
292
|
paused: PropTypes.bool,
|
|
285
293
|
focusTrapOptions: PropTypes.shape({
|
|
294
|
+
document: PropTypes.object,
|
|
286
295
|
onActivate: PropTypes.func,
|
|
287
296
|
onPostActivate: PropTypes.func,
|
|
288
297
|
checkCanFocusTrap: PropTypes.func,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "focus-trap-react",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.2",
|
|
4
4
|
"description": "A React component that traps focus.",
|
|
5
5
|
"main": "dist/focus-trap-react.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -55,43 +55,43 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/focus-trap/focus-trap-react#readme",
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@babel/cli": "^7.
|
|
59
|
-
"@babel/core": "^7.
|
|
58
|
+
"@babel/cli": "^7.15.7",
|
|
59
|
+
"@babel/core": "^7.15.8",
|
|
60
60
|
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
61
|
-
"@babel/preset-env": "^7.
|
|
61
|
+
"@babel/preset-env": "^7.15.8",
|
|
62
62
|
"@babel/preset-react": "^7.14.5",
|
|
63
|
-
"@changesets/cli": "^2.
|
|
64
|
-
"@testing-library/cypress": "^
|
|
65
|
-
"@testing-library/dom": "^8.
|
|
63
|
+
"@changesets/cli": "^2.17.0",
|
|
64
|
+
"@testing-library/cypress": "^8.0.1",
|
|
65
|
+
"@testing-library/dom": "^8.7.2",
|
|
66
66
|
"@testing-library/jest-dom": "^5.14.1",
|
|
67
|
-
"@testing-library/react": "^12.
|
|
68
|
-
"@testing-library/user-event": "^13.
|
|
69
|
-
"@types/jquery": "^3.5.
|
|
67
|
+
"@testing-library/react": "^12.1.2",
|
|
68
|
+
"@testing-library/user-event": "^13.3.0",
|
|
69
|
+
"@types/jquery": "^3.5.7",
|
|
70
70
|
"all-contributors-cli": "^6.20.0",
|
|
71
71
|
"babel-eslint": "^10.1.0",
|
|
72
|
-
"babel-jest": "^27.
|
|
72
|
+
"babel-jest": "^27.2.5",
|
|
73
73
|
"babelify": "^10.0.0",
|
|
74
74
|
"browserify": "^17.0.0",
|
|
75
75
|
"budo": "^11.6.4",
|
|
76
|
-
"cypress": "^
|
|
76
|
+
"cypress": "^8.6.0",
|
|
77
77
|
"cypress-plugin-tab": "^1.0.5",
|
|
78
|
-
"eslint": "^7.
|
|
78
|
+
"eslint": "^7.32.0",
|
|
79
79
|
"eslint-config-prettier": "^8.3.0",
|
|
80
|
-
"eslint-plugin-cypress": "^2.
|
|
81
|
-
"eslint-plugin-react": "^7.
|
|
82
|
-
"jest": "^27.
|
|
83
|
-
"jest-watch-typeahead": "^0.
|
|
80
|
+
"eslint-plugin-cypress": "^2.12.1",
|
|
81
|
+
"eslint-plugin-react": "^7.26.1",
|
|
82
|
+
"jest": "^27.2.5",
|
|
83
|
+
"jest-watch-typeahead": "^1.0.0",
|
|
84
84
|
"onchange": "^7.1.0",
|
|
85
|
-
"prettier": "^2.
|
|
85
|
+
"prettier": "^2.4.1",
|
|
86
86
|
"prop-types": "^15.7.2",
|
|
87
87
|
"react": "^17.0.2",
|
|
88
88
|
"react-dom": "^17.0.2",
|
|
89
|
-
"regenerator-runtime": "^0.13.
|
|
90
|
-
"start-server-and-test": "^1.
|
|
91
|
-
"typescript": "^4.
|
|
89
|
+
"regenerator-runtime": "^0.13.9",
|
|
90
|
+
"start-server-and-test": "^1.14.0",
|
|
91
|
+
"typescript": "^4.4.4"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"focus-trap": "^6.
|
|
94
|
+
"focus-trap": "^6.7.1"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"prop-types": "^15.7.2",
|
package/src/focus-trap-react.js
CHANGED
|
@@ -87,13 +87,18 @@ class FocusTrap extends React.Component {
|
|
|
87
87
|
|
|
88
88
|
/** Update the previously focused element with the currently focused element. */
|
|
89
89
|
updatePreviousElement() {
|
|
90
|
-
if
|
|
91
|
-
|
|
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);
|
|
94
|
+
if (currentDocument) {
|
|
95
|
+
this.previouslyFocusedElement = currentDocument.activeElement;
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
deactivateTrap() {
|
|
96
|
-
const { checkCanReturnFocus } =
|
|
100
|
+
const { checkCanReturnFocus, preventScroll = false } =
|
|
101
|
+
this.tailoredFocusTrapOptions;
|
|
97
102
|
|
|
98
103
|
if (this.focusTrap) {
|
|
99
104
|
// NOTE: we never let the trap return the focus since we do that ourselves
|
|
@@ -107,7 +112,9 @@ class FocusTrap extends React.Component {
|
|
|
107
112
|
|
|
108
113
|
if (canReturnFocus) {
|
|
109
114
|
/** Returns focus to the element that had focus when the trap was activated. */
|
|
110
|
-
returnFocusNode.focus(
|
|
115
|
+
returnFocusNode.focus({
|
|
116
|
+
preventScroll,
|
|
117
|
+
});
|
|
111
118
|
}
|
|
112
119
|
|
|
113
120
|
if (this.onPostDeactivate) {
|
|
@@ -241,6 +248,7 @@ FocusTrap.propTypes = {
|
|
|
241
248
|
active: PropTypes.bool,
|
|
242
249
|
paused: PropTypes.bool,
|
|
243
250
|
focusTrapOptions: PropTypes.shape({
|
|
251
|
+
document: PropTypes.object,
|
|
244
252
|
onActivate: PropTypes.func,
|
|
245
253
|
onPostActivate: PropTypes.func,
|
|
246
254
|
checkCanFocusTrap: PropTypes.func,
|