focus-trap 7.5.3 β 7.6.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 +19 -4
- package/dist/focus-trap.esm.js +59 -45
- 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 +59 -45
- 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 +59 -45
- 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.js +38 -9
- package/package.json +23 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8aeacee: Move `Escape` key handler to target phase to allow more control in `escapeDeactivates` ([#1247](https://github.com/focus-trap/focus-trap/issues/1247))
|
|
8
|
+
|
|
9
|
+
## 7.5.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 680f6e8: Fix issue with not being able to cycle back to the start from the last element if there is a focusable web component inside the focus-trap ((#1068)[https://github.com/focus-trap/focus-trap/issues/1068])
|
|
14
|
+
|
|
3
15
|
## 7.5.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
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.
|
|
@@ -348,6 +348,18 @@ You will hit this error if your trap does not have (or no longer has) any [tabba
|
|
|
348
348
|
|
|
349
349
|
This often happens when traps are related to elements that appear and disappear dynamically. Typically, the error will fire either as the element is being shown (because the trap gets created before the trapped children have been inserted into the DOM), or as it's being hidden (because the trapped children are destroyed before the trap is either destroyed or disabled).
|
|
350
350
|
|
|
351
|
+
### First element in trap is unreachable with the TAB key
|
|
352
|
+
|
|
353
|
+
If you create a trap and try to use the TAB key to set focus to the first element in your trap, the first element seems unreachable because focus keeps skipping over it for some reason.
|
|
354
|
+
|
|
355
|
+
This can happen in projects where the Angular-related [zone.js](https://www.npmjs.com/package/zone.js) module is being used because Zone can interfere with Focus-trap's ability to control where focus goes when it _leaves an edge node_ (that is, a node that is on the edge of a container in which it is trapping focus).
|
|
356
|
+
|
|
357
|
+
What is actually happening is that Focus-trap is correctly wrapping focus around to that first element (or last element, if going in reverse with SHIFT+TAB, and you're seeing that get skipped) and setting focus to it, but because of Zone's interference (in which Focus-trap's call to `preventDefault()` on the focus event triggered by the TAB key press is rendered ineffective), once Focus-trap is done handling the event, the browser hasn't received the signal that its default behavior should be prevented, and so it proceeds to move focus to the _next_ element -- effectively "skipping" over the element to which Focus-trap set focus, making it seem "unreachable".
|
|
358
|
+
|
|
359
|
+
Unfortunately, there's no good workaround to this issue from Focus-trap's perspective. The issue was [reported to Angular](https://github.com/angular/angular/issues/45020) (not by Focus-trap) and [has a PR](https://github.com/angular/angular/pull/49477) (also not by Focus-trap) for a fix.
|
|
360
|
+
|
|
361
|
+
This was originally investigated in [#1165](https://github.com/focus-trap/focus-trap/issues/1165) if you want to go deeper.
|
|
362
|
+
|
|
351
363
|
# Contributing
|
|
352
364
|
|
|
353
365
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
|
@@ -371,34 +383,37 @@ In alphabetical order:
|
|
|
371
383
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/features/security"><img src="https://avatars1.githubusercontent.com/u/27347476?v=4?s=100" width="100px;" alt="Dependabot"/><br /><sub><b>Dependabot</b></sub></a><br /><a href="#maintenance-dependabot" title="Maintenance">π§</a></td>
|
|
372
384
|
</tr>
|
|
373
385
|
<tr>
|
|
386
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jcfranco"><img src="https://avatars.githubusercontent.com/u/197440?v=4?s=100" width="100px;" alt="JC Franco"/><br /><sub><b>JC Franco</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=jcfranco" title="Code">π»</a></td>
|
|
374
387
|
<td align="center" valign="top" width="14.28%"><a href="https://www.schilljs.com/"><img src="https://avatars.githubusercontent.com/u/213943?v=4?s=100" width="100px;" alt="Joas Schilling"/><br /><sub><b>Joas Schilling</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/pulls?q=is%3Apr+reviewed-by%3Anickvergessen" title="Reviewed Pull Requests">π</a></td>
|
|
375
388
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/skjnldsv"><img src="https://avatars.githubusercontent.com/u/14975046?v=4?s=100" width="100px;" alt="John MolakvoΓ¦"/><br /><sub><b>John MolakvoΓ¦</b></sub></a><br /><a href="#ideas-skjnldsv" title="Ideas, Planning, & Feedback">π€</a></td>
|
|
376
389
|
<td align="center" valign="top" width="14.28%"><a href="http://reload.dk"><img src="https://avatars.githubusercontent.com/u/73966?v=4?s=100" width="100px;" alt="Kasper GarnΓ¦s"/><br /><sub><b>Kasper GarnΓ¦s</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=kasperg" title="Documentation">π</a> <a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Akasperg" title="Bug reports">π</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=kasperg" title="Code">π»</a></td>
|
|
377
390
|
<td align="center" valign="top" width="14.28%"><a href="http://blogs.esri.com/esri/arcgis/"><img src="https://avatars.githubusercontent.com/u/1231455?v=4?s=100" width="100px;" alt="Matt Driscoll"/><br /><sub><b>Matt Driscoll</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Adriskull" title="Bug reports">π</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=driskull" title="Code">π»</a> <a href="#tutorial-driskull" title="Tutorials">β
</a></td>
|
|
378
391
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/msev"><img src="https://avatars.githubusercontent.com/u/1529562?v=4?s=100" width="100px;" alt="Maxime"/><br /><sub><b>Maxime</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Amsev" title="Bug reports">π</a></td>
|
|
379
392
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/michael-ar"><img src="https://avatars3.githubusercontent.com/u/18557997?v=4?s=100" width="100px;" alt="Michael Reynolds"/><br /><sub><b>Michael Reynolds</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Amichael-ar" title="Bug reports">π</a></td>
|
|
380
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/liunate"><img src="https://avatars2.githubusercontent.com/u/38996291?v=4?s=100" width="100px;" alt="Nate Liu"/><br /><sub><b>Nate Liu</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=liunate" title="Tests">β οΈ</a></td>
|
|
381
393
|
</tr>
|
|
382
394
|
<tr>
|
|
395
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/liunate"><img src="https://avatars2.githubusercontent.com/u/38996291?v=4?s=100" width="100px;" alt="Nate Liu"/><br /><sub><b>Nate Liu</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=liunate" title="Tests">β οΈ</a></td>
|
|
383
396
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/far-fetched"><img src="https://avatars.githubusercontent.com/u/11621383?v=4?s=100" width="100px;" alt="Piotr Panek"/><br /><sub><b>Piotr Panek</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Afar-fetched" title="Bug reports">π</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=far-fetched" title="Documentation">π</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=far-fetched" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=far-fetched" title="Tests">β οΈ</a></td>
|
|
384
397
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/randypuro"><img src="https://avatars2.githubusercontent.com/u/2579?v=4?s=100" width="100px;" alt="Randy Puro"/><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>
|
|
385
398
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sadick254"><img src="https://avatars2.githubusercontent.com/u/5238135?v=4?s=100" width="100px;" alt="Sadick"/><br /><sub><b>Sadick</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=sadick254" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=sadick254" title="Tests">β οΈ</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=sadick254" title="Documentation">π</a></td>
|
|
386
399
|
<td align="center" valign="top" width="14.28%"><a href="https://scottblinch.me/"><img src="https://avatars2.githubusercontent.com/u/4682114?v=4?s=100" width="100px;" alt="Scott Blinch"/><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>
|
|
387
400
|
<td align="center" valign="top" width="14.28%"><a href="https://seanmcp.com/"><img src="https://avatars1.githubusercontent.com/u/6360367?v=4?s=100" width="100px;" alt="Sean McPherson"/><br /><sub><b>Sean McPherson</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=SeanMcP" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=SeanMcP" title="Documentation">π</a></td>
|
|
388
401
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/skriems"><img src="https://avatars.githubusercontent.com/u/15573317?v=4?s=100" width="100px;" alt="Sebastian Kriems"/><br /><sub><b>Sebastian Kriems</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Askriems" title="Bug reports">π</a></td>
|
|
389
|
-
<td align="center" valign="top" width="14.28%"><a href="https://recollectr.io"><img src="https://avatars2.githubusercontent.com/u/6835891?v=4?s=100" width="100px;" alt="Slapbox"/><br /><sub><b>Slapbox</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3ASlapbox" title="Bug reports">π</a></td>
|
|
390
402
|
</tr>
|
|
391
403
|
<tr>
|
|
404
|
+
<td align="center" valign="top" width="14.28%"><a href="https://recollectr.io"><img src="https://avatars2.githubusercontent.com/u/6835891?v=4?s=100" width="100px;" alt="Slapbox"/><br /><sub><b>Slapbox</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3ASlapbox" title="Bug reports">π</a></td>
|
|
392
405
|
<td align="center" valign="top" width="14.28%"><a href="https://stefancameron.com/"><img src="https://avatars3.githubusercontent.com/u/2855350?v=4?s=100" width="100px;" alt="Stefan Cameron"/><br /><sub><b>Stefan Cameron</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=stefcameron" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/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/commits?author=stefcameron" title="Tests">β οΈ</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=stefcameron" title="Documentation">π</a> <a href="#maintenance-stefcameron" title="Maintenance">π§</a></td>
|
|
393
406
|
<td align="center" valign="top" width="14.28%"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4?s=100" width="100px;" alt="Tyler Hawkins"/><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>
|
|
394
407
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vasiliki-b"><img src="https://avatars.githubusercontent.com/u/98032598?v=4?s=100" width="100px;" alt="Vasiliki Boutas"/><br /><sub><b>Vasiliki Boutas</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Avasiliki-b" title="Bug reports">π</a></td>
|
|
395
408
|
<td align="center" valign="top" width="14.28%"><a href="https://vinicius73.dev/"><img src="https://avatars.githubusercontent.com/u/1561347?v=4?s=100" width="100px;" alt="Vinicius Reis"/><br /><sub><b>Vinicius Reis</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=vinicius73" title="Code">π»</a> <a href="#ideas-vinicius73" title="Ideas, Planning, & Feedback">π€</a></td>
|
|
396
409
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wandroll"><img src="https://avatars.githubusercontent.com/u/4492317?v=4?s=100" width="100px;" alt="Wandrille Verlut"/><br /><sub><b>Wandrille Verlut</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=wandroll" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=wandroll" title="Tests">β οΈ</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=wandroll" title="Documentation">π</a> <a href="#tool-wandroll" title="Tools">π§</a></td>
|
|
397
410
|
<td align="center" valign="top" width="14.28%"><a href="http://willmruzek.com/"><img src="https://avatars.githubusercontent.com/u/108522?v=4?s=100" width="100px;" alt="Will Mruzek"/><br /><sub><b>Will Mruzek</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=mruzekw" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=mruzekw" title="Documentation">π</a> <a href="#example-mruzekw" title="Examples">π‘</a> <a href="https://github.com/focus-trap/focus-trap/commits?author=mruzekw" title="Tests">β οΈ</a> <a href="#question-mruzekw" title="Answering Questions">π¬</a></td>
|
|
398
|
-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4?s=100" width="100px;" alt="Zioth"/><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>
|
|
399
411
|
</tr>
|
|
400
412
|
<tr>
|
|
413
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4?s=100" width="100px;" alt="Zioth"/><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>
|
|
414
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/glushkova91"><img src="https://avatars.githubusercontent.com/u/13402897?v=4?s=100" width="100px;" alt="glushkova91"/><br /><sub><b>glushkova91</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=glushkova91" title="Documentation">π</a></td>
|
|
401
415
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jpveooys"><img src="https://avatars.githubusercontent.com/u/66470099?v=4?s=100" width="100px;" alt="jpveooys"/><br /><sub><b>jpveooys</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Ajpveooys" title="Bug reports">π</a></td>
|
|
416
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/simonxabris"><img src="https://avatars.githubusercontent.com/u/27497229?v=4?s=100" width="100px;" alt="Γbris Simon"/><br /><sub><b>Γbris Simon</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/commits?author=simonxabris" title="Code">π»</a> <a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Asimonxabris" title="Bug reports">π</a></td>
|
|
402
417
|
</tr>
|
|
403
418
|
</tbody>
|
|
404
419
|
</table>
|
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 7.
|
|
2
|
+
* focus-trap 7.6.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';
|
|
6
6
|
|
|
7
|
+
function _defineProperty(e, r, t) {
|
|
8
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
9
|
+
value: t,
|
|
10
|
+
enumerable: !0,
|
|
11
|
+
configurable: !0,
|
|
12
|
+
writable: !0
|
|
13
|
+
}) : e[r] = t, e;
|
|
14
|
+
}
|
|
7
15
|
function ownKeys(e, r) {
|
|
8
16
|
var t = Object.keys(e);
|
|
9
17
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -25,33 +33,19 @@ function _objectSpread2(e) {
|
|
|
25
33
|
}
|
|
26
34
|
return e;
|
|
27
35
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
obj[key] = value;
|
|
39
|
-
}
|
|
40
|
-
return obj;
|
|
41
|
-
}
|
|
42
|
-
function _toPrimitive(input, hint) {
|
|
43
|
-
if (typeof input !== "object" || input === null) return input;
|
|
44
|
-
var prim = input[Symbol.toPrimitive];
|
|
45
|
-
if (prim !== undefined) {
|
|
46
|
-
var res = prim.call(input, hint || "default");
|
|
47
|
-
if (typeof res !== "object") return res;
|
|
36
|
+
function _toPrimitive(t, r) {
|
|
37
|
+
if ("object" != typeof t || !t) return t;
|
|
38
|
+
var e = t[Symbol.toPrimitive];
|
|
39
|
+
if (void 0 !== e) {
|
|
40
|
+
var i = e.call(t, r || "default");
|
|
41
|
+
if ("object" != typeof i) return i;
|
|
48
42
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
49
43
|
}
|
|
50
|
-
return (
|
|
44
|
+
return ("string" === r ? String : Number)(t);
|
|
51
45
|
}
|
|
52
|
-
function _toPropertyKey(
|
|
53
|
-
var
|
|
54
|
-
return
|
|
46
|
+
function _toPropertyKey(t) {
|
|
47
|
+
var i = _toPrimitive(t, "string");
|
|
48
|
+
return "symbol" == typeof i ? i : i + "";
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
var activeFocusTraps = {
|
|
@@ -113,10 +107,8 @@ var findIndex = function findIndex(arr, fn) {
|
|
|
113
107
|
idx = i;
|
|
114
108
|
return false; // break
|
|
115
109
|
}
|
|
116
|
-
|
|
117
110
|
return true; // next
|
|
118
111
|
});
|
|
119
|
-
|
|
120
112
|
return idx;
|
|
121
113
|
};
|
|
122
114
|
|
|
@@ -263,7 +255,6 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
263
255
|
if (optionValue === true) {
|
|
264
256
|
optionValue = undefined; // use default value
|
|
265
257
|
}
|
|
266
|
-
|
|
267
258
|
if (!optionValue) {
|
|
268
259
|
if (optionValue === undefined || optionValue === false) {
|
|
269
260
|
return optionValue;
|
|
@@ -400,15 +391,34 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
400
391
|
throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.");
|
|
401
392
|
}
|
|
402
393
|
};
|
|
403
|
-
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Gets the current activeElement. If it's a web-component and has open shadow-root
|
|
397
|
+
* it will recursively search inside shadow roots for the "true" activeElement.
|
|
398
|
+
*
|
|
399
|
+
* @param {Document | ShadowRoot} el
|
|
400
|
+
*
|
|
401
|
+
* @returns {HTMLElement} The element that currently has the focus
|
|
402
|
+
**/
|
|
403
|
+
var _getActiveElement = function getActiveElement(el) {
|
|
404
|
+
var activeElement = el.activeElement;
|
|
405
|
+
if (!activeElement) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
|
|
409
|
+
return _getActiveElement(activeElement.shadowRoot);
|
|
410
|
+
}
|
|
411
|
+
return activeElement;
|
|
412
|
+
};
|
|
413
|
+
var _tryFocus = function tryFocus(node) {
|
|
404
414
|
if (node === false) {
|
|
405
415
|
return;
|
|
406
416
|
}
|
|
407
|
-
if (node ===
|
|
417
|
+
if (node === _getActiveElement(document)) {
|
|
408
418
|
return;
|
|
409
419
|
}
|
|
410
420
|
if (!node || !node.focus) {
|
|
411
|
-
|
|
421
|
+
_tryFocus(getInitialFocusNode());
|
|
412
422
|
return;
|
|
413
423
|
}
|
|
414
424
|
node.focus({
|
|
@@ -652,9 +662,9 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
652
662
|
});
|
|
653
663
|
}
|
|
654
664
|
if (nextNode) {
|
|
655
|
-
|
|
665
|
+
_tryFocus(nextNode);
|
|
656
666
|
} else {
|
|
657
|
-
|
|
667
|
+
_tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
|
|
658
668
|
}
|
|
659
669
|
}
|
|
660
670
|
state.recentNavEvent = undefined; // clear
|
|
@@ -679,19 +689,21 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
679
689
|
// to where it normally would
|
|
680
690
|
event.preventDefault();
|
|
681
691
|
}
|
|
682
|
-
|
|
692
|
+
_tryFocus(destinationNode);
|
|
683
693
|
}
|
|
684
694
|
// else, let the browser take care of [shift+]tab and move the focus
|
|
685
695
|
};
|
|
696
|
+
var checkTabKey = function checkTabKey(event) {
|
|
697
|
+
if (config.isKeyForward(event) || config.isKeyBackward(event)) {
|
|
698
|
+
checkKeyNav(event, config.isKeyBackward(event));
|
|
699
|
+
}
|
|
700
|
+
};
|
|
686
701
|
|
|
687
|
-
|
|
702
|
+
// we use a different event phase for the Escape key to allow canceling the event and checking for this in escapeDeactivates
|
|
703
|
+
var checkEscapeKey = function checkEscapeKey(event) {
|
|
688
704
|
if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
|
|
689
705
|
event.preventDefault();
|
|
690
706
|
trap.deactivate();
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
if (config.isKeyForward(event) || config.isKeyBackward(event)) {
|
|
694
|
-
checkKeyNav(event, config.isKeyBackward(event));
|
|
695
707
|
}
|
|
696
708
|
};
|
|
697
709
|
var checkClick = function checkClick(e) {
|
|
@@ -724,8 +736,8 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
724
736
|
// Delay ensures that the focused element doesn't capture the event
|
|
725
737
|
// that caused the focus trap activation.
|
|
726
738
|
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
|
|
727
|
-
|
|
728
|
-
}) :
|
|
739
|
+
_tryFocus(getInitialFocusNode());
|
|
740
|
+
}) : _tryFocus(getInitialFocusNode());
|
|
729
741
|
doc.addEventListener('focusin', checkFocusIn, true);
|
|
730
742
|
doc.addEventListener('mousedown', checkPointerDown, {
|
|
731
743
|
capture: true,
|
|
@@ -739,10 +751,11 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
739
751
|
capture: true,
|
|
740
752
|
passive: false
|
|
741
753
|
});
|
|
742
|
-
doc.addEventListener('keydown',
|
|
754
|
+
doc.addEventListener('keydown', checkTabKey, {
|
|
743
755
|
capture: true,
|
|
744
756
|
passive: false
|
|
745
757
|
});
|
|
758
|
+
doc.addEventListener('keydown', checkEscapeKey);
|
|
746
759
|
return trap;
|
|
747
760
|
};
|
|
748
761
|
var removeListeners = function removeListeners() {
|
|
@@ -753,7 +766,8 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
753
766
|
doc.removeEventListener('mousedown', checkPointerDown, true);
|
|
754
767
|
doc.removeEventListener('touchstart', checkPointerDown, true);
|
|
755
768
|
doc.removeEventListener('click', checkClick, true);
|
|
756
|
-
doc.removeEventListener('keydown',
|
|
769
|
+
doc.removeEventListener('keydown', checkTabKey, true);
|
|
770
|
+
doc.removeEventListener('keydown', checkEscapeKey);
|
|
757
771
|
return trap;
|
|
758
772
|
};
|
|
759
773
|
|
|
@@ -772,7 +786,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
772
786
|
// If the currently focused is removed then browsers will move focus to the
|
|
773
787
|
// <body> element. If this happens, try to move focus back into the trap.
|
|
774
788
|
if (isFocusedNodeRemoved) {
|
|
775
|
-
|
|
789
|
+
_tryFocus(getInitialFocusNode());
|
|
776
790
|
}
|
|
777
791
|
};
|
|
778
792
|
|
|
@@ -858,7 +872,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
|
858
872
|
var finishDeactivation = function finishDeactivation() {
|
|
859
873
|
delay(function () {
|
|
860
874
|
if (returnFocus) {
|
|
861
|
-
|
|
875
|
+
_tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
|
|
862
876
|
}
|
|
863
877
|
onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
|
|
864
878
|
});
|