Socket
Socket
Sign inDemoInstall

focus-trap

Package Overview
Dependencies
Maintainers
3
Versions
81
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.2.2 to 6.2.3

6

CHANGELOG.md
# Changelog
## 6.2.3
### Patch Changes
- 036a72e: Fix crash in IE due to use of `Array.findIndex()` not supported in that browser (#257)
## 6.2.2

@@ -4,0 +10,0 @@

21

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

@@ -108,2 +108,17 @@ */

return setTimeout(fn, 0);
}; // Array.find/findIndex() are not supported on IE; this replicates enough
// of Array.findIndex() for our needs
var findIndex = function findIndex(arr, fn) {
var idx = -1;
arr.every(function (value, i) {
if (fn(value)) {
idx = i;
return false; // break
}
return true; // next
});
return idx;
};

@@ -303,3 +318,3 @@

if (e.shiftKey) {
var startOfGroupIndex = state.tabbableGroups.findIndex(function (_ref) {
var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref) {
var firstTabbableNode = _ref.firstTabbableNode;

@@ -315,3 +330,3 @@ return e.target === firstTabbableNode;

} else {
var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref2) {
var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
var lastTabbableNode = _ref2.lastTabbableNode;

@@ -318,0 +333,0 @@ return e.target === lastTabbableNode;

4

dist/focus-trap.esm.min.js
/*!
* focus-trap 6.2.2
* focus-trap 6.2.3
* @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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(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}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(o,u){var s,l=document,f=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},u),v={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},b=function(e){return v.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},p=function(){var e;if(null!==d("initialFocus"))e=d("initialFocus");else if(b(l.activeElement))e=l.activeElement;else{var t=v.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},m=function(){if(v.tabbableGroups=v.containers.map((function(t){var n=e(t);if(n.length>0)return{firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),v.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")},y=function e(t){t!==l.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!f.preventScroll}),v.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(p()))},h=function(e){b(e.target)||(f.clickOutsideDeactivates?s.deactivate({returnFocus:f.returnFocusOnDeactivate&&!t(e.target)}):f.allowOutsideClick&&("boolean"==typeof f.allowOutsideClick?f.allowOutsideClick:f.allowOutsideClick(e))||e.preventDefault())},O=function(e){var t=b(e.target);t||e.target instanceof Document?t&&(v.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),y(v.mostRecentlyFocusedNode||p()))},g=function(e){if(!1!==f.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))return e.preventDefault(),void s.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){m();var t=null;if(v.tabbableGroups.length>0)if(e.shiftKey){var n=v.tabbableGroups.findIndex((function(t){var n=t.firstTabbableNode;return e.target===n}));if(n>=0){var a=0===n?v.tabbableGroups.length-1:n-1;t=v.tabbableGroups[a].lastTabbableNode}}else{var r=v.tabbableGroups.findIndex((function(t){var n=t.lastTabbableNode;return e.target===n}));if(r>=0){var o=r===v.tabbableGroups.length-1?0:r+1;t=v.tabbableGroups[o].firstTabbableNode}}else t=d("fallbackFocus");t&&(e.preventDefault(),y(t))}(e)},w=function(e){f.clickOutsideDeactivates||b(e.target)||f.allowOutsideClick&&("boolean"==typeof f.allowOutsideClick?f.allowOutsideClick:f.allowOutsideClick(e))||(e.preventDefault(),e.stopImmediatePropagation())},k=function(){if(v.active)return i.activateTrap(s),r=f.delayInitialFocus?c((function(){y(p())})):y(p()),l.addEventListener("focusin",O,!0),l.addEventListener("mousedown",h,{capture:!0,passive:!1}),l.addEventListener("touchstart",h,{capture:!0,passive:!1}),l.addEventListener("click",w,{capture:!0,passive:!1}),l.addEventListener("keydown",g,{capture:!0,passive:!1}),s},E=function(){if(v.active)return l.removeEventListener("focusin",O,!0),l.removeEventListener("mousedown",h,!0),l.removeEventListener("touchstart",h,!0),l.removeEventListener("click",w,!0),l.removeEventListener("keydown",g,!0),s};return(s={activate:function(e){if(v.active)return this;m(),v.active=!0,v.paused=!1,v.nodeFocusedBeforeActivation=l.activeElement;var t=e&&e.onActivate?e.onActivate:f.onActivate;return t&&t(),k(),this},deactivate:function(e){if(!v.active)return this;clearTimeout(r),E(),v.active=!1,v.paused=!1,i.deactivateTrap(s);var t=e&&void 0!==e.onDeactivate?e.onDeactivate:f.onDeactivate;return t&&t(),(e&&void 0!==e.returnFocus?e.returnFocus:f.returnFocusOnDeactivate)&&c((function(){var e;y((e=v.nodeFocusedBeforeActivation,d("setReturnFocus")||e))})),this},pause:function(){return v.paused||!v.active||(v.paused=!0,E()),this},unpause:function(){return v.paused&&v.active?(v.paused=!1,m(),k(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return v.containers=t.map((function(e){return"string"==typeof e?l.querySelector(e):e})),v.active&&m(),this}}).updateContainerElements(o),s};export{u as createFocusTrap};
import{tabbable as e,isFocusable as t}from"tabbable";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}function a(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}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(o,s){var l,f=document,v=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},s),b={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},p=function(e){return b.containers.some((function(t){return t.contains(e)}))},d=function(e){var t=v[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},m=function(){var e;if(null!==d("initialFocus"))e=d("initialFocus");else if(p(f.activeElement))e=f.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(t);if(n.length>0)return{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")},h=function e(t){t!==f.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!v.preventScroll}),b.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(m()))},O=function(e){p(e.target)||(v.clickOutsideDeactivates?l.deactivate({returnFocus:v.returnFocusOnDeactivate&&!t(e.target)}):v.allowOutsideClick&&("boolean"==typeof v.allowOutsideClick?v.allowOutsideClick:v.allowOutsideClick(e))||e.preventDefault())},g=function(e){var t=p(e.target);t||e.target instanceof Document?t&&(b.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),h(b.mostRecentlyFocusedNode||m()))},w=function(e){if(!1!==v.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){y();var t=null;if(b.tabbableGroups.length>0)if(e.shiftKey){var n=u(b.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(n>=0){var a=0===n?b.tabbableGroups.length-1:n-1;t=b.tabbableGroups[a].lastTabbableNode}}else{var r=u(b.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(r>=0){var o=r===b.tabbableGroups.length-1?0:r+1;t=b.tabbableGroups[o].firstTabbableNode}}else t=d("fallbackFocus");t&&(e.preventDefault(),h(t))}(e)},k=function(e){v.clickOutsideDeactivates||p(e.target)||v.allowOutsideClick&&("boolean"==typeof v.allowOutsideClick?v.allowOutsideClick:v.allowOutsideClick(e))||(e.preventDefault(),e.stopImmediatePropagation())},E=function(){if(b.active)return i.activateTrap(l),r=v.delayInitialFocus?c((function(){h(m())})):h(m()),f.addEventListener("focusin",g,!0),f.addEventListener("mousedown",O,{capture:!0,passive:!1}),f.addEventListener("touchstart",O,{capture:!0,passive:!1}),f.addEventListener("click",k,{capture:!0,passive:!1}),f.addEventListener("keydown",w,{capture:!0,passive:!1}),l},F=function(){if(b.active)return f.removeEventListener("focusin",g,!0),f.removeEventListener("mousedown",O,!0),f.removeEventListener("touchstart",O,!0),f.removeEventListener("click",k,!0),f.removeEventListener("keydown",w,!0),l};return(l={activate:function(e){if(b.active)return this;y(),b.active=!0,b.paused=!1,b.nodeFocusedBeforeActivation=f.activeElement;var t=e&&e.onActivate?e.onActivate:v.onActivate;return t&&t(),E(),this},deactivate:function(e){if(!b.active)return this;clearTimeout(r),F(),b.active=!1,b.paused=!1,i.deactivateTrap(l);var t=e&&void 0!==e.onDeactivate?e.onDeactivate:v.onDeactivate;return t&&t(),(e&&void 0!==e.returnFocus?e.returnFocus:v.returnFocusOnDeactivate)&&c((function(){var e;h((e=b.nodeFocusedBeforeActivation,d("setReturnFocus")||e))})),this},pause:function(){return b.paused||!b.active||(b.paused=!0,F()),this},unpause:function(){return b.paused&&b.active?(b.paused=!1,y(),E(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return b.containers=t.map((function(e){return"string"==typeof e?f.querySelector(e):e})),b.active&&y(),this}}).updateContainerElements(o),l};export{s as createFocusTrap};
//# sourceMappingURL=focus-trap.esm.min.js.map
/*!
* focus-trap 6.2.2
* focus-trap 6.2.3
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE

@@ -112,2 +112,17 @@ */

return setTimeout(fn, 0);
}; // Array.find/findIndex() are not supported on IE; this replicates enough
// of Array.findIndex() for our needs
var findIndex = function findIndex(arr, fn) {
var idx = -1;
arr.every(function (value, i) {
if (fn(value)) {
idx = i;
return false; // break
}
return true; // next
});
return idx;
};

@@ -307,3 +322,3 @@

if (e.shiftKey) {
var startOfGroupIndex = state.tabbableGroups.findIndex(function (_ref) {
var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref) {
var firstTabbableNode = _ref.firstTabbableNode;

@@ -319,3 +334,3 @@ return e.target === firstTabbableNode;

} else {
var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref2) {
var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
var lastTabbableNode = _ref2.lastTabbableNode;

@@ -322,0 +337,0 @@ return e.target === lastTabbableNode;

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

@@ -117,2 +117,17 @@ */

return setTimeout(fn, 0);
}; // Array.find/findIndex() are not supported on IE; this replicates enough
// of Array.findIndex() for our needs
var findIndex = function findIndex(arr, fn) {
var idx = -1;
arr.every(function (value, i) {
if (fn(value)) {
idx = i;
return false; // break
}
return true; // next
});
return idx;
};

@@ -312,3 +327,3 @@

if (e.shiftKey) {
var startOfGroupIndex = state.tabbableGroups.findIndex(function (_ref) {
var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref) {
var firstTabbableNode = _ref.firstTabbableNode;

@@ -324,3 +339,3 @@ return e.target === firstTabbableNode;

} else {
var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref2) {
var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
var lastTabbableNode = _ref2.lastTabbableNode;

@@ -327,0 +342,0 @@ return e.target === lastTabbableNode;

/*!
* focus-trap 6.2.2
* focus-trap 6.2.3
* @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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(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}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)};e.createFocusTrap=function(e,o){var u,s=document,l=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},o),f={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},b=function(e){return f.containers.some((function(t){return t.contains(e)}))},v=function(e){var t=l[e];if(!t)return null;var n=t;if("string"==typeof t&&!(n=s.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},d=function(){var e;if(null!==v("initialFocus"))e=v("initialFocus");else if(b(s.activeElement))e=s.activeElement;else{var t=f.tabbableGroups[0];e=t&&t.firstTabbableNode||v("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},p=function(){if(f.tabbableGroups=f.containers.map((function(e){var n=t.tabbable(e);if(n.length>0)return{firstTabbableNode:n[0],lastTabbableNode:n[n.length-1]}})).filter((function(e){return!!e})),f.tabbableGroups.length<=0&&!v("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!==s.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!l.preventScroll}),f.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(d()))},y=function(e){b(e.target)||(l.clickOutsideDeactivates?u.deactivate({returnFocus:l.returnFocusOnDeactivate&&!t.isFocusable(e.target)}):l.allowOutsideClick&&("boolean"==typeof l.allowOutsideClick?l.allowOutsideClick:l.allowOutsideClick(e))||e.preventDefault())},h=function(e){var t=b(e.target);t||e.target instanceof Document?t&&(f.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(f.mostRecentlyFocusedNode||d()))},g=function(e){if(!1!==l.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))return e.preventDefault(),void u.deactivate();(function(e){return"Tab"===e.key||9===e.keyCode})(e)&&function(e){p();var t=null;if(f.tabbableGroups.length>0)if(e.shiftKey){var n=f.tabbableGroups.findIndex((function(t){var n=t.firstTabbableNode;return e.target===n}));if(n>=0){var a=0===n?f.tabbableGroups.length-1:n-1;t=f.tabbableGroups[a].lastTabbableNode}}else{var r=f.tabbableGroups.findIndex((function(t){var n=t.lastTabbableNode;return e.target===n}));if(r>=0){var o=r===f.tabbableGroups.length-1?0:r+1;t=f.tabbableGroups[o].firstTabbableNode}}else t=v("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},O=function(e){l.clickOutsideDeactivates||b(e.target)||l.allowOutsideClick&&("boolean"==typeof l.allowOutsideClick?l.allowOutsideClick:l.allowOutsideClick(e))||(e.preventDefault(),e.stopImmediatePropagation())},w=function(){if(f.active)return i.activateTrap(u),r=l.delayInitialFocus?c((function(){m(d())})):m(d()),s.addEventListener("focusin",h,!0),s.addEventListener("mousedown",y,{capture:!0,passive:!1}),s.addEventListener("touchstart",y,{capture:!0,passive:!1}),s.addEventListener("click",O,{capture:!0,passive:!1}),s.addEventListener("keydown",g,{capture:!0,passive:!1}),u},k=function(){if(f.active)return s.removeEventListener("focusin",h,!0),s.removeEventListener("mousedown",y,!0),s.removeEventListener("touchstart",y,!0),s.removeEventListener("click",O,!0),s.removeEventListener("keydown",g,!0),u};return(u={activate:function(e){if(f.active)return this;p(),f.active=!0,f.paused=!1,f.nodeFocusedBeforeActivation=s.activeElement;var t=e&&e.onActivate?e.onActivate:l.onActivate;return t&&t(),w(),this},deactivate:function(e){if(!f.active)return this;clearTimeout(r),k(),f.active=!1,f.paused=!1,i.deactivateTrap(u);var t=e&&void 0!==e.onDeactivate?e.onDeactivate:l.onDeactivate;return t&&t(),(e&&void 0!==e.returnFocus?e.returnFocus:l.returnFocusOnDeactivate)&&c((function(){var e;m((e=f.nodeFocusedBeforeActivation,v("setReturnFocus")||e))})),this},pause:function(){return f.paused||!f.active||(f.paused=!0,k()),this},unpause:function(){return f.paused&&f.active?(f.paused=!1,p(),w(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return f.containers=t.map((function(e){return"string"==typeof e?s.querySelector(e):e})),f.active&&p(),this}}).updateContainerElements(e),u},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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(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}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};e.createFocusTrap=function(e,o){var s,l=document,f=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},o),b={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1},v=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},p=function(){var e;if(null!==d("initialFocus"))e=d("initialFocus");else if(v(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(e){var n=t.tabbable(e);if(n.length>0)return{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){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(p()))},h=function(e){v(e.target)||(f.clickOutsideDeactivates?s.deactivate({returnFocus:f.returnFocusOnDeactivate&&!t.isFocusable(e.target)}):f.allowOutsideClick&&("boolean"==typeof f.allowOutsideClick?f.allowOutsideClick:f.allowOutsideClick(e))||e.preventDefault())},g=function(e){var t=v(e.target);t||e.target instanceof Document?t&&(b.mostRecentlyFocusedNode=e.target):(e.stopImmediatePropagation(),m(b.mostRecentlyFocusedNode||p()))},O=function(e){if(!1!==f.escapeDeactivates&&function(e){return"Escape"===e.key||"Esc"===e.key||27===e.keyCode}(e))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)if(e.shiftKey){var n=u(b.tabbableGroups,(function(t){var n=t.firstTabbableNode;return e.target===n}));if(n>=0){var a=0===n?b.tabbableGroups.length-1:n-1;t=b.tabbableGroups[a].lastTabbableNode}}else{var r=u(b.tabbableGroups,(function(t){var n=t.lastTabbableNode;return e.target===n}));if(r>=0){var o=r===b.tabbableGroups.length-1?0:r+1;t=b.tabbableGroups[o].firstTabbableNode}}else t=d("fallbackFocus");t&&(e.preventDefault(),m(t))}(e)},w=function(e){f.clickOutsideDeactivates||v(e.target)||f.allowOutsideClick&&("boolean"==typeof f.allowOutsideClick?f.allowOutsideClick:f.allowOutsideClick(e))||(e.preventDefault(),e.stopImmediatePropagation())},k=function(){if(b.active)return i.activateTrap(s),r=f.delayInitialFocus?c((function(){m(p())})):m(p()),l.addEventListener("focusin",g,!0),l.addEventListener("mousedown",h,{capture:!0,passive:!1}),l.addEventListener("touchstart",h,{capture:!0,passive:!1}),l.addEventListener("click",w,{capture:!0,passive:!1}),l.addEventListener("keydown",O,{capture:!0,passive:!1}),s},E=function(){if(b.active)return l.removeEventListener("focusin",g,!0),l.removeEventListener("mousedown",h,!0),l.removeEventListener("touchstart",h,!0),l.removeEventListener("click",w,!0),l.removeEventListener("keydown",O,!0),s};return(s={activate:function(e){if(b.active)return this;y(),b.active=!0,b.paused=!1,b.nodeFocusedBeforeActivation=l.activeElement;var t=e&&e.onActivate?e.onActivate:f.onActivate;return t&&t(),k(),this},deactivate:function(e){if(!b.active)return this;clearTimeout(r),E(),b.active=!1,b.paused=!1,i.deactivateTrap(s);var t=e&&void 0!==e.onDeactivate?e.onDeactivate:f.onDeactivate;return t&&t(),(e&&void 0!==e.returnFocus?e.returnFocus:f.returnFocusOnDeactivate)&&c((function(){var e;m((e=b.nodeFocusedBeforeActivation,d("setReturnFocus")||e))})),this},pause:function(){return b.paused||!b.active||(b.paused=!0,E()),this},unpause:function(){return b.paused&&b.active?(b.paused=!1,y(),k(),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(e),s},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=focus-trap.umd.min.js.map

@@ -59,2 +59,19 @@ import { tabbable, isFocusable } from 'tabbable';

// Array.find/findIndex() are not supported on IE; this replicates enough
// of Array.findIndex() for our needs
const findIndex = function (arr, fn) {
let idx = -1;
arr.every(function (value, i) {
if (fn(value)) {
idx = i;
return false; // break
}
return true; // next
});
return idx;
};
const createFocusTrap = function (elements, userOptions) {

@@ -263,3 +280,4 @@ const doc = document;

if (e.shiftKey) {
const startOfGroupIndex = state.tabbableGroups.findIndex(
const startOfGroupIndex = findIndex(
state.tabbableGroups,
({ firstTabbableNode }) => e.target === firstTabbableNode

@@ -278,3 +296,4 @@ );

} else {
const lastOfGroupIndex = state.tabbableGroups.findIndex(
const lastOfGroupIndex = findIndex(
state.tabbableGroups,
({ lastTabbableNode }) => e.target === lastTabbableNode

@@ -281,0 +300,0 @@ );

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

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

"@testing-library/cypress": "^7.0.2",
"@types/jquery": "^3.5.4",
"@types/jquery": "^3.5.5",
"all-contributors-cli": "^6.19.0",

@@ -80,9 +80,9 @@ "babel-eslint": "^10.1.0",

"budo": "^11.6.4",
"cypress": "^6.0.1",
"cypress": "^6.1.0",
"cypress-plugin-tab": "^1.0.5",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-cypress": "^2.11.2",
"prettier": "^2.2.1",
"rollup": "^2.34.0",
"rollup": "^2.34.2",
"rollup-plugin-sourcemaps": "^0.6.3",

@@ -89,0 +89,0 @@ "rollup-plugin-terser": "^7.0.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)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -236,2 +236,3 @@

<td align="center"><a href="https://github.com/zioth"><img src="https://avatars3.githubusercontent.com/u/945603?v=4" width="100px;" alt=""/><br /><sub><b>Zioth</b></sub></a><br /><a href="#ideas-zioth" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Azioth" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/randypuro"><img src="https://avatars2.githubusercontent.com/u/2579?v=4" width="100px;" alt=""/><br /><sub><b>Randy Puro</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap/issues?q=author%3Arandypuro" title="Bug reports">🐛</a></td>
</tr>

@@ -238,0 +239,0 @@ </table>

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