Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

focus-trap

Package Overview
Dependencies
Maintainers
3
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

focus-trap - npm Package Compare versions

Comparing version 6.5.1 to 6.6.0

31

CHANGELOG.md
# Changelog
## 6.6.0
### Minor Changes
- 281e66c: Add option to allow no initial focus when trap activates via `initialFocus: false`
There may be cases where we don't want to focus the first tabbable element when a focus trap activates.
Examples use-cases:
- Modals/dialogs
- On mobile devices where "tabbing" doesn't make sense without a connected Bluetooth keyboard
In addition, this change ensures that any element inside the trap manually focused outside of `focus-trap` code will be brought back in focus if focus is somehow found outside of the trap.
Example usage:
When the trap activates, there will be no initially focused element inside the new trap.
```js
const focusTrap = createFocusTrap('#some-container', {
initialFocus: false,
});
```
- 75be463: `escapeDeactivates` can now be either a boolean (as before) or a function that takes an event and returns a boolean.
### Patch Changes
- e2294f0: Fix race condition when activating a second trap where initial focus in the second trap may be thwarted because pausing of first trap clears the `delayInitialFocus` timer created for the second trap before during its activation sequence.
## 6.5.1

@@ -4,0 +35,0 @@

27

dist/focus-trap.esm.js
/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE

@@ -60,4 +60,2 @@ */

var activeFocusDelay;
var activeFocusTraps = function () {

@@ -169,3 +167,6 @@ var trapQueue = [];

active: false,
paused: false
paused: false,
// timer ID for when delayInitialFocus is true and initial focus in this trap
// has been delayed during activation
delayInitialFocusTimer: undefined
};

@@ -213,4 +214,8 @@ var 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

