focus-trap 7.5.4 β†’ 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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 7.5.4
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # focus-trap [![CI](https://github.com/focus-trap/focus-trap/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/focus-trap/focus-trap/actions?query=workflow:CI+branch:master) [![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)
2
2
 
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-30-orange.svg?style=flat-square)](#contributors)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-32-orange.svg?style=flat-square)](#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,33 +383,35 @@ 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>
402
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>
403
417
  </tr>
@@ -1,9 +1,17 @@
1
1
  /*!
2
- * focus-trap 7.5.4
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 _defineProperty(obj, key, value) {
29
- key = _toPropertyKey(key);
30
- if (key in obj) {
31
- Object.defineProperty(obj, key, {
32
- value: value,
33
- enumerable: true,
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 (hint === "string" ? String : Number)(input);
44
+ return ("string" === r ? String : Number)(t);
51
45
  }
52
- function _toPropertyKey(arg) {
53
- var key = _toPrimitive(arg, "string");
54
- return typeof key === "symbol" ? key : String(key);
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;
@@ -409,25 +400,25 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
409
400
  *
410
401
  * @returns {HTMLElement} The element that currently has the focus
411
402
  **/
412
- var getActiveElement = function getActiveElement(el) {
403
+ var _getActiveElement = function getActiveElement(el) {
413
404
  var activeElement = el.activeElement;
414
405
  if (!activeElement) {
415
406
  return;
416
407
  }
417
408
  if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
418
- return getActiveElement(activeElement.shadowRoot);
409
+ return _getActiveElement(activeElement.shadowRoot);
419
410
  }
420
411
  return activeElement;
421
412
  };
422
- var tryFocus = function tryFocus(node) {
413
+ var _tryFocus = function tryFocus(node) {
423
414
  if (node === false) {
424
415
  return;
425
416
  }
426
- if (node === getActiveElement(document)) {
417
+ if (node === _getActiveElement(document)) {
427
418
  return;
428
419
  }
429
420
  if (!node || !node.focus) {
430
- tryFocus(getInitialFocusNode());
421
+ _tryFocus(getInitialFocusNode());
431
422
  return;
432
423
  }
433
424
  node.focus({
@@ -671,9 +662,9 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
671
662
  });
672
663
  }
673
664
  if (nextNode) {
674
- tryFocus(nextNode);
665
+ _tryFocus(nextNode);
675
666
  } else {
676
- tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
667
+ _tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
677
668
  }
678
669
  }
679
670
  state.recentNavEvent = undefined; // clear
@@ -698,19 +689,21 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
698
689
  // to where it normally would
699
690
  event.preventDefault();
700
691
  }
701
- tryFocus(destinationNode);
692
+ _tryFocus(destinationNode);
702
693
  }
703
694
  // else, let the browser take care of [shift+]tab and move the focus
704
695
  };
696
+ var checkTabKey = function checkTabKey(event) {
697
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
698
+ checkKeyNav(event, config.isKeyBackward(event));
699
+ }
700
+ };
705
701
 
706
- var checkKey = function checkKey(event) {
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) {
707
704
  if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
708
705
  event.preventDefault();
709
706
  trap.deactivate();
710
- return;
711
- }
712
- if (config.isKeyForward(event) || config.isKeyBackward(event)) {
713
- checkKeyNav(event, config.isKeyBackward(event));
714
707
  }
715
708
  };
716
709
  var checkClick = function checkClick(e) {
@@ -743,8 +736,8 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
743
736
  // Delay ensures that the focused element doesn't capture the event
744
737
  // that caused the focus trap activation.
745
738
  state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
746
- tryFocus(getInitialFocusNode());
747
- }) : tryFocus(getInitialFocusNode());
739
+ _tryFocus(getInitialFocusNode());
740
+ }) : _tryFocus(getInitialFocusNode());
748
741
  doc.addEventListener('focusin', checkFocusIn, true);
749
742
  doc.addEventListener('mousedown', checkPointerDown, {
750
743
  capture: true,
@@ -758,10 +751,11 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
758
751
  capture: true,
759
752
  passive: false
760
753
  });
761
- doc.addEventListener('keydown', checkKey, {
754
+ doc.addEventListener('keydown', checkTabKey, {
762
755
  capture: true,
763
756
  passive: false
764
757
  });
758
+ doc.addEventListener('keydown', checkEscapeKey);
765
759
  return trap;
766
760
  };
767
761
  var removeListeners = function removeListeners() {
@@ -772,7 +766,8 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
772
766
  doc.removeEventListener('mousedown', checkPointerDown, true);
773
767
  doc.removeEventListener('touchstart', checkPointerDown, true);
774
768
  doc.removeEventListener('click', checkClick, true);
775
- doc.removeEventListener('keydown', checkKey, true);
769
+ doc.removeEventListener('keydown', checkTabKey, true);
770
+ doc.removeEventListener('keydown', checkEscapeKey);
776
771
  return trap;
777
772
  };
778
773
 
@@ -791,7 +786,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
791
786
  // If the currently focused is removed then browsers will move focus to the
792
787
  // <body> element. If this happens, try to move focus back into the trap.
793
788
  if (isFocusedNodeRemoved) {
794
- tryFocus(getInitialFocusNode());
789
+ _tryFocus(getInitialFocusNode());
795
790
  }
796
791
  };
797
792
 
@@ -877,7 +872,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
877
872
  var finishDeactivation = function finishDeactivation() {
878
873
  delay(function () {
879
874
  if (returnFocus) {
880
- tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
875
+ _tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
881
876
  }
882
877
  onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
883
878
  });