focus-trap 8.0.0 → 8.1.0
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 +12 -0
- package/README.md +20 -18
- package/dist/focus-trap.esm.js +25 -9
- package/dist/focus-trap.esm.js.map +1 -1
- package/dist/focus-trap.esm.min.js +2 -2
- package/dist/focus-trap.esm.min.js.map +1 -1
- package/dist/focus-trap.js +25 -9
- package/dist/focus-trap.js.map +1 -1
- package/dist/focus-trap.min.js +3 -3
- package/dist/focus-trap.min.js.map +1 -1
- package/dist/focus-trap.umd.js +25 -9
- package/dist/focus-trap.umd.js.map +1 -1
- package/dist/focus-trap.umd.min.js +2 -2
- package/dist/focus-trap.umd.min.js.map +1 -1
- package/index.d.ts +23 -10
- package/index.js +8 -8
- package/package.json +26 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 8.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 642f7f2: Update lifecycle hooks to include the associated focus trap as a parameter.
|
|
8
|
+
|
|
9
|
+
## 8.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 7d5010e: Loosen checkCanFocusTrap Promise resolution type to `unknown` to make it easier to use `Promise.all()` or `Promise.allSettled()` as the returned Promise (`Promise<void>` was causing issues because those Promise APIs do not resolve with a `void` value).
|
|
14
|
+
|
|
3
15
|
## 8.0.0
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Returns a new focus trap on `element` (one or more "containers" of tabbable node
|
|
|
94
94
|
##### onActivate
|
|
95
95
|
|
|
96
96
|
```typescript
|
|
97
|
-
() => void
|
|
97
|
+
(params: LifecycleParameters) => void
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
A function that will be called **before** sending focus to the target element upon activation.
|
|
@@ -102,7 +102,7 @@ A function that will be called **before** sending focus to the target element up
|
|
|
102
102
|
##### onPostActivate
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
|
-
() => void
|
|
105
|
+
(params: LifecycleParameters) => void
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
A function that will be called **after** sending focus to the target element upon activation **unless** initial focus is delayed because the [delayInitialFocus](#delayinitialfocus) is true (default).
|
|
@@ -110,7 +110,7 @@ A function that will be called **after** sending focus to the target element upo
|
|
|
110
110
|
##### onPause
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
() => void
|
|
113
|
+
(params: LifecycleParameters) => void
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
A function that will be called immediately after the trap's state is updated to be paused.
|
|
@@ -118,7 +118,7 @@ A function that will be called immediately after the trap's state is updated to
|
|
|
118
118
|
##### onPostPause
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
|
-
() => void
|
|
121
|
+
(params: LifecycleParameters) => void
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
A function that will be called after the trap has been completely paused and is no longer managing/trapping focus.
|
|
@@ -126,7 +126,7 @@ A function that will be called after the trap has been completely paused and is
|
|
|
126
126
|
##### onUnpause
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
|
-
() => void
|
|
129
|
+
(params: LifecycleParameters) => void
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
A function that will be called immediately after the trap's state is updated to be active again, but prior to updating its knowledge of what nodes are tabbable within its containers, and prior to actively managing/trapping focus.
|
|
@@ -134,7 +134,7 @@ A function that will be called immediately after the trap's state is updated to
|
|
|
134
134
|
##### onPostUnpause
|
|
135
135
|
|
|
136
136
|
```typescript
|
|
137
|
-
() => void
|
|
137
|
+
(params: LifecycleParameters) => void
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
A function that will be called after the trap has been completely unpaused and is once again managing/trapping focus.
|
|
@@ -144,15 +144,17 @@ Note that if [delayInitialFocus](#delayinitialfocus) is true, this handler will
|
|
|
144
144
|
##### checkCanFocusTrap
|
|
145
145
|
|
|
146
146
|
```typescript
|
|
147
|
-
(containers: Array<HTMLElement | SVGElement>) => Promise<
|
|
147
|
+
(containers: Array<HTMLElement | SVGElement>) => Promise<unknown>
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
Animated dialogs have a small delay between when `onActivate` is called and when the focus trap is focusable. `checkCanFocusTrap` expects a promise to be returned. When that promise settles (resolves or rejects), focus will be sent to the first tabbable node (in tab order) in the focus trap (or the node configured in the `initialFocus` option).
|
|
151
151
|
|
|
152
|
+
🔺 It does not matter whether the Promise resolves or rejects, only that it settles. A rejected Promise will not result in cancellation of trap activation.
|
|
153
|
+
|
|
152
154
|
##### onDeactivate
|
|
153
155
|
|
|
154
156
|
```typescript
|
|
155
|
-
() => void
|
|
157
|
+
(params: LifecycleParameters) => void
|
|
156
158
|
```
|
|
157
159
|
|
|
158
160
|
A function that will be called **before** returning focus to the node that had focus prior to activation (or configured with the `setReturnFocus` option) upon deactivation.
|
|
@@ -160,7 +162,7 @@ A function that will be called **before** returning focus to the node that had f
|
|
|
160
162
|
##### onPostDeactivate
|
|
161
163
|
|
|
162
164
|
```typescript
|
|
163
|
-
() => void
|
|
165
|
+
(params: LifecycleParameters) => void
|
|
164
166
|
```
|
|
165
167
|
|
|
166
168
|
A function that will be called after the trap is deactivated, after `onDeactivate`. If the `returnFocus` deactivation option was set, it will be called **after** returning focus to the node that had focus prior to activation (or configured with the `setReturnFocus` option) upon deactivation; otherwise, it will be called after deactivation completes.
|
|
@@ -387,9 +389,9 @@ Returns the `trap`.
|
|
|
387
389
|
|
|
388
390
|
These options are used to override the focus trap's default behavior for this particular activation.
|
|
389
391
|
|
|
390
|
-
- **onActivate** `{() => void}`: Default: whatever you chose for `createOptions.onActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
391
|
-
- **onPostActivate** `{() => void}`: Default: whatever you chose for `createOptions.onPostActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
392
|
-
- **checkCanFocusTrap** `{(containers: Array<HTMLElement | SVGElement>) => Promise<
|
|
392
|
+
- **onActivate** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
393
|
+
- **onPostActivate** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onPostActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
394
|
+
- **checkCanFocusTrap** `{(containers: Array<HTMLElement | SVGElement>) => Promise<unknown>}`: Default: whatever you chose for `createOptions.checkCanFocusTrap`.
|
|
393
395
|
|
|
394
396
|
### trap.deactivate()
|
|
395
397
|
|
|
@@ -406,8 +408,8 @@ Returns the `trap`.
|
|
|
406
408
|
These options are used to override the focus trap's default behavior for this particular deactivation.
|
|
407
409
|
|
|
408
410
|
- **returnFocus** `{boolean}`: Default: whatever you set for `createOptions.returnFocusOnDeactivate`. If `true`, then the `setReturnFocus` option (specified when the trap was created) is used to determine where focus will be returned.
|
|
409
|
-
- **onDeactivate** `{() => void}`: Default: whatever you set for `createOptions.onDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
410
|
-
- **onPostDeactivate** `{() => void}`: Default: whatever you set for `createOptions.onPostDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
411
|
+
- **onDeactivate** `{(params: LifecycleParameters) => void}`: Default: whatever you set for `createOptions.onDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
412
|
+
- **onPostDeactivate** `{(params: LifecycleParameters) => void}`: Default: whatever you set for `createOptions.onPostDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
411
413
|
- **checkCanReturnFocus** `{(trigger: HTMLElement | SVGElement) => Promise<void>}`: Default: whatever you set for `createOptions.checkCanReturnFocus`. Not called if the `returnFocus` option is falsy. `trigger` is either the originally focused node prior to activation, or the result of the `setReturnFocus` configuration option.
|
|
412
414
|
|
|
413
415
|
### trap.pause()
|
|
@@ -434,8 +436,8 @@ This is useful in various cases, one of which is when you want one focus trap wi
|
|
|
434
436
|
|
|
435
437
|
These options are used to override the focus trap's default behavior for this particular pausing.
|
|
436
438
|
|
|
437
|
-
- **onPause** `{() => void}`: Default: whatever you chose for `createOptions.onPause`. `null` or `false` are the equivalent of a `noop`.
|
|
438
|
-
- **onPostPause** `{() => void}`: Default: whatever you chose for `createOptions.onPostPause`. `null` or `false` are the equivalent of a `noop`.
|
|
439
|
+
- **onPause** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onPause`. `null` or `false` are the equivalent of a `noop`.
|
|
440
|
+
- **onPostPause** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onPostPause`. `null` or `false` are the equivalent of a `noop`.
|
|
439
441
|
|
|
440
442
|
### trap.unpause()
|
|
441
443
|
|
|
@@ -459,8 +461,8 @@ Returns the `trap`.
|
|
|
459
461
|
|
|
460
462
|
These options are used to override the focus trap's default behavior for this particular unpausing.
|
|
461
463
|
|
|
462
|
-
- **onUnpause** `{() => void}`: Default: whatever you chose for `createOptions.onUnpause`. `null` or `false` are the equivalent of a `noop`.
|
|
463
|
-
- **onPostUnpause** `{() => void}`: Default: whatever you chose for `createOptions.onPostUnpause`. `null` or `false` are the equivalent of a `noop`.
|
|
464
|
+
- **onUnpause** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onUnpause`. `null` or `false` are the equivalent of a `noop`.
|
|
465
|
+
- **onPostUnpause** `{(params: LifecycleParameters) => void}`: Default: whatever you chose for `createOptions.onPostUnpause`. `null` or `false` are the equivalent of a `noop`.
|
|
464
466
|
|
|
465
467
|
### trap.updateContainerElements()
|
|
466
468
|
|
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 8.
|
|
2
|
+
* focus-trap 8.1.0
|
|
3
3
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
import { isFocusable, tabbable, focusable, isTabbable, getTabIndex } from 'tabbable';
|
|
@@ -1172,7 +1172,9 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
1172
1172
|
state.active = true;
|
|
1173
1173
|
state.paused = false;
|
|
1174
1174
|
state.nodeFocusedBeforeActivation = _getActiveElement(doc);
|
|
1175
|
-
onActivate === null || onActivate === void 0 || onActivate(
|
|
1175
|
+
onActivate === null || onActivate === void 0 || onActivate({
|
|
1176
|
+
trap: trap
|
|
1177
|
+
});
|
|
1176
1178
|
var finishActivation = /*#__PURE__*/function () {
|
|
1177
1179
|
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1178
1180
|
return _regenerator().w(function (_context) {
|
|
@@ -1192,7 +1194,9 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
1192
1194
|
case 1:
|
|
1193
1195
|
trap._setSubtreeIsolation(true);
|
|
1194
1196
|
updateObservedNodes();
|
|
1195
|
-
onPostActivate === null || onPostActivate === void 0 || onPostActivate(
|
|
1197
|
+
onPostActivate === null || onPostActivate === void 0 || onPostActivate({
|
|
1198
|
+
trap: trap
|
|
1199
|
+
});
|
|
1196
1200
|
case 2:
|
|
1197
1201
|
return _context.a(2);
|
|
1198
1202
|
}
|
|
@@ -1250,13 +1254,17 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
1250
1254
|
var onPostDeactivate = getOption(options, 'onPostDeactivate');
|
|
1251
1255
|
var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
|
|
1252
1256
|
var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
|
|
1253
|
-
onDeactivate === null || onDeactivate === void 0 || onDeactivate(
|
|
1257
|
+
onDeactivate === null || onDeactivate === void 0 || onDeactivate({
|
|
1258
|
+
trap: trap
|
|
1259
|
+
});
|
|
1254
1260
|
var finishDeactivation = function finishDeactivation() {
|
|
1255
1261
|
delay(function () {
|
|
1256
1262
|
if (returnFocus) {
|
|
1257
1263
|
_tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
|
|
1258
1264
|
}
|
|
1259
|
-
onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate(
|
|
1265
|
+
onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate({
|
|
1266
|
+
trap: trap
|
|
1267
|
+
});
|
|
1260
1268
|
});
|
|
1261
1269
|
};
|
|
1262
1270
|
if (returnFocus && checkCanReturnFocus) {
|
|
@@ -1316,15 +1324,21 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
1316
1324
|
if (paused) {
|
|
1317
1325
|
var onPause = getOption(options, 'onPause');
|
|
1318
1326
|
var onPostPause = getOption(options, 'onPostPause');
|
|
1319
|
-
onPause === null || onPause === void 0 || onPause(
|
|
1327
|
+
onPause === null || onPause === void 0 || onPause({
|
|
1328
|
+
trap: trap
|
|
1329
|
+
});
|
|
1320
1330
|
removeListeners();
|
|
1321
1331
|
trap._setSubtreeIsolation(false);
|
|
1322
1332
|
updateObservedNodes();
|
|
1323
|
-
onPostPause === null || onPostPause === void 0 || onPostPause(
|
|
1333
|
+
onPostPause === null || onPostPause === void 0 || onPostPause({
|
|
1334
|
+
trap: trap
|
|
1335
|
+
});
|
|
1324
1336
|
} else {
|
|
1325
1337
|
var onUnpause = getOption(options, 'onUnpause');
|
|
1326
1338
|
var onPostUnpause = getOption(options, 'onPostUnpause');
|
|
1327
|
-
onUnpause === null || onUnpause === void 0 || onUnpause(
|
|
1339
|
+
onUnpause === null || onUnpause === void 0 || onUnpause({
|
|
1340
|
+
trap: trap
|
|
1341
|
+
});
|
|
1328
1342
|
var finishUnpause = /*#__PURE__*/function () {
|
|
1329
1343
|
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
1330
1344
|
return _regenerator().w(function (_context2) {
|
|
@@ -1342,7 +1356,9 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
1342
1356
|
case 1:
|
|
1343
1357
|
trap._setSubtreeIsolation(true);
|
|
1344
1358
|
updateObservedNodes();
|
|
1345
|
-
onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause(
|
|
1359
|
+
onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause({
|
|
1360
|
+
trap: trap
|
|
1361
|
+
});
|
|
1346
1362
|
case 2:
|
|
1347
1363
|
return _context2.a(2);
|
|
1348
1364
|
}
|