focus-trap 8.0.1 → 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 +6 -0
- package/README.md +16 -16
- 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 +18 -8
- package/index.js +8 -8
- package/package.json +16 -16
package/CHANGELOG.md
CHANGED
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.
|
|
@@ -154,7 +154,7 @@ Animated dialogs have a small delay between when `onActivate` is called and when
|
|
|
154
154
|
##### onDeactivate
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
|
-
() => void
|
|
157
|
+
(params: LifecycleParameters) => void
|
|
158
158
|
```
|
|
159
159
|
|
|
160
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.
|
|
@@ -162,7 +162,7 @@ A function that will be called **before** returning focus to the node that had f
|
|
|
162
162
|
##### onPostDeactivate
|
|
163
163
|
|
|
164
164
|
```typescript
|
|
165
|
-
() => void
|
|
165
|
+
(params: LifecycleParameters) => void
|
|
166
166
|
```
|
|
167
167
|
|
|
168
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.
|
|
@@ -389,8 +389,8 @@ Returns the `trap`.
|
|
|
389
389
|
|
|
390
390
|
These options are used to override the focus trap's default behavior for this particular activation.
|
|
391
391
|
|
|
392
|
-
- **onActivate** `{() => void}`: Default: whatever you chose for `createOptions.onActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
393
|
-
- **onPostActivate** `{() => void}`: Default: whatever you chose for `createOptions.onPostActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
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
394
|
- **checkCanFocusTrap** `{(containers: Array<HTMLElement | SVGElement>) => Promise<unknown>}`: Default: whatever you chose for `createOptions.checkCanFocusTrap`.
|
|
395
395
|
|
|
396
396
|
### trap.deactivate()
|
|
@@ -408,8 +408,8 @@ Returns the `trap`.
|
|
|
408
408
|
These options are used to override the focus trap's default behavior for this particular deactivation.
|
|
409
409
|
|
|
410
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.
|
|
411
|
-
- **onDeactivate** `{() => void}`: Default: whatever you set for `createOptions.onDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
412
|
-
- **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`.
|
|
413
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.
|
|
414
414
|
|
|
415
415
|
### trap.pause()
|
|
@@ -436,8 +436,8 @@ This is useful in various cases, one of which is when you want one focus trap wi
|
|
|
436
436
|
|
|
437
437
|
These options are used to override the focus trap's default behavior for this particular pausing.
|
|
438
438
|
|
|
439
|
-
- **onPause** `{() => void}`: Default: whatever you chose for `createOptions.onPause`. `null` or `false` are the equivalent of a `noop`.
|
|
440
|
-
- **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`.
|
|
441
441
|
|
|
442
442
|
### trap.unpause()
|
|
443
443
|
|
|
@@ -461,8 +461,8 @@ Returns the `trap`.
|
|
|
461
461
|
|
|
462
462
|
These options are used to override the focus trap's default behavior for this particular unpausing.
|
|
463
463
|
|
|
464
|
-
- **onUnpause** `{() => void}`: Default: whatever you chose for `createOptions.onUnpause`. `null` or `false` are the equivalent of a `noop`.
|
|
465
|
-
- **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`.
|
|
466
466
|
|
|
467
467
|
### trap.updateContainerElements()
|
|
468
468
|
|
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 8.0
|
|
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
|
}
|