focus-trap 6.2.1 → 6.4.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 +35 -2
- package/README.md +39 -22
- package/dist/focus-trap.esm.js +137 -36
- 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 +137 -36
- package/dist/focus-trap.js.map +1 -1
- package/dist/focus-trap.min.js +2 -2
- package/dist/focus-trap.min.js.map +1 -1
- package/dist/focus-trap.umd.js +137 -36
- 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 +7 -6
- package/index.js +158 -50
- package/package.json +25 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 6.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 21c82ce: Bump tabbable from 5.1.6 to 5.2.0. There should be no changes in behavior as a result of this upgrade as `focus-trap` does not currently leverage the new `displayCheck` option.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 1baf62e: Fix focus trapped on initial focus container with tabindex=-1 when pressing shift+tab (#363)
|
|
12
|
+
|
|
13
|
+
## 6.3.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- a882d62: `clickOutsideDeactivates` can now also be a function that returns a `boolean`, similar to `allowOutsideClick`. The function receives the `MouseEvent` that triggered the click. (#289)
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 4d67dee: Fix a focus escape when pressing TAB after hiding element with focus (#281)
|
|
22
|
+
- ca32014: Bump tabbable from 5.1.4 to 5.1.5
|
|
23
|
+
|
|
24
|
+
## 6.2.3
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 036a72e: Fix crash in IE due to use of `Array.findIndex()` not supported in that browser (#257)
|
|
29
|
+
|
|
30
|
+
## 6.2.2
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- fd3f2d1: Fix a bug where a multi-container trap would cease to work if all tabbable nodes were removed from one of the containers (fixes #223). As a result, an error is now thrown if the trap is left in a state where none of its containers contain any tabbable nodes (unless a `fallbackFocus` node has been configured in the trap's options). Also, the most-recently-focused node is more reliably tracked now, should focus somehow escape the trap and be brought back in by the trap, resulting in the truly most-recently-focused node to regain focus if that ever happens.
|
|
35
|
+
|
|
3
36
|
## 6.2.1
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
6
39
|
|
|
7
40
|
- f0c2aff: Bump tabbable to [5.1.4](https://github.com/focus-trap/tabbable/blob/master/CHANGELOG.md#514) for bug fix.
|
|
8
41
|
- 2ba512b:
|
|
9
|
-
|
|
10
|
-
|
|
42
|
+
- Refactored code to use function declarations instead of hoisted functions (this should have no bearing on functionality in the build output included in `./dist`.
|
|
43
|
+
- Fixed bugs where `trap.activate()` and `trap.deactivate()` would not always return the trap (now they do in all circumstances).
|
|
11
44
|
- d26d2e1: Refactoring to use const/let, and simplify a few lines. This does NOT impact the build output published in `./dist`, however, and hence does not impact browser support.
|
|
12
45
|
|
|
13
46
|
## 6.2.0
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# focus-trap [](https://github.com/focus-trap/focus-trap/actions?query=workflow:CI+branch:master) [](./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
|
Trap focus within a DOM node.
|
|
@@ -38,7 +38,18 @@ For more advanced usage (e.g. focus traps within focus traps), you can also paus
|
|
|
38
38
|
npm install focus-trap
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
### UMD
|
|
42
|
+
|
|
43
|
+
You can also use a UMD version published to `unpkg.com` as `dist/focus-trap.umd.js` and `dist/focus-trap.umd.min.js`.
|
|
44
|
+
|
|
45
|
+
> NOTE: The UMD build does not bundle the `tabbable` dependency. Therefore you will have to also include that one, and include it _before_ `focus-trap`.
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<head>
|
|
49
|
+
<script src="https://unpkg.com/tabbable/dist/index.umd.js"></script>
|
|
50
|
+
<script src="https://unpkg.com/focus-trap/dist/focus-trap.umd.js"></script>
|
|
51
|
+
</head>
|
|
52
|
+
```
|
|
42
53
|
|
|
43
54
|
## Browser Support
|
|
44
55
|
|
|
@@ -53,34 +64,38 @@ And its only dependency, tabbable, uses [a couple of IE9+ functions](https://git
|
|
|
53
64
|
### createFocusTrap(element[, createOptions])
|
|
54
65
|
|
|
55
66
|
```javascript
|
|
56
|
-
import
|
|
57
|
-
const
|
|
67
|
+
import * as focusTrap from 'focus-trap'; // ESM
|
|
68
|
+
const focusTrap = require('focus-trap'); // CJS
|
|
69
|
+
// UMD: `focusTrap` is defined as a global on `window`
|
|
58
70
|
|
|
59
|
-
|
|
71
|
+
trap = focusTrap.createFocusTrap(element[, createOptions]);
|
|
60
72
|
```
|
|
61
73
|
|
|
62
|
-
Returns a new focus trap on `element
|
|
74
|
+
Returns a new focus trap on `element` (one or more "containers" of tabbable nodes that, together, form the total set of nodes that can be visited, with clicks or the tab key, within the trap).
|
|
63
75
|
|
|
64
76
|
`element` can be
|
|
65
|
-
- a DOM node (the focus trap itself)
|
|
66
|
-
- a selector string (which will be passed to `document.querySelector()` to find the DOM node) or
|
|
77
|
+
- a DOM node (the focus trap itself);
|
|
78
|
+
- a selector string (which will be passed to `document.querySelector()` to find the DOM node); or
|
|
67
79
|
- an array of DOM nodes or selector strings (where the order determines where the focus will go after the last tabbable element of a DOM node/selector is reached).
|
|
68
80
|
|
|
81
|
+
> A focus trap must have at least one container with at least one tabbable/focusable node in it to be considered valid. While nodes can be added/removed at runtime, with the trap adjusting to added/removed tabbable nodes, __an error will be thrown__ if the trap ever gets into a state where it determines none of its containers have any tabbable nodes in them _and_ the `fallbackFocus` option does not resolve to an alternate node where focus can go.
|
|
82
|
+
|
|
69
83
|
`createOptions`:
|
|
70
84
|
|
|
71
85
|
- **onActivate** {function}: A function that will be called when the focus trap activates.
|
|
72
86
|
- **onDeactivate** {function}: A function that will be called when the focus trap deactivates,
|
|
73
87
|
- **initialFocus** {element|string|function}: By default, when a focus trap is activated the first element in the focus trap's tab order will receive focus. With this option you can specify a different element to receive that initial focus. Can be a DOM node, or a selector string (which will be passed to `document.querySelector()` to find the DOM node), or a function that returns a DOM node.
|
|
74
|
-
- **fallbackFocus** {element|string|function}: By default, an error will be thrown if the focus trap contains no elements in its tab order. With this option you can specify a fallback element to programmatically receive focus if no other tabbable elements are found. For example, you may want a popover's `<div>` to receive focus if the popover's content includes no tabbable elements. *Make sure the fallback element has a negative `tabindex` so it can be programmatically focused.* The option value can be a DOM node, a selector string (which will be passed to `document.querySelector()` to find the DOM node), or
|
|
88
|
+
- **fallbackFocus** {element|string|function}: By default, an error will be thrown if the focus trap contains no elements in its tab order. With this option you can specify a fallback element to programmatically receive focus if no other tabbable elements are found. For example, you may want a popover's `<div>` to receive focus if the popover's content includes no tabbable elements. *Make sure the fallback element has a negative `tabindex` so it can be programmatically focused.* The option value can be a DOM node, a selector string (which will be passed to `document.querySelector()` to find the DOM node), or a function that returns a DOM node.
|
|
75
89
|
- **escapeDeactivates** {boolean}: Default: `true`. If `false`, the `Escape` key will not trigger deactivation of the focus trap. This can be useful if you want to force the user to make a decision instead of allowing an easy way out.
|
|
76
|
-
- **clickOutsideDeactivates** {boolean
|
|
77
|
-
-
|
|
90
|
+
- **clickOutsideDeactivates** {boolean|(e: MouseEvent) => boolean}: If `true` or returns `true`, a click outside the focus trap will deactivate the focus trap and allow the click event to do its thing (i.e. to pass-through to the element that was clicked). This option **takes precedence** over `allowOutsideClick` when it's set to `true`. Default: `false`.
|
|
91
|
+
- ⚠️ If you're using a password manager such as 1Password, where the app adds a clickable icon to all fillable fields, you should avoid using this option, and instead use the `allowOutsideClick` option to better control exactly when the focus trap can be deactivated. The clickable icons are usually positioned absolutely, floating on top of the fields, and therefore _not_ part of the container the trap is managing. When using the `clickOutsideDeactivates` option, clicking on a field's 1Password icon will likely cause the trap to be unintentionally deactivated.
|
|
92
|
+
- **allowOutsideClick** {boolean|(e: MouseEvent) => boolean}: If set and is or returns `true`, a click outside the focus trap will not be prevented, even when `clickOutsideDeactivates` is `false`. When `clickOutsideDeactivates` is `true`, this option is **ignored** (i.e. if it's a function, it will not be called). Use this option to control if (and even which) clicks are allowed outside the trap in conjunction with `clickOutsideDeactivates: false`. Default: `false`.
|
|
78
93
|
- **returnFocusOnDeactivate** {boolean}: Default: `true`. If `false`, when the trap is deactivated, focus will *not* return to the element that had focus before activation.
|
|
79
94
|
- **setReturnFocus** {element|string|function}: By default, focus trap on deactivation will return to the element that was focused before activation. With this option you can specify another element to programmatically receive focus after deactivation. Can be a DOM node, or a selector string (which will be passed to `document.querySelector()` to find the DOM node), or a function that returns a DOM node.
|
|
80
95
|
- **preventScroll** {boolean}: By default, focus() will scroll to the element if not in viewport. It can produce unintended effects like scrolling back to the top of a modal. If set to `true`, no scroll will happen.
|
|
81
96
|
- **delayInitialFocus** {boolean}: Default: `true`. Delays the autofocus when the focus trap is activated. This prevents elements within the focusable element from capturing the event that triggered the focus trap activation.
|
|
82
97
|
|
|
83
|
-
###
|
|
98
|
+
### trap.activate([activateOptions])
|
|
84
99
|
|
|
85
100
|
Activates the focus trap, adding various event listeners to the document.
|
|
86
101
|
|
|
@@ -92,7 +107,7 @@ If focus is already within it the trap, it remains unaffected. Otherwise, focus-
|
|
|
92
107
|
|
|
93
108
|
If none of the above exist, an error will be thrown. You cannot have a focus trap that lacks focus.
|
|
94
109
|
|
|
95
|
-
Returns the `
|
|
110
|
+
Returns the `trap`.
|
|
96
111
|
|
|
97
112
|
`activateOptions`:
|
|
98
113
|
|
|
@@ -100,11 +115,11 @@ These options are used to override the focus trap's default behavior for this pa
|
|
|
100
115
|
|
|
101
116
|
- **onActivate** {function | null | false}: Default: whatever you chose for `createOptions.onActivate`. `null` or `false` are the equivalent of a `noop`.
|
|
102
117
|
|
|
103
|
-
###
|
|
118
|
+
### trap.deactivate([deactivateOptions])
|
|
104
119
|
|
|
105
120
|
Deactivates the focus trap.
|
|
106
121
|
|
|
107
|
-
Returns the `
|
|
122
|
+
Returns the `trap`.
|
|
108
123
|
|
|
109
124
|
`deactivateOptions`:
|
|
110
125
|
|
|
@@ -113,19 +128,19 @@ These options are used to override the focus trap's default behavior for this pa
|
|
|
113
128
|
- **returnFocus** {boolean}: Default: whatever you chose for `createOptions.returnFocusOnDeactivate`.
|
|
114
129
|
- **onDeactivate** {function | null | false}: Default: whatever you chose for `createOptions.onDeactivate`. `null` or `false` are the equivalent of a `noop`.
|
|
115
130
|
|
|
116
|
-
###
|
|
131
|
+
### trap.pause()
|
|
117
132
|
|
|
118
133
|
Pause an active focus trap's event listening without deactivating the trap.
|
|
119
134
|
|
|
120
135
|
If the focus trap has not been activated, nothing happens.
|
|
121
136
|
|
|
122
|
-
Returns the `
|
|
137
|
+
Returns the `trap`.
|
|
123
138
|
|
|
124
139
|
Any `onDeactivate` callback will not be called, and focus will not return to the element that was focused before the trap's activation. But the trap's behavior will be paused.
|
|
125
140
|
|
|
126
141
|
This is useful in various cases, one of which is when you want one focus trap within another. `demo-six` exemplifies how you can implement this.
|
|
127
142
|
|
|
128
|
-
###
|
|
143
|
+
### trap.unpause()
|
|
129
144
|
|
|
130
145
|
Unpause an active focus trap. (See `pause()`, above.)
|
|
131
146
|
|
|
@@ -133,9 +148,9 @@ Focus is forced into the trap just as described for `focusTrap.activate()`.
|
|
|
133
148
|
|
|
134
149
|
If the focus trap has not been activated or has not been paused, nothing happens.
|
|
135
150
|
|
|
136
|
-
Returns the `
|
|
151
|
+
Returns the `trap`.
|
|
137
152
|
|
|
138
|
-
###
|
|
153
|
+
### trap.updateContainerElements()
|
|
139
154
|
|
|
140
155
|
Update the element(s) that are used as containers for the focus trap.
|
|
141
156
|
|
|
@@ -143,7 +158,7 @@ When you call the function `createFocusTrap`, you pass in an element (or selecto
|
|
|
143
158
|
|
|
144
159
|
A use case for this is found in focus-trap-react, where React `ref`'s may not be initialized yet, but when they are you want to have them be a container element.
|
|
145
160
|
|
|
146
|
-
Returns the `
|
|
161
|
+
Returns the `trap`.
|
|
147
162
|
|
|
148
163
|
## Examples
|
|
149
164
|
|
|
@@ -230,7 +245,9 @@ In alphabetical order:
|
|
|
230
245
|
<td align="center"><a href="https://github.com/bparish628"><img src="https://avatars1.githubusercontent.com/u/8492971?v=4" width="100px;" alt=""/><br /><sub><b>Benjamin Parish</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Abparish628" title="Bug reports">🐛</a></td>
|
|
231
246
|
<td align="center"><a href="https://scottblinch.me/"><img src="https://avatars2.githubusercontent.com/u/4682114?v=4" width="100px;" alt=""/><br /><sub><b>Scott Blinch</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=scottblinch" title="Documentation">📖</a></td>
|
|
232
247
|
<td align="center"><a href="https://clintgoodman.com"><img src="https://avatars3.githubusercontent.com/u/5473697?v=4" width="100px;" alt=""/><br /><sub><b>Clint Goodman</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=cgood92" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=cgood92" title="Documentation">📖</a> <a href="#example-cgood92" title="Examples">💡</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=cgood92" title="Tests">⚠️</a></td>
|
|
233
|
-
<td align="center"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4" width="100px;" alt=""/><br /><sub><b>Zioth</b></sub></a><br /><a href="#ideas-zioth" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
248
|
+
<td align="center"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4" width="100px;" alt=""/><br /><sub><b>Zioth</b></sub></a><br /><a href="#ideas-zioth" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Azioth" title="Bug reports">🐛</a></td>
|
|
249
|
+
<td align="center"><a href="https://github.com/randypuro"><img src="https://avatars2.githubusercontent.com/u/2579?v=4" width="100px;" alt=""/><br /><sub><b>Randy Puro</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Arandypuro" title="Bug reports">🐛</a></td>
|
|
250
|
+
<td align="center"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4" width="100px;" alt=""/><br /><sub><b>Tyler Hawkins</b></sub></a><br /><a href="#tool-thawkin3" title="Tools">🔧</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=thawkin3" title="Tests">⚠️</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=thawkin3" title="Documentation">📖</a></td>
|
|
234
251
|
</tr>
|
|
235
252
|
</table>
|
|
236
253
|
|
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 6.
|
|
2
|
+
* focus-trap 6.4.0
|
|
3
3
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
import { tabbable, isFocusable } from 'tabbable';
|
|
@@ -105,6 +105,37 @@ var isTabEvent = function isTabEvent(e) {
|
|
|
105
105
|
|
|
106
106
|
var delay = function delay(fn) {
|
|
107
107
|
return setTimeout(fn, 0);
|
|
108
|
+
}; // Array.find/findIndex() are not supported on IE; this replicates enough
|
|
109
|
+
// of Array.findIndex() for our needs
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
var findIndex = function findIndex(arr, fn) {
|
|
113
|
+
var idx = -1;
|
|
114
|
+
arr.every(function (value, i) {
|
|
115
|
+
if (fn(value)) {
|
|
116
|
+
idx = i;
|
|
117
|
+
return false; // break
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true; // next
|
|
121
|
+
});
|
|
122
|
+
return idx;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Get an option's value when it could be a plain value, or a handler that provides
|
|
126
|
+
* the value.
|
|
127
|
+
* @param {*} value Option's value to check.
|
|
128
|
+
* @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
|
|
129
|
+
* @returns {*} The `value`, or the handler's returned value.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
var valueOrHandler = function valueOrHandler(value) {
|
|
134
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
135
|
+
params[_key - 1] = arguments[_key];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return typeof value === 'function' ? value.apply(void 0, params) : value;
|
|
108
139
|
};
|
|
109
140
|
|
|
110
141
|
var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
@@ -119,7 +150,13 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
119
150
|
var state = {
|
|
120
151
|
// @type {Array<HTMLElement>}
|
|
121
152
|
containers: [],
|
|
122
|
-
//
|
|
153
|
+
// list of objects identifying the first and last tabbable nodes in all containers/groups in
|
|
154
|
+
// the trap
|
|
155
|
+
// NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
|
|
156
|
+
// is active, but the trap should never get to a state where there isn't at least one group
|
|
157
|
+
// with at least one tabbable node in it (that would lead to an error condition that would
|
|
158
|
+
// result in an error being thrown)
|
|
159
|
+
// @type {Array<{ container: HTMLElement, firstTabbableNode: HTMLElement|null, lastTabbableNode: HTMLElement|null }>}
|
|
123
160
|
tabbableGroups: [],
|
|
124
161
|
nodeFocusedBeforeActivation: null,
|
|
125
162
|
mostRecentlyFocusedNode: null,
|
|
@@ -185,11 +222,24 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
185
222
|
var updateTabbableNodes = function updateTabbableNodes() {
|
|
186
223
|
state.tabbableGroups = state.containers.map(function (container) {
|
|
187
224
|
var tabbableNodes = tabbable(container);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
225
|
+
|
|
226
|
+
if (tabbableNodes.length > 0) {
|
|
227
|
+
return {
|
|
228
|
+
container: container,
|
|
229
|
+
firstTabbableNode: tabbableNodes[0],
|
|
230
|
+
lastTabbableNode: tabbableNodes[tabbableNodes.length - 1]
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return undefined;
|
|
235
|
+
}).filter(function (group) {
|
|
236
|
+
return !!group;
|
|
237
|
+
}); // remove groups with no tabbable nodes
|
|
238
|
+
// throw if no groups have tabbable nodes and we don't have a fallback focus node either
|
|
239
|
+
|
|
240
|
+
if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus')) {
|
|
241
|
+
throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
|
|
242
|
+
}
|
|
193
243
|
};
|
|
194
244
|
|
|
195
245
|
var tryFocus = function tryFocus(node) {
|
|
@@ -225,7 +275,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
225
275
|
return;
|
|
226
276
|
}
|
|
227
277
|
|
|
228
|
-
if (config.clickOutsideDeactivates) {
|
|
278
|
+
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
|
|
229
279
|
// immediately deactivate the trap
|
|
230
280
|
trap.deactivate({
|
|
231
281
|
// if, on deactivation, we should return focus to the node originally-focused
|
|
@@ -247,7 +297,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
247
297
|
// then on mobile they will be blocked anyways if `touchstart` is blocked.)
|
|
248
298
|
|
|
249
299
|
|
|
250
|
-
if (
|
|
300
|
+
if (valueOrHandler(config.allowOutsideClick, e)) {
|
|
251
301
|
// allow the click outside the trap to take place
|
|
252
302
|
return;
|
|
253
303
|
} // otherwise, prevent the click
|
|
@@ -258,13 +308,17 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
258
308
|
|
|
259
309
|
|
|
260
310
|
var checkFocusIn = function checkFocusIn(e) {
|
|
261
|
-
// In Firefox when you Tab out of an iframe the Document is briefly focused.
|
|
262
|
-
if (containersContain(e.target) || e.target instanceof Document) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
311
|
+
var targetContained = containersContain(e.target); // In Firefox when you Tab out of an iframe the Document is briefly focused.
|
|
265
312
|
|
|
266
|
-
e.
|
|
267
|
-
|
|
313
|
+
if (targetContained || e.target instanceof Document) {
|
|
314
|
+
if (targetContained) {
|
|
315
|
+
state.mostRecentlyFocusedNode = e.target;
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
// escaped! pull it back in to where it just left
|
|
319
|
+
e.stopImmediatePropagation();
|
|
320
|
+
tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
|
|
321
|
+
}
|
|
268
322
|
}; // Hijack Tab events on the first and last focusable nodes of the trap,
|
|
269
323
|
// in order to prevent focus from escaping. If it escapes for even a
|
|
270
324
|
// moment it can end up scrolling the page and causing confusion so we
|
|
@@ -275,35 +329,82 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
275
329
|
updateTabbableNodes();
|
|
276
330
|
var destinationNode = null;
|
|
277
331
|
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
332
|
+
if (state.tabbableGroups.length > 0) {
|
|
333
|
+
// make sure the target is actually contained in a group
|
|
334
|
+
// NOTE: the target may also be the container itself if it's tabbable
|
|
335
|
+
// with tabIndex='-1' and was given initial focus
|
|
336
|
+
var containerIndex = findIndex(state.tabbableGroups, function (_ref) {
|
|
337
|
+
var container = _ref.container;
|
|
338
|
+
return container.contains(e.target);
|
|
282
339
|
});
|
|
283
340
|
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
341
|
+
if (containerIndex < 0) {
|
|
342
|
+
// target not found in any group: quite possible focus has escaped the trap,
|
|
343
|
+
// so bring it back in to...
|
|
344
|
+
if (e.shiftKey) {
|
|
345
|
+
// ...the last node in the last group
|
|
346
|
+
destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
|
|
347
|
+
} else {
|
|
348
|
+
// ...the first node in the first group
|
|
349
|
+
destinationNode = state.tabbableGroups[0].firstTabbableNode;
|
|
350
|
+
}
|
|
351
|
+
} else if (e.shiftKey) {
|
|
352
|
+
// REVERSE
|
|
353
|
+
// is the target the first tabbable node in a group?
|
|
354
|
+
var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
|
|
355
|
+
var firstTabbableNode = _ref2.firstTabbableNode;
|
|
356
|
+
return e.target === firstTabbableNode;
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
if (startOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) {
|
|
360
|
+
// an exception case where the target is the container itself, in which
|
|
361
|
+
// case, we should handle shift+tab as if focus were on the container's
|
|
362
|
+
// first tabbable node, and go to the last tabbable node of the LAST group
|
|
363
|
+
startOfGroupIndex = containerIndex;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (startOfGroupIndex >= 0) {
|
|
367
|
+
// YES: then shift+tab should go to the last tabbable node in the
|
|
368
|
+
// previous group (and wrap around to the last tabbable node of
|
|
369
|
+
// the LAST group if it's the first tabbable node of the FIRST group)
|
|
370
|
+
var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
|
|
371
|
+
var destinationGroup = state.tabbableGroups[destinationGroupIndex];
|
|
372
|
+
destinationNode = destinationGroup.lastTabbableNode;
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
// FORWARD
|
|
376
|
+
// is the target the last tabbable node in a group?
|
|
377
|
+
var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
|
|
378
|
+
var lastTabbableNode = _ref3.lastTabbableNode;
|
|
379
|
+
return e.target === lastTabbableNode;
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
if (lastOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) {
|
|
383
|
+
// an exception case where the target is the container itself, in which
|
|
384
|
+
// case, we should handle tab as if focus were on the container's
|
|
385
|
+
// last tabbable node, and go to the first tabbable node of the FIRST group
|
|
386
|
+
lastOfGroupIndex = containerIndex;
|
|
387
|
+
}
|
|
294
388
|
|
|
295
|
-
|
|
296
|
-
|
|
389
|
+
if (lastOfGroupIndex >= 0) {
|
|
390
|
+
// YES: then tab should go to the first tabbable node in the next
|
|
391
|
+
// group (and wrap around to the first tabbable node of the FIRST
|
|
392
|
+
// group if it's the last tabbable node of the LAST group)
|
|
393
|
+
var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
|
|
297
394
|
|
|
298
|
-
|
|
299
|
-
|
|
395
|
+
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
|
|
396
|
+
destinationNode = _destinationGroup.firstTabbableNode;
|
|
397
|
+
}
|
|
300
398
|
}
|
|
399
|
+
} else {
|
|
400
|
+
destinationNode = getNodeForOption('fallbackFocus');
|
|
301
401
|
}
|
|
302
402
|
|
|
303
403
|
if (destinationNode) {
|
|
304
404
|
e.preventDefault();
|
|
305
405
|
tryFocus(destinationNode);
|
|
306
|
-
}
|
|
406
|
+
} // else, let the browser take care of [shift+]tab and move the focus
|
|
407
|
+
|
|
307
408
|
};
|
|
308
409
|
|
|
309
410
|
var checkKey = function checkKey(e) {
|
|
@@ -320,7 +421,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
320
421
|
};
|
|
321
422
|
|
|
322
423
|
var checkClick = function checkClick(e) {
|
|
323
|
-
if (config.clickOutsideDeactivates) {
|
|
424
|
+
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
|
|
324
425
|
return;
|
|
325
426
|
}
|
|
326
427
|
|
|
@@ -328,7 +429,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
328
429
|
return;
|
|
329
430
|
}
|
|
330
431
|
|
|
331
|
-
if (
|
|
432
|
+
if (valueOrHandler(config.allowOutsideClick, e)) {
|
|
332
433
|
return;
|
|
333
434
|
}
|
|
334
435
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap.esm.js","sources":["../index.js"],"sourcesContent":["import { tabbable, isFocusable } from 'tabbable';\n\nlet activeFocusDelay;\n\nconst activeFocusTraps = (function () {\n const trapQueue = [];\n return {\n activateTrap(trap) {\n if (trapQueue.length > 0) {\n const activeTrap = trapQueue[trapQueue.length - 1];\n if (activeTrap !== trap) {\n activeTrap.pause();\n }\n }\n\n const trapIndex = trapQueue.indexOf(trap);\n if (trapIndex === -1) {\n trapQueue.push(trap);\n } else {\n // move this existing trap to the front of the queue\n trapQueue.splice(trapIndex, 1);\n trapQueue.push(trap);\n }\n },\n\n deactivateTrap(trap) {\n const trapIndex = trapQueue.indexOf(trap);\n if (trapIndex !== -1) {\n trapQueue.splice(trapIndex, 1);\n }\n\n if (trapQueue.length > 0) {\n trapQueue[trapQueue.length - 1].unpause();\n }\n },\n };\n})();\n\nconst isSelectableInput = function (node) {\n return (\n node.tagName &&\n node.tagName.toLowerCase() === 'input' &&\n typeof node.select === 'function'\n );\n};\n\nconst isEscapeEvent = function (e) {\n return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;\n};\n\nconst isTabEvent = function (e) {\n return e.key === 'Tab' || e.keyCode === 9;\n};\n\nconst delay = function (fn) {\n return setTimeout(fn, 0);\n};\n\nconst createFocusTrap = function (elements, userOptions) {\n const doc = document;\n\n const config = {\n returnFocusOnDeactivate: true,\n escapeDeactivates: true,\n delayInitialFocus: true,\n ...userOptions,\n };\n\n const state = {\n // @type {Array<HTMLElement>}\n containers: [],\n // @type {{ firstTabbableNode: HTMLElement, lastTabbableNode: HTMLElement }}\n tabbableGroups: [],\n nodeFocusedBeforeActivation: null,\n mostRecentlyFocusedNode: null,\n active: false,\n paused: false,\n };\n\n let trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later\n\n const containersContain = function (element) {\n return state.containers.some((container) => container.contains(element));\n };\n\n const getNodeForOption = function (optionName) {\n const optionValue = config[optionName];\n if (!optionValue) {\n return null;\n }\n\n let node = optionValue;\n\n if (typeof optionValue === 'string') {\n node = doc.querySelector(optionValue);\n if (!node) {\n throw new Error(`\\`${optionName}\\` refers to no known node`);\n }\n }\n\n if (typeof optionValue === 'function') {\n node = optionValue();\n if (!node) {\n throw new Error(`\\`${optionName}\\` did not return a node`);\n }\n }\n\n return node;\n };\n\n const getInitialFocusNode = function () {\n let node;\n\n if (getNodeForOption('initialFocus') !== null) {\n node = getNodeForOption('initialFocus');\n } else if (containersContain(doc.activeElement)) {\n node = doc.activeElement;\n } else {\n const firstTabbableGroup = state.tabbableGroups[0];\n const firstTabbableNode =\n firstTabbableGroup && firstTabbableGroup.firstTabbableNode;\n node = firstTabbableNode || getNodeForOption('fallbackFocus');\n }\n\n if (!node) {\n throw new Error(\n 'Your focus-trap needs to have at least one focusable element'\n );\n }\n\n return node;\n };\n\n const updateTabbableNodes = function () {\n state.tabbableGroups = state.containers.map((container) => {\n const tabbableNodes = tabbable(container);\n\n return {\n firstTabbableNode: tabbableNodes[0],\n lastTabbableNode: tabbableNodes[tabbableNodes.length - 1],\n };\n });\n };\n\n const tryFocus = function (node) {\n if (node === doc.activeElement) {\n return;\n }\n if (!node || !node.focus) {\n tryFocus(getInitialFocusNode());\n return;\n }\n\n node.focus({ preventScroll: !!config.preventScroll });\n state.mostRecentlyFocusedNode = node;\n\n if (isSelectableInput(node)) {\n node.select();\n }\n };\n\n const getReturnFocusNode = function (previousActiveElement) {\n const node = getNodeForOption('setReturnFocus');\n\n return node ? node : previousActiveElement;\n };\n\n // This needs to be done on mousedown and touchstart instead of click\n // so that it precedes the focus event.\n const checkPointerDown = function (e) {\n if (containersContain(e.target)) {\n // allow the click since it ocurred inside the trap\n return;\n }\n\n if (config.clickOutsideDeactivates) {\n // immediately deactivate the trap\n trap.deactivate({\n // if, on deactivation, we should return focus to the node originally-focused\n // when the trap was activated (or the configured `setReturnFocus` node),\n // then assume it's also OK to return focus to the outside node that was\n // just clicked, causing deactivation, as long as that node is focusable;\n // if it isn't focusable, then return focus to the original node focused\n // on activation (or the configured `setReturnFocus` node)\n // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,\n // which will result in the outside click setting focus to the node\n // that was clicked, whether it's focusable or not; by setting\n // `returnFocus: true`, we'll attempt to re-focus the node originally-focused\n // on activation (or the configured `setReturnFocus` node)\n returnFocus: config.returnFocusOnDeactivate && !isFocusable(e.target),\n });\n return;\n }\n\n // This is needed for mobile devices.\n // (If we'll only let `click` events through,\n // then on mobile they will be blocked anyways if `touchstart` is blocked.)\n if (\n config.allowOutsideClick &&\n (typeof config.allowOutsideClick === 'boolean'\n ? config.allowOutsideClick\n : config.allowOutsideClick(e))\n ) {\n // allow the click outside the trap to take place\n return;\n }\n\n // otherwise, prevent the click\n e.preventDefault();\n };\n\n // In case focus escapes the trap for some strange reason, pull it back in.\n const checkFocusIn = function (e) {\n // In Firefox when you Tab out of an iframe the Document is briefly focused.\n if (containersContain(e.target) || e.target instanceof Document) {\n return;\n }\n e.stopImmediatePropagation();\n tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());\n };\n\n // Hijack Tab events on the first and last focusable nodes of the trap,\n // in order to prevent focus from escaping. If it escapes for even a\n // moment it can end up scrolling the page and causing confusion so we\n // kind of need to capture the action at the keydown phase.\n const checkTab = function (e) {\n updateTabbableNodes();\n\n let destinationNode = null;\n\n if (e.shiftKey) {\n const startOfGroupIndex = state.tabbableGroups.findIndex(\n ({ firstTabbableNode }) => e.target === firstTabbableNode\n );\n\n if (startOfGroupIndex >= 0) {\n const destinationGroupIndex =\n startOfGroupIndex === 0\n ? state.tabbableGroups.length - 1\n : startOfGroupIndex - 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n destinationNode = destinationGroup.lastTabbableNode;\n }\n } else {\n const lastOfGroupIndex = state.tabbableGroups.findIndex(\n ({ lastTabbableNode }) => e.target === lastTabbableNode\n );\n\n if (lastOfGroupIndex >= 0) {\n const destinationGroupIndex =\n lastOfGroupIndex === state.tabbableGroups.length - 1\n ? 0\n : lastOfGroupIndex + 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n destinationNode = destinationGroup.firstTabbableNode;\n }\n }\n\n if (destinationNode) {\n e.preventDefault();\n\n tryFocus(destinationNode);\n }\n };\n\n const checkKey = function (e) {\n if (config.escapeDeactivates !== false && isEscapeEvent(e)) {\n e.preventDefault();\n trap.deactivate();\n return;\n }\n\n if (isTabEvent(e)) {\n checkTab(e);\n return;\n }\n };\n\n const checkClick = function (e) {\n if (config.clickOutsideDeactivates) {\n return;\n }\n if (containersContain(e.target)) {\n return;\n }\n if (\n config.allowOutsideClick &&\n (typeof config.allowOutsideClick === 'boolean'\n ? config.allowOutsideClick\n : config.allowOutsideClick(e))\n ) {\n return;\n }\n e.preventDefault();\n e.stopImmediatePropagation();\n };\n\n //\n // EVENT LISTENERS\n //\n\n const addListeners = function () {\n if (!state.active) {\n return;\n }\n\n // There can be only one listening focus trap at a time\n activeFocusTraps.activateTrap(trap);\n\n // Delay ensures that the focused element doesn't capture the event\n // that caused the focus trap activation.\n activeFocusDelay = config.delayInitialFocus\n ? delay(function () {\n tryFocus(getInitialFocusNode());\n })\n : tryFocus(getInitialFocusNode());\n\n doc.addEventListener('focusin', checkFocusIn, true);\n doc.addEventListener('mousedown', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('touchstart', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('click', checkClick, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkKey, {\n capture: true,\n passive: false,\n });\n\n return trap;\n };\n\n const removeListeners = function () {\n if (!state.active) {\n return;\n }\n\n doc.removeEventListener('focusin', checkFocusIn, true);\n doc.removeEventListener('mousedown', checkPointerDown, true);\n doc.removeEventListener('touchstart', checkPointerDown, true);\n doc.removeEventListener('click', checkClick, true);\n doc.removeEventListener('keydown', checkKey, true);\n\n return trap;\n };\n\n //\n // TRAP DEFINITION\n //\n\n trap = {\n activate(activateOptions) {\n if (state.active) {\n return this;\n }\n\n updateTabbableNodes();\n\n state.active = true;\n state.paused = false;\n state.nodeFocusedBeforeActivation = doc.activeElement;\n\n const onActivate =\n activateOptions && activateOptions.onActivate\n ? activateOptions.onActivate\n : config.onActivate;\n if (onActivate) {\n onActivate();\n }\n\n addListeners();\n return this;\n },\n\n deactivate(deactivateOptions) {\n if (!state.active) {\n return this;\n }\n\n clearTimeout(activeFocusDelay);\n\n removeListeners();\n state.active = false;\n state.paused = false;\n\n activeFocusTraps.deactivateTrap(trap);\n\n const onDeactivate =\n deactivateOptions && deactivateOptions.onDeactivate !== undefined\n ? deactivateOptions.onDeactivate\n : config.onDeactivate;\n if (onDeactivate) {\n onDeactivate();\n }\n\n const returnFocus =\n deactivateOptions && deactivateOptions.returnFocus !== undefined\n ? deactivateOptions.returnFocus\n : config.returnFocusOnDeactivate;\n\n if (returnFocus) {\n delay(function () {\n tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));\n });\n }\n\n return this;\n },\n\n pause() {\n if (state.paused || !state.active) {\n return this;\n }\n\n state.paused = true;\n removeListeners();\n\n return this;\n },\n\n unpause() {\n if (!state.paused || !state.active) {\n return this;\n }\n\n state.paused = false;\n updateTabbableNodes();\n addListeners();\n\n return this;\n },\n\n updateContainerElements(containerElements) {\n const elementsAsArray = [].concat(containerElements).filter(Boolean);\n\n state.containers = elementsAsArray.map((element) =>\n typeof element === 'string' ? doc.querySelector(element) : element\n );\n\n if (state.active) {\n updateTabbableNodes();\n }\n\n return this;\n },\n };\n\n // initialize container elements\n trap.updateContainerElements(elements);\n\n return trap;\n};\n\nexport { createFocusTrap };\n"],"names":["activeFocusDelay","activeFocusTraps","trapQueue","activateTrap","trap","length","activeTrap","pause","trapIndex","indexOf","push","splice","deactivateTrap","unpause","isSelectableInput","node","tagName","toLowerCase","select","isEscapeEvent","e","key","keyCode","isTabEvent","delay","fn","setTimeout","createFocusTrap","elements","userOptions","doc","document","config","returnFocusOnDeactivate","escapeDeactivates","delayInitialFocus","state","containers","tabbableGroups","nodeFocusedBeforeActivation","mostRecentlyFocusedNode","active","paused","containersContain","element","some","container","contains","getNodeForOption","optionName","optionValue","querySelector","Error","getInitialFocusNode","activeElement","firstTabbableGroup","firstTabbableNode","updateTabbableNodes","map","tabbableNodes","tabbable","lastTabbableNode","tryFocus","focus","preventScroll","getReturnFocusNode","previousActiveElement","checkPointerDown","target","clickOutsideDeactivates","deactivate","returnFocus","isFocusable","allowOutsideClick","preventDefault","checkFocusIn","Document","stopImmediatePropagation","checkTab","destinationNode","shiftKey","startOfGroupIndex","findIndex","destinationGroupIndex","destinationGroup","lastOfGroupIndex","checkKey","checkClick","addListeners","addEventListener","capture","passive","removeListeners","removeEventListener","activate","activateOptions","onActivate","deactivateOptions","clearTimeout","onDeactivate","undefined","updateContainerElements","containerElements","elementsAsArray","concat","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAIA,gBAAJ;;AAEA,IAAMC,gBAAgB,GAAI,YAAY;AACpC,MAAMC,SAAS,GAAG,EAAlB;AACA,SAAO;AACLC,IAAAA,YADK,wBACQC,IADR,EACc;AACjB,UAAIF,SAAS,CAACG,MAA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EK;AACR,UAAI,CAACuB,KAAK,CAACM,MAAP,IAAiB,CAACN,KAAK,CAACK,MAA5B,EAAoC;AAClC,eAAO,IAAP;AACD;;AAEDL,MAAAA,KAAK,CAACM,MAAN,GAAe,KAAf;AACAe,MAAAA,mBAAmB;AACnB+B,MAAAA,YAAY;AAEZ,aAAO,IAAP;AACD,KAhFI;AAkFLa,IAAAA,uBAlFK,mCAkFmBC,iBAlFnB,EAkFsC;AACzC,UAAMC,eAAe,GAAG,GAAGC,MAAH,CAAUF,iBAAV,EAA6BG,MAA7B,CAAoCC,OAApC,CAAxB;AAEAtE,MAAAA,KAAK,CAACC,UAAN,GAAmBkE,eAAe,CAAC7C,GAAhB,CAAoB,UAACd,OAAD;AAAA,eACrC,OAAOA,OAAP,KAAmB,QAAnB,GAA8Bd,GAAG,CAACqB,aAAJ,CAAkBP,OAAlB,CAA9B,GAA2DA,OADtB;AAAA,OAApB,CAAnB;;AAIA,UAAIR,KAAK,CAACK,MAAV,EAAkB;AAChBgB,QAAAA,mBAAmB;AACpB;;AAED,aAAO,IAAP;AACD;AA9FI,GAAP,CA5SuD;;AA8YvDrD,EAAAA,IAAI,CAACiG,uBAAL,CAA6BzE,QAA7B;AAEA,SAAOxB,IAAP;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"focus-trap.esm.js","sources":["../index.js"],"sourcesContent":["import { tabbable, isFocusable } from 'tabbable';\n\nlet activeFocusDelay;\n\nconst activeFocusTraps = (function () {\n const trapQueue = [];\n return {\n activateTrap(trap) {\n if (trapQueue.length > 0) {\n const activeTrap = trapQueue[trapQueue.length - 1];\n if (activeTrap !== trap) {\n activeTrap.pause();\n }\n }\n\n const trapIndex = trapQueue.indexOf(trap);\n if (trapIndex === -1) {\n trapQueue.push(trap);\n } else {\n // move this existing trap to the front of the queue\n trapQueue.splice(trapIndex, 1);\n trapQueue.push(trap);\n }\n },\n\n deactivateTrap(trap) {\n const trapIndex = trapQueue.indexOf(trap);\n if (trapIndex !== -1) {\n trapQueue.splice(trapIndex, 1);\n }\n\n if (trapQueue.length > 0) {\n trapQueue[trapQueue.length - 1].unpause();\n }\n },\n };\n})();\n\nconst isSelectableInput = function (node) {\n return (\n node.tagName &&\n node.tagName.toLowerCase() === 'input' &&\n typeof node.select === 'function'\n );\n};\n\nconst isEscapeEvent = function (e) {\n return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;\n};\n\nconst isTabEvent = function (e) {\n return e.key === 'Tab' || e.keyCode === 9;\n};\n\nconst delay = function (fn) {\n return setTimeout(fn, 0);\n};\n\n// Array.find/findIndex() are not supported on IE; this replicates enough\n// of Array.findIndex() for our needs\nconst findIndex = function (arr, fn) {\n let idx = -1;\n\n arr.every(function (value, i) {\n if (fn(value)) {\n idx = i;\n return false; // break\n }\n\n return true; // next\n });\n\n return idx;\n};\n\n/**\n * Get an option's value when it could be a plain value, or a handler that provides\n * the value.\n * @param {*} value Option's value to check.\n * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.\n * @returns {*} The `value`, or the handler's returned value.\n */\nconst valueOrHandler = function (value, ...params) {\n return typeof value === 'function' ? value(...params) : value;\n};\n\nconst createFocusTrap = function (elements, userOptions) {\n const doc = document;\n\n const config = {\n returnFocusOnDeactivate: true,\n escapeDeactivates: true,\n delayInitialFocus: true,\n ...userOptions,\n };\n\n const state = {\n // @type {Array<HTMLElement>}\n containers: [],\n\n // list of objects identifying the first and last tabbable nodes in all containers/groups in\n // the trap\n // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap\n // is active, but the trap should never get to a state where there isn't at least one group\n // with at least one tabbable node in it (that would lead to an error condition that would\n // result in an error being thrown)\n // @type {Array<{ container: HTMLElement, firstTabbableNode: HTMLElement|null, lastTabbableNode: HTMLElement|null }>}\n tabbableGroups: [],\n\n nodeFocusedBeforeActivation: null,\n mostRecentlyFocusedNode: null,\n active: false,\n paused: false,\n };\n\n let trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later\n\n const containersContain = function (element) {\n return state.containers.some((container) => container.contains(element));\n };\n\n const getNodeForOption = function (optionName) {\n const optionValue = config[optionName];\n if (!optionValue) {\n return null;\n }\n\n let node = optionValue;\n\n if (typeof optionValue === 'string') {\n node = doc.querySelector(optionValue);\n if (!node) {\n throw new Error(`\\`${optionName}\\` refers to no known node`);\n }\n }\n\n if (typeof optionValue === 'function') {\n node = optionValue();\n if (!node) {\n throw new Error(`\\`${optionName}\\` did not return a node`);\n }\n }\n\n return node;\n };\n\n const getInitialFocusNode = function () {\n let node;\n\n if (getNodeForOption('initialFocus') !== null) {\n node = getNodeForOption('initialFocus');\n } else if (containersContain(doc.activeElement)) {\n node = doc.activeElement;\n } else {\n const firstTabbableGroup = state.tabbableGroups[0];\n const firstTabbableNode =\n firstTabbableGroup && firstTabbableGroup.firstTabbableNode;\n node = firstTabbableNode || getNodeForOption('fallbackFocus');\n }\n\n if (!node) {\n throw new Error(\n 'Your focus-trap needs to have at least one focusable element'\n );\n }\n\n return node;\n };\n\n const updateTabbableNodes = function () {\n state.tabbableGroups = state.containers\n .map((container) => {\n const tabbableNodes = tabbable(container);\n\n if (tabbableNodes.length > 0) {\n return {\n container,\n firstTabbableNode: tabbableNodes[0],\n lastTabbableNode: tabbableNodes[tabbableNodes.length - 1],\n };\n }\n\n return undefined;\n })\n .filter((group) => !!group); // remove groups with no tabbable nodes\n\n // throw if no groups have tabbable nodes and we don't have a fallback focus node either\n if (\n state.tabbableGroups.length <= 0 &&\n !getNodeForOption('fallbackFocus')\n ) {\n throw new Error(\n 'Your focus-trap must have at least one container with at least one tabbable node in it at all times'\n );\n }\n };\n\n const tryFocus = function (node) {\n if (node === doc.activeElement) {\n return;\n }\n if (!node || !node.focus) {\n tryFocus(getInitialFocusNode());\n return;\n }\n\n node.focus({ preventScroll: !!config.preventScroll });\n state.mostRecentlyFocusedNode = node;\n\n if (isSelectableInput(node)) {\n node.select();\n }\n };\n\n const getReturnFocusNode = function (previousActiveElement) {\n const node = getNodeForOption('setReturnFocus');\n\n return node ? node : previousActiveElement;\n };\n\n // This needs to be done on mousedown and touchstart instead of click\n // so that it precedes the focus event.\n const checkPointerDown = function (e) {\n if (containersContain(e.target)) {\n // allow the click since it ocurred inside the trap\n return;\n }\n\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n // immediately deactivate the trap\n trap.deactivate({\n // if, on deactivation, we should return focus to the node originally-focused\n // when the trap was activated (or the configured `setReturnFocus` node),\n // then assume it's also OK to return focus to the outside node that was\n // just clicked, causing deactivation, as long as that node is focusable;\n // if it isn't focusable, then return focus to the original node focused\n // on activation (or the configured `setReturnFocus` node)\n // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,\n // which will result in the outside click setting focus to the node\n // that was clicked, whether it's focusable or not; by setting\n // `returnFocus: true`, we'll attempt to re-focus the node originally-focused\n // on activation (or the configured `setReturnFocus` node)\n returnFocus: config.returnFocusOnDeactivate && !isFocusable(e.target),\n });\n return;\n }\n\n // This is needed for mobile devices.\n // (If we'll only let `click` events through,\n // then on mobile they will be blocked anyways if `touchstart` is blocked.)\n if (valueOrHandler(config.allowOutsideClick, e)) {\n // allow the click outside the trap to take place\n return;\n }\n\n // otherwise, prevent the click\n e.preventDefault();\n };\n\n // In case focus escapes the trap for some strange reason, pull it back in.\n const checkFocusIn = function (e) {\n const targetContained = containersContain(e.target);\n // In Firefox when you Tab out of an iframe the Document is briefly focused.\n if (targetContained || e.target instanceof Document) {\n if (targetContained) {\n state.mostRecentlyFocusedNode = e.target;\n }\n } else {\n // escaped! pull it back in to where it just left\n e.stopImmediatePropagation();\n tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());\n }\n };\n\n // Hijack Tab events on the first and last focusable nodes of the trap,\n // in order to prevent focus from escaping. If it escapes for even a\n // moment it can end up scrolling the page and causing confusion so we\n // kind of need to capture the action at the keydown phase.\n const checkTab = function (e) {\n updateTabbableNodes();\n\n let destinationNode = null;\n\n if (state.tabbableGroups.length > 0) {\n // make sure the target is actually contained in a group\n // NOTE: the target may also be the container itself if it's tabbable\n // with tabIndex='-1' and was given initial focus\n const containerIndex = findIndex(state.tabbableGroups, ({ container }) =>\n container.contains(e.target)\n );\n\n if (containerIndex < 0) {\n // target not found in any group: quite possible focus has escaped the trap,\n // so bring it back in to...\n if (e.shiftKey) {\n // ...the last node in the last group\n destinationNode =\n state.tabbableGroups[state.tabbableGroups.length - 1]\n .lastTabbableNode;\n } else {\n // ...the first node in the first group\n destinationNode = state.tabbableGroups[0].firstTabbableNode;\n }\n } else if (e.shiftKey) {\n // REVERSE\n\n // is the target the first tabbable node in a group?\n let startOfGroupIndex = findIndex(\n state.tabbableGroups,\n ({ firstTabbableNode }) => e.target === firstTabbableNode\n );\n\n if (\n startOfGroupIndex < 0 &&\n state.tabbableGroups[containerIndex].container === e.target\n ) {\n // an exception case where the target is the container itself, in which\n // case, we should handle shift+tab as if focus were on the container's\n // first tabbable node, and go to the last tabbable node of the LAST group\n startOfGroupIndex = containerIndex;\n }\n\n if (startOfGroupIndex >= 0) {\n // YES: then shift+tab should go to the last tabbable node in the\n // previous group (and wrap around to the last tabbable node of\n // the LAST group if it's the first tabbable node of the FIRST group)\n const destinationGroupIndex =\n startOfGroupIndex === 0\n ? state.tabbableGroups.length - 1\n : startOfGroupIndex - 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n destinationNode = destinationGroup.lastTabbableNode;\n }\n } else {\n // FORWARD\n\n // is the target the last tabbable node in a group?\n let lastOfGroupIndex = findIndex(\n state.tabbableGroups,\n ({ lastTabbableNode }) => e.target === lastTabbableNode\n );\n\n if (\n lastOfGroupIndex < 0 &&\n state.tabbableGroups[containerIndex].container === e.target\n ) {\n // an exception case where the target is the container itself, in which\n // case, we should handle tab as if focus were on the container's\n // last tabbable node, and go to the first tabbable node of the FIRST group\n lastOfGroupIndex = containerIndex;\n }\n\n if (lastOfGroupIndex >= 0) {\n // YES: then tab should go to the first tabbable node in the next\n // group (and wrap around to the first tabbable node of the FIRST\n // group if it's the last tabbable node of the LAST group)\n const destinationGroupIndex =\n lastOfGroupIndex === state.tabbableGroups.length - 1\n ? 0\n : lastOfGroupIndex + 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n destinationNode = destinationGroup.firstTabbableNode;\n }\n }\n } else {\n destinationNode = getNodeForOption('fallbackFocus');\n }\n\n if (destinationNode) {\n e.preventDefault();\n tryFocus(destinationNode);\n }\n // else, let the browser take care of [shift+]tab and move the focus\n };\n\n const checkKey = function (e) {\n if (config.escapeDeactivates !== false && isEscapeEvent(e)) {\n e.preventDefault();\n trap.deactivate();\n return;\n }\n\n if (isTabEvent(e)) {\n checkTab(e);\n return;\n }\n };\n\n const checkClick = function (e) {\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n return;\n }\n\n if (containersContain(e.target)) {\n return;\n }\n\n if (valueOrHandler(config.allowOutsideClick, e)) {\n return;\n }\n\n e.preventDefault();\n e.stopImmediatePropagation();\n };\n\n //\n // EVENT LISTENERS\n //\n\n const addListeners = function () {\n if (!state.active) {\n return;\n }\n\n // There can be only one listening focus trap at a time\n activeFocusTraps.activateTrap(trap);\n\n // Delay ensures that the focused element doesn't capture the event\n // that caused the focus trap activation.\n activeFocusDelay = config.delayInitialFocus\n ? delay(function () {\n tryFocus(getInitialFocusNode());\n })\n : tryFocus(getInitialFocusNode());\n\n doc.addEventListener('focusin', checkFocusIn, true);\n doc.addEventListener('mousedown', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('touchstart', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('click', checkClick, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkKey, {\n capture: true,\n passive: false,\n });\n\n return trap;\n };\n\n const removeListeners = function () {\n if (!state.active) {\n return;\n }\n\n doc.removeEventListener('focusin', checkFocusIn, true);\n doc.removeEventListener('mousedown', checkPointerDown, true);\n doc.removeEventListener('touchstart', checkPointerDown, true);\n doc.removeEventListener('click', checkClick, true);\n doc.removeEventListener('keydown', checkKey, true);\n\n return trap;\n };\n\n //\n // TRAP DEFINITION\n //\n\n trap = {\n activate(activateOptions) {\n if (state.active) {\n return this;\n }\n\n updateTabbableNodes();\n\n state.active = true;\n state.paused = false;\n state.nodeFocusedBeforeActivation = doc.activeElement;\n\n const onActivate =\n activateOptions && activateOptions.onActivate\n ? activateOptions.onActivate\n : config.onActivate;\n if (onActivate) {\n onActivate();\n }\n\n addListeners();\n return this;\n },\n\n deactivate(deactivateOptions) {\n if (!state.active) {\n return this;\n }\n\n clearTimeout(activeFocusDelay);\n\n removeListeners();\n state.active = false;\n state.paused = false;\n\n activeFocusTraps.deactivateTrap(trap);\n\n const onDeactivate =\n deactivateOptions && deactivateOptions.onDeactivate !== undefined\n ? deactivateOptions.onDeactivate\n : config.onDeactivate;\n if (onDeactivate) {\n onDeactivate();\n }\n\n const returnFocus =\n deactivateOptions && deactivateOptions.returnFocus !== undefined\n ? deactivateOptions.returnFocus\n : config.returnFocusOnDeactivate;\n\n if (returnFocus) {\n delay(function () {\n tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));\n });\n }\n\n return this;\n },\n\n pause() {\n if (state.paused || !state.active) {\n return this;\n }\n\n state.paused = true;\n removeListeners();\n\n return this;\n },\n\n unpause() {\n if (!state.paused || !state.active) {\n return this;\n }\n\n state.paused = false;\n updateTabbableNodes();\n addListeners();\n\n return this;\n },\n\n updateContainerElements(containerElements) {\n const elementsAsArray = [].concat(containerElements).filter(Boolean);\n\n state.containers = elementsAsArray.map((element) =>\n typeof element === 'string' ? doc.querySelector(element) : element\n );\n\n if (state.active) {\n updateTabbableNodes();\n }\n\n return this;\n },\n };\n\n // initialize container elements\n trap.updateContainerElements(elements);\n\n return trap;\n};\n\nexport { createFocusTrap };\n"],"names":["activeFocusDelay","activeFocusTraps","trapQueue","activateTrap","trap","length","activeTrap","pause","trapIndex","indexOf","push","splice","deactivateTrap","unpause","isSelectableInput","node","tagName","toLowerCase","select","isEscapeEvent","e","key","keyCode","isTabEvent","delay","fn","setTimeout","findIndex","arr","idx","every","value","i","valueOrHandler","params","createFocusTrap","elements","userOptions","doc","document","config","returnFocusOnDeactivate","escapeDeactivates","delayInitialFocus","state","containers","tabbableGroups","nodeFocusedBeforeActivation","mostRecentlyFocusedNode","active","paused","containersContain","element","some","container","contains","getNodeForOption","optionName","optionValue","querySelector","Error","getInitialFocusNode","activeElement","firstTabbableGroup","firstTabbableNode","updateTabbableNodes","map","tabbableNodes","tabbable","lastTabbableNode","undefined","filter","group","tryFocus","focus","preventScroll","getReturnFocusNode","previousActiveElement","checkPointerDown","target","clickOutsideDeactivates","deactivate","returnFocus","isFocusable","allowOutsideClick","preventDefault","checkFocusIn","targetContained","Document","stopImmediatePropagation","checkTab","destinationNode","containerIndex","shiftKey","startOfGroupIndex","destinationGroupIndex","destinationGroup","lastOfGroupIndex","checkKey","checkClick","addListeners","addEventListener","capture","passive","removeListeners","removeEventListener","activate","activateOptions","onActivate","deactivateOptions","clearTimeout","onDeactivate","updateContainerElements","containerElements","elementsAsArray","concat","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAIA,gBAAJ;;AAEA,IAAMC,gBAAgB,GAAI,YAAY;AACpC,MAAMC,SAAS,GAAG,EAAlB;AACA,SAAO;AACLC,IAAAA,YADK,wBACQC,IADR,EACc;AACjB,UAAIF,SAAS,CAACG,MAAV,GAAmB,CAAvB,EAA0B;AACxB,YAAMC,UAAU,GAAGJ,SAAS,CAACA,SAAS,CAACG,MAAV,GAAmB,CAApB,CAA5B;;AACA,YAAIC,UAAU,KAAKF,IAAnB,EAAyB;AACvBE,UAAAA,UAAU,CAACC,KAAX;AACD;AACF;;AAED,UAAMC,SAAS,GAAGN,SAAS,CAACO,OAAV,CAAkBL,IAAlB,CAAlB;;AACA,UAAII,SAAS,KAAK,CAAC,CAAnB,EAAsB;AACpBN,QAAAA,SAAS,CAACQ,IAAV,CAAeN,IAA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