var getInitialFocusNode = function getInitialFocusNode() {
var node;
var node; // false indicates we want no initialFocus at all
if (getOption({}, 'initialFocus') === false) {
return false;
}
if (getNodeForOption('initialFocus') !== null) {

@@ -257,2 +262,6 @@ node = getNodeForOption('initialFocus');

var tryFocus = function tryFocus(node) {
if (node === false) {
return;
}
if (node === doc.activeElement) {

@@ -423,3 +432,3 @@ return;

var checkKey = function checkKey(e) {
if (config.escapeDeactivates !== false && isEscapeEvent(e)) {
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) {
e.preventDefault();

@@ -465,3 +474,3 @@ trap.deactivate();

activeFocusDelay = config.delayInitialFocus ? delay(function () {
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
tryFocus(getInitialFocusNode());

@@ -552,3 +561,5 @@ }) : tryFocus(getInitialFocusNode());

clearTimeout(activeFocusDelay);
clearTimeout(state.delayInitialFocusTimer); // noop if undefined
state.delayInitialFocusTimer = undefined;
removeListeners();

@@ -555,0 +566,0 @@ state.active = false;

/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/
import{tabbable as e,isFocusable as t}from"tabbable";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a,o,i=(o=[],{activateTrap:function(e){if(o.length>0){var t=o[o.length-1];t!==e&&t.pause()}var n=o.indexOf(e);-1===n||o.splice(n,1),o.push(e)},deactivateTrap:function(e){var t=o.indexOf(e);-1!==t&&o.splice(t,1),o.length>0&&o[o.length-1].unpause()}}),c=function(e){return setTimeout(e,0)},u=function(e,t){var n=-1;return e.every((function(e,r){return!t(e)||(n=r,!1)})),n},s=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,n):e},l=function(o,l){var f,b=document,v=function(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},l),p={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},d=function(e,t,n){return e&&void 0!==e[t]?e[t]:v[n||t]},h=function(e){return p.containers.some((function(t){return t.contains(e)}))},m=function(e){var t=v[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=b.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},g=function(){var e;if(null!==m("initialFocus"))e=m("initialFocus");else if(h(b.activeElement))e=b.activeElement;else{var t=p.tabbableGroups[0];e=t&&t.firstTabbableNode||m("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},y=function(){if(p.tabbableGroups=p.containers.map((function(t){var n=e(t);if(n.length>0)return{container:t,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),p.tabbableGroups.length<=0&&!m("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},O=function e(t){t!==b.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!v.preventScroll}),p.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(g()))},w=function(e){var t=m("setReturnFocus");return t||e},E=function(e){h(e.target)||(s(v.clickOutsideDeactivates,e)?f.deactivate({returnFocus:v.returnFocusOnDeactivate&&!t(e.target)}):s(v.allowOutsideClick,e)||e.preventDefault())},F=function(e){var t=h(e.target);t||e.target instanceof Document?t&&(p.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),O(p.mostRecentlyFocusedNode||g()))},k=function(e){if(!1!==v.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))return e.preventDefault(),void f.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){y();var t=null;if(p.tabbableGroups.length>0){var n=u(p.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?p.tabbableGroups[p.tabbableGroups.length-1].lastTabbableNode:p.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var r=u(p.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(r<0&&p.tabbableGroups[n].container===e.target&&(r=n),r>=0){var a=0===r?p.tabbableGroups.length-1:r-1;t=p.tabbableGroups[a].lastTabbableNode}}else{var o=u(p.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&p.tabbableGroups[n].container===e.target&&(o=n),o>=0){var i=o===p.tabbableGroups.length-1?0:o+1;t=p.tabbableGroups[i].firstTabbableNode}}}else t=m("fallbackFocus");t&&(e.preventDefault(),O(t))}(e)},D=function(e){s(v.clickOutsideDeactivates,e)||h(e.target)||s(v.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},G=function(){if(p.active)return i.activateTrap(f),a=v.delayInitialFocus?c((function(){O(g())})):O(g()),b.addEventListener("focusin",F,!0),b.addEventListener("mousedown",E,{capture:!0,passive:!1}),b.addEventListener("touchstart",E,{capture:!0,passive:!1}),b.addEventListener("click",D,{capture:!0,passive:!1}),b.addEventListener("keydown",k,{capture:!0,passive:!1}),f},T=function(){if(p.active)return b.removeEventListener("focusin",F,!0),b.removeEventListener("mousedown",E,!0),b.removeEventListener("touchstart",E,!0),b.removeEventListener("click",D,!0),b.removeEventListener("keydown",k,!0),f};return(f={activate:function(e){if(p.active)return this;var t=d(e,"onActivate"),n=d(e,"onPostActivate"),r=d(e,"checkCanFocusTrap");r||y(),p.active=!0,p.paused=!1,p.nodeFocusedBeforeActivation=b.activeElement,t&&t();var a=function(){r&&y(),G(),n&&n()};return r?(r(p.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(e){if(!p.active)return this;clearTimeout(a),T(),p.active=!1,p.paused=!1,i.deactivateTrap(f);var t=d(e,"onDeactivate"),n=d(e,"onPostDeactivate"),r=d(e,"checkCanReturnFocus");t&&t();var o=d(e,"returnFocus","returnFocusOnDeactivate"),u=function(){c((function(){o&&O(w(p.nodeFocusedBeforeActivation)),n&&n()}))};return o&&r?(r(w(p.nodeFocusedBeforeActivation)).then(u,u),this):(u(),this)},pause:function(){return p.paused||!p.active||(p.paused=!0,T()),this},unpause:function(){return p.paused&&p.active?(p.paused=!1,y(),G(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return p.containers=t.map((function(e){return"string"==typeof e?b.querySelector(e):e})),p.active&&y(),this}}).updateContainerElements(o),f};export{l as createFocusTrap};
import{tabbable as e,isFocusable as t}from"tabbable";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r,o=(r=[],{activateTrap:function(e){if(r.length>0){var t=r[r.length-1];t!==e&&t.pause()}var n=r.indexOf(e);-1===n||r.splice(n,1),r.push(e)},deactivateTrap:function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1),r.length>0&&r[r.length-1].unpause()}}),i=function(e){return setTimeout(e,0)},c=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},u=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},s=function(r,s){var l,f=document,b=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},s),v={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},p=function(e,t,n){return e&&void 0!==e[t]?e[t]:b[n||t]},d=function(e){return v.containers.some((function(t){return t.contains(e)}))},m=function(e){var t=b[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=f.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},h=function(){var e;if(!1===p({},"initialFocus"))return!1;if(null!==m("initialFocus"))e=m("initialFocus");else if(d(f.activeElement))e=f.activeElement;else{var t=v.tabbableGroups[0];e=t&&t.firstTabbableNode||m("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},y=function(){if(v.tabbableGroups=v.containers.map((function(t){var n=e(t);if(n.length>0)return{container:t,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),v.tabbableGroups.length<=0&&!m("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},g=function e(t){!1!==t&&t!==f.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!b.preventScroll}),v.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(h()))},F=function(e){var t=m("setReturnFocus");return t||e},O=function(e){d(e.target)||(u(b.clickOutsideDeactivates,e)?l.deactivate({returnFocus:b.returnFocusOnDeactivate&&!t(e.target)}):u(b.allowOutsideClick,e)||e.preventDefault())},w=function(e){var t=d(e.target);t||e.target instanceof Document?t&&(v.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),g(v.mostRecentlyFocusedNode||h()))},E=function(e){if(function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e)&&!1!==u(b.escapeDeactivates))return e.preventDefault(),void l.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){y();var t=null;if(v.tabbableGroups.length>0){var n=c(v.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?v.tabbableGroups[v.tabbableGroups.length-1].lastTabbableNode:v.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var a=c(v.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(a<0&&v.tabbableGroups[n].container===e.target&&(a=n),a>=0){var r=0===a?v.tabbableGroups.length-1:a-1;t=v.tabbableGroups[r].lastTabbableNode}}else{var o=c(v.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&v.tabbableGroups[n].container===e.target&&(o=n),o>=0){var i=o===v.tabbableGroups.length-1?0:o+1;t=v.tabbableGroups[i].firstTabbableNode}}}else t=m("fallbackFocus");t&&(e.preventDefault(),g(t))}(e)},T=function(e){u(b.clickOutsideDeactivates,e)||d(e.target)||u(b.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},k=function(){if(v.active)return o.activateTrap(l),v.delayInitialFocusTimer=b.delayInitialFocus?i((function(){g(h())})):g(h()),f.addEventListener("focusin",w,!0),f.addEventListener("mousedown",O,{capture:!0,passive:!1}),f.addEventListener("touchstart",O,{capture:!0,passive:!1}),f.addEventListener("click",T,{capture:!0,passive:!1}),f.addEventListener("keydown",E,{capture:!0,passive:!1}),l},D=function(){if(v.active)return f.removeEventListener("focusin",w,!0),f.removeEventListener("mousedown",O,!0),f.removeEventListener("touchstart",O,!0),f.removeEventListener("click",T,!0),f.removeEventListener("keydown",E,!0),l};return(l={activate:function(e){if(v.active)return this;var t=p(e,"onActivate"),n=p(e,"onPostActivate"),a=p(e,"checkCanFocusTrap");a||y(),v.active=!0,v.paused=!1,v.nodeFocusedBeforeActivation=f.activeElement,t&&t();var r=function(){a&&y(),k(),n&&n()};return a?(a(v.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!v.active)return this;clearTimeout(v.delayInitialFocusTimer),v.delayInitialFocusTimer=void 0,D(),v.active=!1,v.paused=!1,o.deactivateTrap(l);var t=p(e,"onDeactivate"),n=p(e,"onPostDeactivate"),a=p(e,"checkCanReturnFocus");t&&t();var r=p(e,"returnFocus","returnFocusOnDeactivate"),c=function(){i((function(){r&&g(F(v.nodeFocusedBeforeActivation)),n&&n()}))};return r&&a?(a(F(v.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return v.paused||!v.active||(v.paused=!0,D()),this},unpause:function(){return v.paused&&v.active?(v.paused=!1,y(),k(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return v.containers=t.map((function(e){return"string"==typeof e?f.querySelector(e):e})),v.active&&y(),this}}).updateContainerElements(r),l};export{s as createFocusTrap};
//# sourceMappingURL=focus-trap.esm.min.js.map
/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE

@@ -64,4 +64,2 @@ */

var activeFocusDelay;
var activeFocusTraps = function () {

@@ -173,3 +171,6 @@ var trapQueue = [];

active: false,
paused: false
paused: false,
// timer ID for when delayInitialFocus is true and initial focus in this trap
// has been delayed during activation
delayInitialFocusTimer: undefined
};

@@ -217,4 +218,8 @@ var 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

var getInitialFocusNode = function getInitialFocusNode() {
var node;
var node; // false indicates we want no initialFocus at all
if (getOption({}, 'initialFocus') === false) {
return false;
}
if (getNodeForOption('initialFocus') !== null) {

@@ -261,2 +266,6 @@ node = getNodeForOption('initialFocus');

var tryFocus = function tryFocus(node) {
if (node === false) {
return;
}
if (node === doc.activeElement) {

@@ -427,3 +436,3 @@ return;

var checkKey = function checkKey(e) {
if (config.escapeDeactivates !== false && isEscapeEvent(e)) {
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) {
e.preventDefault();

@@ -469,3 +478,3 @@ trap.deactivate();

activeFocusDelay = config.delayInitialFocus ? delay(function () {
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
tryFocus(getInitialFocusNode());

@@ -556,3 +565,5 @@ }) : tryFocus(getInitialFocusNode());

clearTimeout(activeFocusDelay);
clearTimeout(state.delayInitialFocusTimer); // noop if undefined
state.delayInitialFocusTimer = undefined;
removeListeners();

@@ -559,0 +570,0 @@ state.active = false;

/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("tabbable");function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a,o=(a=[],{activateTrap:function(e){if(a.length>0){var t=a[a.length-1];t!==e&&t.pause()}var n=a.indexOf(e);-1===n||a.splice(n,1),a.push(e)},deactivateTrap:function(e){var t=a.indexOf(e);-1!==t&&a.splice(t,1),a.length>0&&a[a.length-1].unpause()}}),i=function(e){return setTimeout(e,0)},c=function(e,t){var n=-1;return e.every((function(e,r){return!t(e)||(n=r,!1)})),n},u=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,n):e};exports.createFocusTrap=function(a,s){var l,f=document,b=function(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},s),v={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},p=function(e,t,n){return e&&void 0!==e[t]?e[t]:b[n||t]},d=function(e){return v.containers.some((function(t){return t.contains(e)}))},h=function(e){var t=b[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=f.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},y=function(){var e;if(null!==h("initialFocus"))e=h("initialFocus");else if(d(f.activeElement))e=f.activeElement;else{var t=v.tabbableGroups[0];e=t&&t.firstTabbableNode||h("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},g=function(){if(v.tabbableGroups=v.containers.map((function(e){var n=t.tabbable(e);if(n.length>0)return{container:e,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),v.tabbableGroups.length<=0&&!h("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},m=function e(t){t!==f.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!b.preventScroll}),v.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(y()))},O=function(e){var t=h("setReturnFocus");return t||e},w=function(e){d(e.target)||(u(b.clickOutsideDeactivates,e)?l.deactivate({returnFocus:b.returnFocusOnDeactivate&&!t.isFocusable(e.target)}):u(b.allowOutsideClick,e)||e.preventDefault())},F=function(e){var t=d(e.target);t||e.target instanceof Document?t&&(v.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(v.mostRecentlyFocusedNode||y()))},E=function(e){if(!1!==b.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))return e.preventDefault(),void l.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){g();var t=null;if(v.tabbableGroups.length>0){var n=c(v.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?v.tabbableGroups[v.tabbableGroups.length-1].lastTabbableNode:v.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var r=c(v.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(r<0&&v.tabbableGroups[n].container===e.target&&(r=n),r>=0){var a=0===r?v.tabbableGroups.length-1:r-1;t=v.tabbableGroups[a].lastTabbableNode}}else{var o=c(v.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&v.tabbableGroups[n].container===e.target&&(o=n),o>=0){var i=o===v.tabbableGroups.length-1?0:o+1;t=v.tabbableGroups[i].firstTabbableNode}}}else t=h("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},k=function(e){u(b.clickOutsideDeactivates,e)||d(e.target)||u(b.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},D=function(){if(v.active)return o.activateTrap(l),e=b.delayInitialFocus?i((function(){m(y())})):m(y()),f.addEventListener("focusin",F,!0),f.addEventListener("mousedown",w,{capture:!0,passive:!1}),f.addEventListener("touchstart",w,{capture:!0,passive:!1}),f.addEventListener("click",k,{capture:!0,passive:!1}),f.addEventListener("keydown",E,{capture:!0,passive:!1}),l},T=function(){if(v.active)return f.removeEventListener("focusin",F,!0),f.removeEventListener("mousedown",w,!0),f.removeEventListener("touchstart",w,!0),f.removeEventListener("click",k,!0),f.removeEventListener("keydown",E,!0),l};return(l={activate:function(e){if(v.active)return this;var t=p(e,"onActivate"),n=p(e,"onPostActivate"),r=p(e,"checkCanFocusTrap");r||g(),v.active=!0,v.paused=!1,v.nodeFocusedBeforeActivation=f.activeElement,t&&t();var a=function(){r&&g(),D(),n&&n()};return r?(r(v.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(t){if(!v.active)return this;clearTimeout(e),T(),v.active=!1,v.paused=!1,o.deactivateTrap(l);var n=p(t,"onDeactivate"),r=p(t,"onPostDeactivate"),a=p(t,"checkCanReturnFocus");n&&n();var c=p(t,"returnFocus","returnFocusOnDeactivate"),u=function(){i((function(){c&&m(O(v.nodeFocusedBeforeActivation)),r&&r()}))};return c&&a?(a(O(v.nodeFocusedBeforeActivation)).then(u,u),this):(u(),this)},pause:function(){return v.paused||!v.active||(v.paused=!0,T()),this},unpause:function(){return v.paused&&v.active?(v.paused=!1,g(),D(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return v.containers=t.map((function(e){return"string"==typeof e?f.querySelector(e):e})),v.active&&g(),this}}).updateContainerElements(a),l};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tabbable");function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a,r=(a=[],{activateTrap:function(e){if(a.length>0){var t=a[a.length-1];t!==e&&t.pause()}var n=a.indexOf(e);-1===n||a.splice(n,1),a.push(e)},deactivateTrap:function(e){var t=a.indexOf(e);-1!==t&&a.splice(t,1),a.length>0&&a[a.length-1].unpause()}}),o=function(e){return setTimeout(e,0)},i=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},c=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e};exports.createFocusTrap=function(a,u){var s,l=document,f=function(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?t(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},u),b={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},v=function(e,t,n){return e&&void 0!==e[t]?e[t]:f[n||t]},p=function(e){return b.containers.some((function(t){return t.contains(e)}))},d=function(e){var t=f[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=l.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},h=function(){var e;if(!1===v({},"initialFocus"))return!1;if(null!==d("initialFocus"))e=d("initialFocus");else if(p(l.activeElement))e=l.activeElement;else{var t=b.tabbableGroups[0];e=t&&t.firstTabbableNode||d("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},y=function(){if(b.tabbableGroups=b.containers.map((function(t){var n=e.tabbable(t);if(n.length>0)return{container:t,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),b.tabbableGroups.length<=0&&!d("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},m=function e(t){!1!==t&&t!==l.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!f.preventScroll}),b.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(h()))},g=function(e){var t=d("setReturnFocus");return t||e},F=function(t){p(t.target)||(c(f.clickOutsideDeactivates,t)?s.deactivate({returnFocus:f.returnFocusOnDeactivate&&!e.isFocusable(t.target)}):c(f.allowOutsideClick,t)||t.preventDefault())},O=function(e){var t=p(e.target);t||e.target instanceof Document?t&&(b.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(b.mostRecentlyFocusedNode||h()))},w=function(e){if(function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e)&&!1!==c(f.escapeDeactivates))return e.preventDefault(),void s.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){y();var t=null;if(b.tabbableGroups.length>0){var n=i(b.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?b.tabbableGroups[b.tabbableGroups.length-1].lastTabbableNode:b.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var a=i(b.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(a<0&&b.tabbableGroups[n].container===e.target&&(a=n),a>=0){var r=0===a?b.tabbableGroups.length-1:a-1;t=b.tabbableGroups[r].lastTabbableNode}}else{var o=i(b.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&b.tabbableGroups[n].container===e.target&&(o=n),o>=0){var c=o===b.tabbableGroups.length-1?0:o+1;t=b.tabbableGroups[c].firstTabbableNode}}}else t=d("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},E=function(e){c(f.clickOutsideDeactivates,e)||p(e.target)||c(f.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},T=function(){if(b.active)return r.activateTrap(s),b.delayInitialFocusTimer=f.delayInitialFocus?o((function(){m(h())})):m(h()),l.addEventListener("focusin",O,!0),l.addEventListener("mousedown",F,{capture:!0,passive:!1}),l.addEventListener("touchstart",F,{capture:!0,passive:!1}),l.addEventListener("click",E,{capture:!0,passive:!1}),l.addEventListener("keydown",w,{capture:!0,passive:!1}),s},k=function(){if(b.active)return l.removeEventListener("focusin",O,!0),l.removeEventListener("mousedown",F,!0),l.removeEventListener("touchstart",F,!0),l.removeEventListener("click",E,!0),l.removeEventListener("keydown",w,!0),s};return(s={activate:function(e){if(b.active)return this;var t=v(e,"onActivate"),n=v(e,"onPostActivate"),a=v(e,"checkCanFocusTrap");a||y(),b.active=!0,b.paused=!1,b.nodeFocusedBeforeActivation=l.activeElement,t&&t();var r=function(){a&&y(),T(),n&&n()};return a?(a(b.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!b.active)return this;clearTimeout(b.delayInitialFocusTimer),b.delayInitialFocusTimer=void 0,k(),b.active=!1,b.paused=!1,r.deactivateTrap(s);var t=v(e,"onDeactivate"),n=v(e,"onPostDeactivate"),a=v(e,"checkCanReturnFocus");t&&t();var i=v(e,"returnFocus","returnFocusOnDeactivate"),c=function(){o((function(){i&&m(g(b.nodeFocusedBeforeActivation)),n&&n()}))};return i&&a?(a(g(b.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return b.paused||!b.active||(b.paused=!0,k()),this},unpause:function(){return b.paused&&b.active?(b.paused=!1,y(),T(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return b.containers=t.map((function(e){return"string"==typeof e?l.querySelector(e):e})),b.active&&y(),this}}).updateContainerElements(a),s};
//# sourceMappingURL=focus-trap.min.js.map
/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE

@@ -69,4 +69,2 @@ */

var activeFocusDelay;
var activeFocusTraps = function () {

@@ -178,3 +176,6 @@ var trapQueue = [];

active: false,
paused: false
paused: false,
// timer ID for when delayInitialFocus is true and initial focus in this trap
// has been delayed during activation
delayInitialFocusTimer: undefined
};

@@ -222,4 +223,8 @@ var 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

var getInitialFocusNode = function getInitialFocusNode() {
var node;
var node; // false indicates we want no initialFocus at all
if (getOption({}, 'initialFocus') === false) {
return false;
}
if (getNodeForOption('initialFocus') !== null) {

@@ -266,2 +271,6 @@ node = getNodeForOption('initialFocus');

var tryFocus = function tryFocus(node) {
if (node === false) {
return;
}
if (node === doc.activeElement) {

@@ -432,3 +441,3 @@ return;

var checkKey = function checkKey(e) {
if (config.escapeDeactivates !== false && isEscapeEvent(e)) {
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) {
e.preventDefault();

@@ -474,3 +483,3 @@ trap.deactivate();

activeFocusDelay = config.delayInitialFocus ? delay(function () {
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
tryFocus(getInitialFocusNode());

@@ -561,3 +570,5 @@ }) : tryFocus(getInitialFocusNode());

clearTimeout(activeFocusDelay);
clearTimeout(state.delayInitialFocusTimer); // noop if undefined
state.delayInitialFocusTimer = undefined;
removeListeners();

@@ -564,0 +575,0 @@ state.active = false;

/*!
* focus-trap 6.5.1
* focus-trap 6.6.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tabbable")):"function"==typeof define&&define.amd?define(["exports","tabbable"],t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.focusTrap,a=e.focusTrap={};t(a,e.tabbable),a.noConflict=function(){return e.focusTrap=n,a}}())}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r,o,i=(o=[],{activateTrap:function(e){if(o.length>0){var t=o[o.length-1];t!==e&&t.pause()}var n=o.indexOf(e);-1===n||o.splice(n,1),o.push(e)},deactivateTrap:function(e){var t=o.indexOf(e);-1!==t&&o.splice(t,1),o.length>0&&o[o.length-1].unpause()}}),c=function(e){return setTimeout(e,0)},u=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},s=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e};e.createFocusTrap=function(e,o){var l,f=document,b=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},o),v={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},p=function(e,t,n){return e&&void 0!==e[t]?e[t]:b[n||t]},d=function(e){return v.containers.some((function(t){return t.contains(e)}))},h=function(e){var t=b[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=f.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},y=function(){var e;if(null!==h("initialFocus"))e=h("initialFocus");else if(d(f.activeElement))e=f.activeElement;else{var t=v.tabbableGroups[0];e=t&&t.firstTabbableNode||h("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},g=function(){if(v.tabbableGroups=v.containers.map((function(e){var n=t.tabbable(e);if(n.length>0)return{container:e,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),v.tabbableGroups.length<=0&&!h("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},m=function e(t){t!==f.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!b.preventScroll}),v.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(y()))},O=function(e){var t=h("setReturnFocus");return t||e},w=function(e){d(e.target)||(s(b.clickOutsideDeactivates,e)?l.deactivate({returnFocus:b.returnFocusOnDeactivate&&!t.isFocusable(e.target)}):s(b.allowOutsideClick,e)||e.preventDefault())},F=function(e){var t=d(e.target);t||e.target instanceof Document?t&&(v.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(v.mostRecentlyFocusedNode||y()))},E=function(e){if(!1!==b.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))return e.preventDefault(),void l.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){g();var t=null;if(v.tabbableGroups.length>0){var n=u(v.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?v.tabbableGroups[v.tabbableGroups.length-1].lastTabbableNode:v.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var a=u(v.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(a<0&&v.tabbableGroups[n].container===e.target&&(a=n),a>=0){var r=0===a?v.tabbableGroups.length-1:a-1;t=v.tabbableGroups[r].lastTabbableNode}}else{var o=u(v.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&v.tabbableGroups[n].container===e.target&&(o=n),o>=0){var i=o===v.tabbableGroups.length-1?0:o+1;t=v.tabbableGroups[i].firstTabbableNode}}}else t=h("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},T=function(e){s(b.clickOutsideDeactivates,e)||d(e.target)||s(b.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},k=function(){if(v.active)return i.activateTrap(l),r=b.delayInitialFocus?c((function(){m(y())})):m(y()),f.addEventListener("focusin",F,!0),f.addEventListener("mousedown",w,{capture:!0,passive:!1}),f.addEventListener("touchstart",w,{capture:!0,passive:!1}),f.addEventListener("click",T,{capture:!0,passive:!1}),f.addEventListener("keydown",E,{capture:!0,passive:!1}),l},D=function(){if(v.active)return f.removeEventListener("focusin",F,!0),f.removeEventListener("mousedown",w,!0),f.removeEventListener("touchstart",w,!0),f.removeEventListener("click",T,!0),f.removeEventListener("keydown",E,!0),l};return(l={activate:function(e){if(v.active)return this;var t=p(e,"onActivate"),n=p(e,"onPostActivate"),a=p(e,"checkCanFocusTrap");a||g(),v.active=!0,v.paused=!1,v.nodeFocusedBeforeActivation=f.activeElement,t&&t();var r=function(){a&&g(),k(),n&&n()};return a?(a(v.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!v.active)return this;clearTimeout(r),D(),v.active=!1,v.paused=!1,i.deactivateTrap(l);var t=p(e,"onDeactivate"),n=p(e,"onPostDeactivate"),a=p(e,"checkCanReturnFocus");t&&t();var o=p(e,"returnFocus","returnFocusOnDeactivate"),u=function(){c((function(){o&&m(O(v.nodeFocusedBeforeActivation)),n&&n()}))};return o&&a?(a(O(v.nodeFocusedBeforeActivation)).then(u,u),this):(u(),this)},pause:function(){return v.paused||!v.active||(v.paused=!0,D()),this},unpause:function(){return v.paused&&v.active?(v.paused=!1,g(),k(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return v.containers=t.map((function(e){return"string"==typeof e?f.querySelector(e):e})),v.active&&g(),this}}).updateContainerElements(e),l},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tabbable")):"function"==typeof define&&define.amd?define(["exports","tabbable"],t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.focusTrap,a=e.focusTrap={};t(a,e.tabbable),a.noConflict=function(){return e.focusTrap=n,a}}())}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r,o=(r=[],{activateTrap:function(e){if(r.length>0){var t=r[r.length-1];t!==e&&t.pause()}var n=r.indexOf(e);-1===n||r.splice(n,1),r.push(e)},deactivateTrap:function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1),r.length>0&&r[r.length-1].unpause()}}),i=function(e){return setTimeout(e,0)},c=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},u=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e};e.createFocusTrap=function(e,r){var s,l=document,f=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},r),b={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},v=function(e,t,n){return e&&void 0!==e[t]?e[t]:f[n||t]},p=function(e){return b.containers.some((function(t){return t.contains(e)}))},d=function(e){var t=f[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=l.querySelector(t)))throw new Error("`".concat(e,"` refers to no known node"));if("function"==typeof t&&!(n=t()))throw new Error("`".concat(e,"` did not return a node"));return n},y=function(){var e;if(!1===v({},"initialFocus"))return!1;if(null!==d("initialFocus"))e=d("initialFocus");else if(p(l.activeElement))e=l.activeElement;else{var t=b.tabbableGroups[0];e=t&&t.firstTabbableNode||d("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},h=function(){if(b.tabbableGroups=b.containers.map((function(e){var n=t.tabbable(e);if(n.length>0)return{container:e,firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),b.tabbableGroups.length<=0&&!d("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},m=function e(t){!1!==t&&t!==l.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!f.preventScroll}),b.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(y()))},g=function(e){var t=d("setReturnFocus");return t||e},F=function(e){p(e.target)||(u(f.clickOutsideDeactivates,e)?s.deactivate({returnFocus:f.returnFocusOnDeactivate&&!t.isFocusable(e.target)}):u(f.allowOutsideClick,e)||e.preventDefault())},O=function(e){var t=p(e.target);t||e.target instanceof Document?t&&(b.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(b.mostRecentlyFocusedNode||y()))},T=function(e){if(function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e)&&!1!==u(f.escapeDeactivates))return e.preventDefault(),void s.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){h();var t=null;if(b.tabbableGroups.length>0){var n=c(b.tabbableGroups,(function(t){return t.container.contains(e.target)}));if(n<0)t=e.shiftKey?b.tabbableGroups[b.tabbableGroups.length-1].lastTabbableNode:b.tabbableGroups[0].firstTabbableNode;else if(e.shiftKey){var a=c(b.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(a<0&&b.tabbableGroups[n].container===e.target&&(a=n),a>=0){var r=0===a?b.tabbableGroups.length-1:a-1;t=b.tabbableGroups[r].lastTabbableNode}}else{var o=c(b.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(o<0&&b.tabbableGroups[n].container===e.target&&(o=n),o>=0){var i=o===b.tabbableGroups.length-1?0:o+1;t=b.tabbableGroups[i].firstTabbableNode}}}else t=d("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},w=function(e){u(f.clickOutsideDeactivates,e)||p(e.target)||u(f.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},E=function(){if(b.active)return o.activateTrap(s),b.delayInitialFocusTimer=f.delayInitialFocus?i((function(){m(y())})):m(y()),l.addEventListener("focusin",O,!0),l.addEventListener("mousedown",F,{capture:!0,passive:!1}),l.addEventListener("touchstart",F,{capture:!0,passive:!1}),l.addEventListener("click",w,{capture:!0,passive:!1}),l.addEventListener("keydown",T,{capture:!0,passive:!1}),s},k=function(){if(b.active)return l.removeEventListener("focusin",O,!0),l.removeEventListener("mousedown",F,!0),l.removeEventListener("touchstart",F,!0),l.removeEventListener("click",w,!0),l.removeEventListener("keydown",T,!0),s};return(s={activate:function(e){if(b.active)return this;var t=v(e,"onActivate"),n=v(e,"onPostActivate"),a=v(e,"checkCanFocusTrap");a||h(),b.active=!0,b.paused=!1,b.nodeFocusedBeforeActivation=l.activeElement,t&&t();var r=function(){a&&h(),E(),n&&n()};return a?(a(b.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!b.active)return this;clearTimeout(b.delayInitialFocusTimer),b.delayInitialFocusTimer=void 0,k(),b.active=!1,b.paused=!1,o.deactivateTrap(s);var t=v(e,"onDeactivate"),n=v(e,"onPostDeactivate"),a=v(e,"checkCanReturnFocus");t&&t();var r=v(e,"returnFocus","returnFocusOnDeactivate"),c=function(){i((function(){r&&m(g(b.nodeFocusedBeforeActivation)),n&&n()}))};return r&&a?(a(g(b.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return b.paused||!b.active||(b.paused=!0,k()),this},unpause:function(){return b.paused&&b.active?(b.paused=!1,h(),E(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return b.containers=t.map((function(e){return"string"==typeof e?l.querySelector(e):e})),b.active&&h(),this}}).updateContainerElements(e),s},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=focus-trap.umd.min.js.map

@@ -9,3 +9,4 @@ declare module 'focus-trap' {

type MouseEventToBoolean = (event: MouseEvent | TouchEvent) => boolean
type MouseEventToBoolean = (event: MouseEvent | TouchEvent) => boolean;
type KeyboardEventToBoolean = (event: KeyboardEvent) => boolean;

@@ -70,5 +71,6 @@ export interface Options {

* focus trap's tab order will receive focus. With this option you can
* specify a different element to receive that initial focus.
* specify a different element to receive that initial focus, or use `false`
* for no initially focused element at all.
*/
initialFocus?: FocusTarget;
initialFocus?: FocusTarget | false;
/**

@@ -95,8 +97,9 @@ * By default, an error will be thrown if the focus trap contains no

/**
* Default: `true`. If `false`, the `Escape` key will not trigger
* Default: `true`. If `false` or returns `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.
* way out. Note that if a function is given, it's only called if the ESC key
* was pressed.
*/
escapeDeactivates?: boolean;
escapeDeactivates?: boolean | KeyboardEventToBoolean;
/**

@@ -103,0 +106,0 @@ * If `true` or returns `true`, a click outside the focus trap will

import { tabbable, isFocusable } from 'tabbable';
let activeFocusDelay;
const activeFocusTraps = (function () {

@@ -114,2 +112,6 @@ const trapQueue = [];

paused: false,
// timer ID for when delayInitialFocus is true and initial focus in this trap
// has been delayed during activation
delayInitialFocusTimer: undefined,
};

@@ -158,2 +160,7 @@

// false indicates we want no initialFocus at all
if (getOption({}, 'initialFocus') === false) {
return false;
}
if (getNodeForOption('initialFocus') !== null) {

@@ -208,5 +215,10 @@ node = getNodeForOption('initialFocus');

const tryFocus = function (node) {
if (node === false) {
return;
}
if (node === doc.activeElement) {
return;
}
if (!node || !node.focus) {

@@ -389,3 +401,6 @@ tryFocus(getInitialFocusNode());

const checkKey = function (e) {
if (config.escapeDeactivates !== false && isEscapeEvent(e)) {
if (
isEscapeEvent(e) &&
valueOrHandler(config.escapeDeactivates) !== false
) {
e.preventDefault();

@@ -433,3 +448,3 @@ trap.deactivate();

// that caused the focus trap activation.
activeFocusDelay = config.delayInitialFocus
state.delayInitialFocusTimer = config.delayInitialFocus
? delay(function () {

@@ -528,3 +543,4 @@ tryFocus(getInitialFocusNode());

clearTimeout(activeFocusDelay);
clearTimeout(state.delayInitialFocusTimer); // noop if undefined
state.delayInitialFocusTimer = undefined;

@@ -531,0 +547,0 @@ removeListeners();

{
"name": "focus-trap",
"version": "6.5.1",
"version": "6.6.0",
"description": "Trap focus within a DOM node.",

@@ -68,3 +68,3 @@ "main": "dist/focus-trap.js",

"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@changesets/cli": "^2.16.0",

@@ -83,15 +83,15 @@ "@rollup/plugin-babel": "^5.3.0",

"cross-env": "^7.0.3",
"cypress": "^7.5.0",
"cypress": "^7.6.0",
"cypress-plugin-tab": "^1.0.5",
"eslint": "^7.28.0",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.11.3",
"onchange": "^7.1.0",
"prettier": "^2.3.1",
"rollup": "^2.51.2",
"prettier": "^2.3.2",
"rollup": "^2.52.4",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.1",
"start-server-and-test": "^1.12.5",
"typescript": "^4.3.2"
"typescript": "^4.3.4"
}
}
# 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)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -91,5 +91,5 @@

- **checkCanReturnFocus** `{(trigger: HTMLElement | SVGElement) => Promise<void>}`: An animated trigger button will have a small delay between when `onDeactivate` is called and when the focus is able to be sent back to the trigger. `checkCanReturnFocus` expects a promise to be returned. When that promise settles (resolves or rejects), focus will be sent to to the node that had focus prior to the activation of the trap (or the node configured in the `setReturnFocus` option). Due to the lack of Promise support, `checkCanReturnFocus` is not supported in IE unless you provide a Promise polyfill.
- **initialFocus** `{HTMLElement | SVGElement | string | () => HTMLElement | SVGElement}`: 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.
- **initialFocus** `{HTMLElement | SVGElement | string | () => HTMLElement | SVGElement | false}`: 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. You can also set this option to `false` to prevent any initial focus at all when the trap activates.
- **fallbackFocus** `{HTMLElement | SVGElement | string | () => HTMLElement | SVGElement}`: 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.
- **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.
- **escapeDeactivates** `{boolean} | (e: KeyboardEvent) => boolean)`: Default: `true`. If `false` or returns `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. Note that if a function is given, it's only called if the ESC key was pressed.
- **clickOutsideDeactivates** `{boolean | (e: MouseEvent | TouchEvent) => 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`.

@@ -245,2 +245,3 @@ - ⚠️ 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.

<tr>
<td align="center"><a href="https://github.com/far-fetched"><img src="https://avatars.githubusercontent.com/u/11621383?v=4?s=100" width="100px;" alt=""/><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></td>
<td align="center"><a href="https://github.com/randypuro"><img src="https://avatars2.githubusercontent.com/u/2579?v=4?s=100" 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>

@@ -252,5 +253,6 @@ <td align="center"><a href="https://github.com/sadick254"><img src="https://avatars2.githubusercontent.com/u/5238135?v=4?s=100" width="100px;" alt=""/><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>

<td align="center"><a href="https://stefancameron.com/"><img src="https://avatars3.githubusercontent.com/u/2855350?v=4?s=100" width="100px;" alt=""/><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>
<td align="center"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4?s=100" 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>
</tr>
<tr>
<td align="center"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4?s=100" 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>
<td align="center"><a href="http://willmruzek.com/"><img src="https://avatars.githubusercontent.com/u/108522?v=4?s=100" width="100px;" alt=""/><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>
<td align="center"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4?s=100" 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>

@@ -257,0 +259,0 @@ </tr>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc