focus-trap 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"focus-trap.umd.min.js","sources":["../index.js"],"sourcesContent":["import {\n tabbable,\n focusable,\n isFocusable,\n isTabbable,\n getTabIndex,\n} from 'tabbable';\n\nconst activeFocusTraps = {\n // Returns the trap from the top of the stack.\n getActiveTrap(trapStack) {\n if (trapStack?.length > 0) {\n return trapStack[trapStack.length - 1];\n }\n return null;\n },\n\n // Pauses the currently active trap, then adds a new trap to the stack.\n activateTrap(trapStack, trap) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n\n if (trap !== activeTrap) {\n activeFocusTraps.pauseTrap(trapStack);\n }\n\n const trapIndex = trapStack.indexOf(trap);\n if (trapIndex === -1) {\n trapStack.push(trap);\n } else {\n // move this existing trap to the front of the queue\n trapStack.splice(trapIndex, 1);\n trapStack.push(trap);\n }\n },\n\n // Removes the trap from the top of the stack, then unpauses the next trap down.\n deactivateTrap(trapStack, trap) {\n const trapIndex = trapStack.indexOf(trap);\n if (trapIndex !== -1) {\n trapStack.splice(trapIndex, 1);\n }\n\n activeFocusTraps.unpauseTrap(trapStack);\n },\n\n // Pauses the trap at the top of the stack.\n pauseTrap(trapStack) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n activeTrap?._setPausedState(true);\n },\n\n // Unpauses the trap at the top of the stack.\n unpauseTrap(trapStack) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n\n if (activeTrap && !activeTrap._isManuallyPaused()) {\n activeTrap._setPausedState(false);\n }\n },\n};\n\nconst isSelectableInput = function (node) {\n return (\n node.tagName &&\n node.tagName.toLowerCase() === 'input' &&\n typeof node.select === 'function'\n );\n};\n\nconst isEscapeEvent = function (e) {\n return e?.key === 'Escape' || e?.key === 'Esc' || e?.keyCode === 27;\n};\n\nconst isTabEvent = function (e) {\n return e?.key === 'Tab' || e?.keyCode === 9;\n};\n\n// checks for TAB by default\nconst isKeyForward = function (e) {\n return isTabEvent(e) && !e.shiftKey;\n};\n\n// checks for SHIFT+TAB by default\nconst isKeyBackward = function (e) {\n return isTabEvent(e) && e.shiftKey;\n};\n\nconst delay = function (fn) {\n return setTimeout(fn, 0);\n};\n\n/**\n * Get an option's value when it could be a plain value, or a handler that provides\n * the value.\n * @param {*} value Option's value to check.\n * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.\n * @returns {*} The `value`, or the handler's returned value.\n */\nconst valueOrHandler = function (value, ...params) {\n return typeof value === 'function' ? value(...params) : value;\n};\n\nconst getActualTarget = function (event) {\n // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the\n // shadow host. However, event.target.composedPath() will be an array of\n // nodes \"clicked\" from inner-most (the actual element inside the shadow) to\n // outer-most (the host HTML document). If we have access to composedPath(),\n // then use its first element; otherwise, fall back to event.target (and\n // this only works for an _open_ shadow DOM; otherwise,\n // composedPath()[0] === event.target always).\n return event.target.shadowRoot && typeof event.composedPath === 'function'\n ? event.composedPath()[0]\n : event.target;\n};\n\n// NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this\n// current instance use the same stack if `userOptions.trapStack` isn't specified\nconst internalTrapStack = [];\n\nconst createFocusTrap = function (elements, userOptions) {\n // SSR: a live trap shouldn't be created in this type of environment so this\n // should be safe code to execute if the `document` option isn't specified\n const doc = userOptions?.document || document;\n\n const trapStack = userOptions?.trapStack || internalTrapStack;\n\n const config = {\n returnFocusOnDeactivate: true,\n escapeDeactivates: true,\n delayInitialFocus: true,\n isolateSubtrees: false,\n isKeyForward,\n isKeyBackward,\n ...userOptions,\n };\n\n const state = {\n // containers given to createFocusTrap()\n /** @type {Array<HTMLElement>} */\n containers: [],\n\n // list of objects identifying tabbable nodes in `containers` in the trap\n // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap\n // is active, but the trap should never get to a state where there isn't at least one group\n // with at least one tabbable node in it (that would lead to an error condition that would\n // result in an error being thrown)\n /** @type {Array<{\n * container: HTMLElement,\n * tabbableNodes: Array<HTMLElement>, // empty if none\n * focusableNodes: Array<HTMLElement>, // empty if none\n * posTabIndexesFound: boolean,\n * firstTabbableNode: HTMLElement|undefined,\n * lastTabbableNode: HTMLElement|undefined,\n * firstDomTabbableNode: HTMLElement|undefined,\n * lastDomTabbableNode: HTMLElement|undefined,\n * nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined\n * }>}\n */\n containerGroups: [], // same order/length as `containers` list\n\n // references to objects in `containerGroups`, but only those that actually have\n // tabbable nodes in them\n // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__\n // the same length\n tabbableGroups: [],\n\n // references to nodes that are siblings to the ancestors of this trap's containers.\n /** @type {Set<HTMLElement>} */\n adjacentElements: new Set(),\n\n // references to nodes that were inert or aria-hidden before the trap was activated.\n /** @type {Set<HTMLElement>} */\n alreadySilent: new Set(),\n nodeFocusedBeforeActivation: null,\n mostRecentlyFocusedNode: null,\n active: false,\n paused: false,\n manuallyPaused: false,\n\n // timer ID for when delayInitialFocus is true and initial focus in this trap\n // has been delayed during activation\n delayInitialFocusTimer: undefined,\n\n // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any\n recentNavEvent: undefined,\n };\n\n let trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later\n\n /**\n * Gets a configuration option value.\n * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,\n * value will be taken from this object. Otherwise, value will be taken from base configuration.\n * @param {string} optionName Name of the option whose value is sought.\n * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`\n * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.\n */\n const getOption = (configOverrideOptions, optionName, configOptionName) => {\n return configOverrideOptions &&\n configOverrideOptions[optionName] !== undefined\n ? configOverrideOptions[optionName]\n : config[configOptionName || optionName];\n };\n\n /**\n * Finds the index of the container that contains the element.\n * @param {HTMLElement} element\n * @param {Event} [event] If available, and `element` isn't directly found in any container,\n * the event's composed path is used to see if includes any known trap containers in the\n * case where the element is inside a Shadow DOM.\n * @returns {number} Index of the container in either `state.containers` or\n * `state.containerGroups` (the order/length of these lists are the same); -1\n * if the element isn't found.\n */\n const findContainerIndex = function (element, event) {\n const composedPath =\n typeof event?.composedPath === 'function'\n ? event.composedPath()\n : undefined;\n // NOTE: search `containerGroups` because it's possible a group contains no tabbable\n // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)\n // and we still need to find the element in there\n return state.containerGroups.findIndex(\n ({ container, tabbableNodes }) =>\n container.contains(element) ||\n // fall back to explicit tabbable search which will take into consideration any\n // web components if the `tabbableOptions.getShadowRoot` option was used for\n // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't\n // look inside web components even if open)\n composedPath?.includes(container) ||\n tabbableNodes.find((node) => node === element)\n );\n };\n\n /**\n * Gets the node for the given option, which is expected to be an option that\n * can be either a DOM node, a string that is a selector to get a node, `false`\n * (if a node is explicitly NOT given), or a function that returns any of these\n * values.\n * @param {string} optionName\n * @param {Object} options\n * @param {boolean} [options.hasFallback] True if the option could be a selector string\n * and the option allows for a fallback scenario in the case where the selector is\n * valid but does not match a node (i.e. the queried node doesn't exist in the DOM).\n * @param {Array} [options.params] Params to pass to the option if it's a function.\n * @returns {undefined | null | false | HTMLElement | SVGElement} Returns\n * `undefined` if the option is not specified; `null` if the option didn't resolve\n * to a node but `options.hasFallback=true`, `false` if the option resolved to `false`\n * (node explicitly not given); otherwise, the resolved DOM node.\n * @throws {Error} If the option is set, not `false`, and is not, or does not\n * resolve to a node, unless the option is a selector string and `options.hasFallback=true`.\n */\n const getNodeForOption = function (\n optionName,\n { hasFallback = false, params = [] } = {}\n ) {\n let optionValue = config[optionName];\n\n if (typeof optionValue === 'function') {\n optionValue = optionValue(...params);\n }\n\n if (optionValue === true) {\n optionValue = undefined; // use default value\n }\n\n if (!optionValue) {\n if (optionValue === undefined || optionValue === false) {\n return optionValue;\n }\n // else, empty string (invalid), null (invalid), 0 (invalid)\n\n throw new Error(\n `\\`${optionName}\\` was specified but was not a node, or did not return a node`\n );\n }\n\n let node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point\n\n if (typeof optionValue === 'string') {\n try {\n node = doc.querySelector(optionValue); // resolve to node, or null if fails\n } catch (err) {\n throw new Error(\n `\\`${optionName}\\` appears to be an invalid selector; error=\"${err.message}\"`\n );\n }\n\n if (!node) {\n if (!hasFallback) {\n throw new Error(\n `\\`${optionName}\\` as selector refers to no known node`\n );\n }\n // else, `node` MUST be `null` because that's what `Document.querySelector()` returns\n // if the selector is valid but doesn't match anything\n }\n }\n\n return node;\n };\n\n const getInitialFocusNode = function () {\n let node = getNodeForOption('initialFocus', { hasFallback: true });\n\n // false explicitly indicates we want no initialFocus at all\n if (node === false) {\n return false;\n }\n\n if (\n node === undefined ||\n (node && !isFocusable(node, config.tabbableOptions))\n ) {\n // option not specified nor focusable: use fallback options\n if (findContainerIndex(doc.activeElement) >= 0) {\n node = doc.activeElement;\n } else {\n const firstTabbableGroup = state.tabbableGroups[0];\n const firstTabbableNode =\n firstTabbableGroup && firstTabbableGroup.firstTabbableNode;\n\n // NOTE: `fallbackFocus` option function cannot return `false` (not supported)\n node = firstTabbableNode || getNodeForOption('fallbackFocus');\n }\n } else if (node === null) {\n // option is a VALID selector string that doesn't yield a node: use the `fallbackFocus`\n // option instead of the default behavior when the option isn't specified at all\n node = getNodeForOption('fallbackFocus');\n }\n\n if (!node) {\n throw new Error(\n 'Your focus-trap needs to have at least one focusable element'\n );\n }\n\n return node;\n };\n\n const updateTabbableNodes = function () {\n state.containerGroups = state.containers.map((container) => {\n const tabbableNodes = tabbable(container, config.tabbableOptions);\n\n // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes\n // are a superset of tabbable nodes since nodes with negative `tabindex` attributes\n // are focusable but not tabbable\n const focusableNodes = focusable(container, config.tabbableOptions);\n\n const firstTabbableNode =\n tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;\n const lastTabbableNode =\n tabbableNodes.length > 0\n ? tabbableNodes[tabbableNodes.length - 1]\n : undefined;\n\n const firstDomTabbableNode = focusableNodes.find((node) =>\n isTabbable(node)\n );\n const lastDomTabbableNode = focusableNodes\n .slice()\n .reverse()\n .find((node) => isTabbable(node));\n\n const posTabIndexesFound = !!tabbableNodes.find(\n (node) => getTabIndex(node) > 0\n );\n\n return {\n container,\n tabbableNodes,\n focusableNodes,\n\n /** True if at least one node with positive `tabindex` was found in this container. */\n posTabIndexesFound,\n\n /** First tabbable node in container, __tabindex__ order; `undefined` if none. */\n firstTabbableNode,\n /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */\n lastTabbableNode,\n\n // NOTE: DOM order is NOT NECESSARILY \"document position\" order, but figuring that out\n // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n // because that API doesn't work with Shadow DOM as well as it should (@see\n // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,\n // to address an edge case related to positive tabindex support, this seems like a much easier,\n // \"close enough most of the time\" alternative for positive tabindexes which should generally\n // be avoided anyway...\n /** First tabbable node in container, __DOM__ order; `undefined` if none. */\n firstDomTabbableNode,\n /** Last tabbable node in container, __DOM__ order; `undefined` if none. */\n lastDomTabbableNode,\n\n /**\n * Finds the __tabbable__ node that follows the given node in the specified direction,\n * in this container, if any.\n * @param {HTMLElement} node\n * @param {boolean} [forward] True if going in forward tab order; false if going\n * in reverse.\n * @returns {HTMLElement|undefined} The next tabbable node, if any.\n */\n nextTabbableNode(node, forward = true) {\n const nodeIdx = tabbableNodes.indexOf(node);\n if (nodeIdx < 0) {\n // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):\n // since `node` should at least have been focusable, we assume that's the case and mimic\n // what browsers do, which is set focus to the next node in __document position order__,\n // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE\n // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to\n // basic DOM order\n if (forward) {\n return focusableNodes\n .slice(focusableNodes.indexOf(node) + 1)\n .find((el) => isTabbable(el));\n }\n\n return focusableNodes\n .slice(0, focusableNodes.indexOf(node))\n .reverse()\n .find((el) => isTabbable(el));\n }\n\n return tabbableNodes[nodeIdx + (forward ? 1 : -1)];\n },\n };\n });\n\n state.tabbableGroups = state.containerGroups.filter(\n (group) => group.tabbableNodes.length > 0\n );\n\n // throw if no groups have tabbable nodes and we don't have a fallback focus node either\n if (\n state.tabbableGroups.length <= 0 &&\n !getNodeForOption('fallbackFocus') // returning false not supported for this option\n ) {\n throw new Error(\n 'Your focus-trap must have at least one container with at least one tabbable node in it at all times'\n );\n }\n\n // NOTE: Positive tabindexes are only properly supported in single-container traps because\n // doing it across multiple containers where tabindexes could be all over the place\n // would require Tabbable to support multiple containers, would require additional\n // specialized Shadow DOM support, and would require Tabbable's multi-container support\n // to look at those containers in document position order rather than user-provided\n // order (as they are treated in Focus-trap, for legacy reasons). See discussion on\n // https://github.com/focus-trap/focus-trap/issues/375 for more details.\n if (\n state.containerGroups.find((g) => g.posTabIndexesFound) &&\n state.containerGroups.length > 1\n ) {\n throw new Error(\n \"At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.\"\n );\n }\n };\n\n /**\n * Gets the current activeElement. If it's a web-component and has open shadow-root\n * it will recursively search inside shadow roots for the \"true\" activeElement.\n *\n * @param {Document | ShadowRoot} el\n *\n * @returns {HTMLElement} The element that currently has the focus\n **/\n const getActiveElement = function (el) {\n const activeElement = el.activeElement;\n\n if (!activeElement) {\n return;\n }\n\n if (\n activeElement.shadowRoot &&\n activeElement.shadowRoot.activeElement !== null\n ) {\n return getActiveElement(activeElement.shadowRoot);\n }\n\n return activeElement;\n };\n\n const tryFocus = function (node) {\n if (node === false) {\n return;\n }\n\n if (node === getActiveElement(document)) {\n return;\n }\n\n if (!node || !node.focus) {\n tryFocus(getInitialFocusNode());\n return;\n }\n\n node.focus({ preventScroll: !!config.preventScroll });\n // NOTE: focus() API does not trigger focusIn event so set MRU node manually\n state.mostRecentlyFocusedNode = node;\n\n if (isSelectableInput(node)) {\n node.select();\n }\n };\n\n const getReturnFocusNode = function (previousActiveElement) {\n const node = getNodeForOption('setReturnFocus', {\n params: [previousActiveElement],\n });\n return node ? node : node === false ? false : previousActiveElement;\n };\n\n /**\n * Finds the next node (in either direction) where focus should move according to a\n * keyboard focus-in event.\n * @param {Object} params\n * @param {Node} [params.target] Known target __from which__ to navigate, if any.\n * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event\n * will be used to determine the `target`). Ignored if `target` is specified.\n * @param {boolean} [params.isBackward] True if focus should move backward.\n * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be\n * determined given the current state of the trap.\n */\n const findNextNavNode = function ({ target, event, isBackward = false }) {\n target = target || getActualTarget(event);\n updateTabbableNodes();\n\n let destinationNode = null;\n\n if (state.tabbableGroups.length > 0) {\n // make sure the target is actually contained in a group\n // NOTE: the target may also be the container itself if it's focusable\n // with tabIndex='-1' and was given initial focus\n const containerIndex = findContainerIndex(target, event);\n const containerGroup =\n containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;\n\n if (containerIndex < 0) {\n // target not found in any group: quite possible focus has escaped the trap,\n // so bring it back into...\n if (isBackward) {\n // ...the last node in the last group\n destinationNode =\n state.tabbableGroups[state.tabbableGroups.length - 1]\n .lastTabbableNode;\n } else {\n // ...the first node in the first group\n destinationNode = state.tabbableGroups[0].firstTabbableNode;\n }\n } else if (isBackward) {\n // REVERSE\n\n // is the target the first tabbable node in a group?\n let startOfGroupIndex = state.tabbableGroups.findIndex(\n ({ firstTabbableNode }) => target === firstTabbableNode\n );\n\n if (\n startOfGroupIndex < 0 &&\n (containerGroup.container === target ||\n (isFocusable(target, config.tabbableOptions) &&\n !isTabbable(target, config.tabbableOptions) &&\n !containerGroup.nextTabbableNode(target, false)))\n ) {\n // an exception case where the target is either the container itself, or\n // a non-tabbable node that was given focus (i.e. tabindex is negative\n // and user clicked on it or node was programmatically given focus)\n // and is not followed by any other tabbable node, in which\n // case, we should handle shift+tab as if focus were on the container's\n // first tabbable node, and go to the last tabbable node of the LAST group\n startOfGroupIndex = containerIndex;\n }\n\n if (startOfGroupIndex >= 0) {\n // YES: then shift+tab should go to the last tabbable node in the\n // previous group (and wrap around to the last tabbable node of\n // the LAST group if it's the first tabbable node of the FIRST group)\n const destinationGroupIndex =\n startOfGroupIndex === 0\n ? state.tabbableGroups.length - 1\n : startOfGroupIndex - 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n\n destinationNode =\n getTabIndex(target) >= 0\n ? destinationGroup.lastTabbableNode\n : destinationGroup.lastDomTabbableNode;\n } else if (!isTabEvent(event)) {\n // user must have customized the nav keys so we have to move focus manually _within_\n // the active group: do this based on the order determined by tabbable()\n destinationNode = containerGroup.nextTabbableNode(target, false);\n }\n } else {\n // FORWARD\n\n // is the target the last tabbable node in a group?\n let lastOfGroupIndex = state.tabbableGroups.findIndex(\n ({ lastTabbableNode }) => target === lastTabbableNode\n );\n\n if (\n lastOfGroupIndex < 0 &&\n (containerGroup.container === target ||\n (isFocusable(target, config.tabbableOptions) &&\n !isTabbable(target, config.tabbableOptions) &&\n !containerGroup.nextTabbableNode(target)))\n ) {\n // an exception case where the target is the container itself, or\n // a non-tabbable node that was given focus (i.e. tabindex is negative\n // and user clicked on it or node was programmatically given focus)\n // and is not followed by any other tabbable node, in which\n // case, we should handle tab as if focus were on the container's\n // last tabbable node, and go to the first tabbable node of the FIRST group\n lastOfGroupIndex = containerIndex;\n }\n\n if (lastOfGroupIndex >= 0) {\n // YES: then tab should go to the first tabbable node in the next\n // group (and wrap around to the first tabbable node of the FIRST\n // group if it's the last tabbable node of the LAST group)\n const destinationGroupIndex =\n lastOfGroupIndex === state.tabbableGroups.length - 1\n ? 0\n : lastOfGroupIndex + 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n\n destinationNode =\n getTabIndex(target) >= 0\n ? destinationGroup.firstTabbableNode\n : destinationGroup.firstDomTabbableNode;\n } else if (!isTabEvent(event)) {\n // user must have customized the nav keys so we have to move focus manually _within_\n // the active group: do this based on the order determined by tabbable()\n destinationNode = containerGroup.nextTabbableNode(target);\n }\n }\n } else {\n // no groups available\n // NOTE: the fallbackFocus option does not support returning false to opt-out\n destinationNode = getNodeForOption('fallbackFocus');\n }\n\n return destinationNode;\n };\n\n // This needs to be done on mousedown and touchstart instead of click\n // so that it precedes the focus event.\n const checkPointerDown = function (e) {\n const target = getActualTarget(e);\n\n if (findContainerIndex(target, e) >= 0) {\n // allow the click since it occurred inside the trap\n return;\n }\n\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n // immediately deactivate the trap\n trap.deactivate({\n // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,\n // which will result in the outside click setting focus to the node\n // that was clicked (and if not focusable, to \"nothing\"); by setting\n // `returnFocus: true`, we'll attempt to re-focus the node originally-focused\n // on activation (or the configured `setReturnFocus` node), whether the\n // outside click was on a focusable node or not\n returnFocus: config.returnFocusOnDeactivate,\n });\n return;\n }\n\n // This is needed for mobile devices.\n // (If we'll only let `click` events through,\n // then on mobile they will be blocked anyways if `touchstart` is blocked.)\n if (valueOrHandler(config.allowOutsideClick, e)) {\n // allow the click outside the trap to take place\n return;\n }\n\n // otherwise, prevent the click\n e.preventDefault();\n };\n\n // In case focus escapes the trap for some strange reason, pull it back in.\n // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected\n // scrolling if the node that got focused was out of view; there's nothing we can do to\n // prevent that from happening by the time we discover that focus escaped\n const checkFocusIn = function (event) {\n const target = getActualTarget(event);\n const targetContained = findContainerIndex(target, event) >= 0;\n\n // In Firefox when you Tab out of an iframe the Document is briefly focused.\n if (targetContained || target instanceof Document) {\n if (targetContained) {\n state.mostRecentlyFocusedNode = target;\n }\n } else {\n // escaped! pull it back in to where it just left\n event.stopImmediatePropagation();\n\n // focus will escape if the MRU node had a positive tab index and user tried to nav forward;\n // it will also escape if the MRU node had a 0 tab index and user tried to nav backward\n // toward a node with a positive tab index\n let nextNode; // next node to focus, if we find one\n let navAcrossContainers = true;\n if (state.mostRecentlyFocusedNode) {\n if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {\n // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...\n const mruContainerIdx = findContainerIndex(\n state.mostRecentlyFocusedNode\n );\n // there MAY not be any tabbable nodes in the container if there are at least 2 containers\n // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container\n // with at least one tabbable node in order to function, so this could be the other container\n // with nothing tabbable in it)\n const { tabbableNodes } = state.containerGroups[mruContainerIdx];\n if (tabbableNodes.length > 0) {\n // MRU tab index MAY not be found if the MRU node is focusable but not tabbable\n const mruTabIdx = tabbableNodes.findIndex(\n (node) => node === state.mostRecentlyFocusedNode\n );\n if (mruTabIdx >= 0) {\n if (config.isKeyForward(state.recentNavEvent)) {\n if (mruTabIdx + 1 < tabbableNodes.length) {\n nextNode = tabbableNodes[mruTabIdx + 1];\n navAcrossContainers = false;\n }\n // else, don't wrap within the container as focus should move to next/previous\n // container\n } else {\n if (mruTabIdx - 1 >= 0) {\n nextNode = tabbableNodes[mruTabIdx - 1];\n navAcrossContainers = false;\n }\n // else, don't wrap within the container as focus should move to next/previous\n // container\n }\n // else, don't find in container order without considering direction too\n }\n }\n // else, no tabbable nodes in that container (which means we must have at least one other\n // container with at least one tabbable node in it, otherwise focus-trap would've thrown\n // an error the last time updateTabbableNodes() was run): find next node among all known\n // containers\n } else {\n // check to see if there's at least one tabbable node with a positive tab index inside\n // the trap because focus seems to escape when navigating backward from a tabbable node\n // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with\n // the greatest positive tab index like it should)\n if (\n !state.containerGroups.some((g) =>\n g.tabbableNodes.some((n) => getTabIndex(n) > 0)\n )\n ) {\n // no containers with tabbable nodes with positive tab indexes which means the focus\n // escaped for some other reason and we should just execute the fallback to the\n // MRU node or initial focus node, if any\n navAcrossContainers = false;\n }\n }\n } else {\n // no MRU node means we're likely in some initial condition when the trap has just\n // been activated and initial focus hasn't been given yet, in which case we should\n // fall through to trying to focus the initial focus node, which is what should\n // happen below at this point in the logic\n navAcrossContainers = false;\n }\n\n if (navAcrossContainers) {\n nextNode = findNextNavNode({\n // move FROM the MRU node, not event-related node (which will be the node that is\n // outside the trap causing the focus escape we're trying to fix)\n target: state.mostRecentlyFocusedNode,\n isBackward: config.isKeyBackward(state.recentNavEvent),\n });\n }\n\n if (nextNode) {\n tryFocus(nextNode);\n } else {\n tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());\n }\n }\n\n state.recentNavEvent = undefined; // clear\n };\n\n // Hijack key nav events on the first and last focusable nodes of the trap,\n // in order to prevent focus from escaping. If it escapes for even a\n // moment it can end up scrolling the page and causing confusion so we\n // kind of need to capture the action at the keydown phase.\n const checkKeyNav = function (event, isBackward = false) {\n state.recentNavEvent = event;\n\n const destinationNode = findNextNavNode({ event, isBackward });\n if (destinationNode) {\n if (isTabEvent(event)) {\n // since tab natively moves focus, we wouldn't have a destination node unless we\n // were on the edge of a container and had to move to the next/previous edge, in\n // which case we want to prevent default to keep the browser from moving focus\n // to where it normally would\n event.preventDefault();\n }\n tryFocus(destinationNode);\n }\n // else, let the browser take care of [shift+]tab and move the focus\n };\n\n const checkTabKey = function (event) {\n if (config.isKeyForward(event) || config.isKeyBackward(event)) {\n checkKeyNav(event, config.isKeyBackward(event));\n }\n };\n\n // we use a different event phase for the Escape key to allow canceling the event and checking for this in escapeDeactivates\n const checkEscapeKey = function (event) {\n if (\n isEscapeEvent(event) &&\n valueOrHandler(config.escapeDeactivates, event) !== false\n ) {\n event.preventDefault();\n trap.deactivate();\n }\n };\n\n const checkClick = function (e) {\n const target = getActualTarget(e);\n\n if (findContainerIndex(target, e) >= 0) {\n return;\n }\n\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n return;\n }\n\n if (valueOrHandler(config.allowOutsideClick, e)) {\n return;\n }\n\n e.preventDefault();\n e.stopImmediatePropagation();\n };\n\n //\n // EVENT LISTENERS\n //\n\n /**\n * Adds listeners to the document necessary for trapping focus and attempts to set focus\n * to the configured initial focus node. Does nothing if the trap isn't active.\n * @returns {Promise<void>} Resolved (always) once the initial focus node has been focused.\n * Also resolved if the trap isn't active.\n */\n const addListeners = function () {\n if (!state.active) {\n return Promise.resolve();\n }\n\n // There can be only one listening focus trap at a time\n activeFocusTraps.activateTrap(trapStack, trap);\n\n // Delay ensures that the focused element doesn't capture the event\n // that caused the focus trap activation.\n /** @type {Promise<void>} */\n let promise;\n if (config.delayInitialFocus) {\n // NOTE: Promise constructor callback is called synchronously, which is what we want\n // since we need to capture the timer ID immediately\n promise = new Promise((resolve) => {\n state.delayInitialFocusTimer = delay(function () {\n tryFocus(getInitialFocusNode());\n resolve();\n });\n });\n } else {\n promise = Promise.resolve();\n tryFocus(getInitialFocusNode());\n }\n\n doc.addEventListener('focusin', checkFocusIn, true);\n doc.addEventListener('mousedown', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('touchstart', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('click', checkClick, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkTabKey, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkEscapeKey);\n\n return promise;\n };\n\n /**\n * Traverses up the DOM from each of `containers`, collecting references to\n * the elements that are siblings to `container` or an ancestor of `container`.\n * @param {Array<HTMLElement>} containers\n */\n const collectAdjacentElements = function (containers) {\n // Re-activate all adjacent elements & clear previous collection.\n if (state.active && !state.paused) {\n trap._setSubtreeIsolation(false);\n }\n state.adjacentElements.clear();\n state.alreadySilent.clear();\n\n // Collect all ancestors of all containers to avoid redundant processing.\n const containerAncestors = new Set();\n\n const adjacentElements = new Set();\n\n // Compile all elements adjacent to the focus trap containers & lineage.\n for (const container of containers) {\n containerAncestors.add(container);\n let insideShadowRoot =\n typeof ShadowRoot !== 'undefined' &&\n container.getRootNode() instanceof ShadowRoot;\n let current = container;\n while (current) {\n containerAncestors.add(current);\n\n let parent = current.parentElement;\n let siblings = [];\n if (parent) {\n siblings = parent.children;\n } else if (!parent && insideShadowRoot) {\n siblings = current.getRootNode().children;\n parent = current.getRootNode().host;\n insideShadowRoot =\n typeof ShadowRoot !== 'undefined' &&\n parent.getRootNode() instanceof ShadowRoot;\n }\n\n // Add all the children, we'll remove container lineage later.\n for (const child of siblings) {\n adjacentElements.add(child);\n }\n\n current = parent;\n }\n }\n\n // Multi-container traps may overlap.\n // Remove elements within container lineages.\n containerAncestors.forEach((el) => {\n adjacentElements.delete(el);\n });\n\n state.adjacentElements = adjacentElements;\n };\n\n const removeListeners = function () {\n if (!state.active) {\n return;\n }\n\n doc.removeEventListener('focusin', checkFocusIn, true);\n doc.removeEventListener('mousedown', checkPointerDown, true);\n doc.removeEventListener('touchstart', checkPointerDown, true);\n doc.removeEventListener('click', checkClick, true);\n doc.removeEventListener('keydown', checkTabKey, true);\n doc.removeEventListener('keydown', checkEscapeKey);\n\n return trap;\n };\n\n //\n // MUTATION OBSERVER\n //\n\n const checkDomRemoval = function (mutations) {\n const isFocusedNodeRemoved = mutations.some(function (mutation) {\n const removedNodes = Array.from(mutation.removedNodes);\n return removedNodes.some(function (node) {\n return node === state.mostRecentlyFocusedNode;\n });\n });\n\n // If the currently focused is removed then browsers will move focus to the\n // <body> element. If this happens, try to move focus back into the trap.\n if (isFocusedNodeRemoved) {\n tryFocus(getInitialFocusNode());\n }\n };\n\n // Use MutationObserver - if supported - to detect if focused node is removed\n // from the DOM.\n const mutationObserver =\n typeof window !== 'undefined' && 'MutationObserver' in window\n ? new MutationObserver(checkDomRemoval)\n : undefined;\n\n const updateObservedNodes = function () {\n if (!mutationObserver) {\n return;\n }\n\n mutationObserver.disconnect();\n if (state.active && !state.paused) {\n state.containers.map(function (container) {\n mutationObserver.observe(container, {\n subtree: true,\n childList: true,\n });\n });\n }\n };\n\n //\n // TRAP DEFINITION\n //\n\n trap = {\n get active() {\n return state.active;\n },\n\n get paused() {\n return state.paused;\n },\n\n activate(activateOptions) {\n if (state.active) {\n return this;\n }\n\n const onActivate = getOption(activateOptions, 'onActivate');\n const onPostActivate = getOption(activateOptions, 'onPostActivate');\n const checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');\n\n // If a currently-active trap is isolating its subtree, we need to remove\n // that isolation to allow the new trap to find tabbable nodes.\n const preexistingTrap = activeFocusTraps.getActiveTrap(trapStack);\n let revertState = false;\n if (preexistingTrap && !preexistingTrap.paused) {\n // [#1729] method MAY not exist if using `trapStack` option to share stack with older\n // versions of Focus-trap in the same DOM so use optional chaining here just in case\n // since this is a trap we may not have created from this instance of the library\n preexistingTrap._setSubtreeIsolation?.(false);\n revertState = true;\n }\n\n try {\n if (!checkCanFocusTrap) {\n updateTabbableNodes();\n }\n\n state.active = true;\n state.paused = false;\n state.nodeFocusedBeforeActivation = getActiveElement(doc);\n\n onActivate?.();\n\n const finishActivation = async () => {\n if (checkCanFocusTrap) {\n updateTabbableNodes();\n }\n\n // NOTE: wait for initial focus node to get focused before we potentially isolate\n // the subtrees with aria-hidden while focus is still in some other subtree and\n // not yet in the trap, resulting in some browsers (e.g. Chrome) logging to the\n // console that they, \"Blocked aria-hidden on an element because its descendant\n // retained focus...\"\n await addListeners();\n\n trap._setSubtreeIsolation(true);\n updateObservedNodes();\n onPostActivate?.();\n };\n\n if (checkCanFocusTrap) {\n checkCanFocusTrap(state.containers.concat()).then(\n finishActivation,\n finishActivation\n );\n return this;\n }\n\n finishActivation();\n } catch (error) {\n // If our activation throws an exception and the stack hasn't changed,\n // we need to re-enable the prior trap's subtree isolation.\n if (\n preexistingTrap === activeFocusTraps.getActiveTrap(trapStack) &&\n revertState\n ) {\n // [#1729] method MAY not exist if using `trapStack` option to share stack with older\n // versions of Focus-trap in the same DOM so use optional chaining here just in case\n // since this is a trap we may not have created from this instance of the library\n preexistingTrap._setSubtreeIsolation?.(true);\n }\n throw error;\n }\n return this;\n },\n\n deactivate(deactivateOptions) {\n if (!state.active) {\n return this;\n }\n\n const options = {\n onDeactivate: config.onDeactivate,\n onPostDeactivate: config.onPostDeactivate,\n checkCanReturnFocus: config.checkCanReturnFocus,\n ...deactivateOptions,\n };\n\n clearTimeout(state.delayInitialFocusTimer); // noop if undefined\n state.delayInitialFocusTimer = undefined;\n\n // Prior to removing this trap from the trapStack, we need to remove any applications of `inert`.\n // This allows the next trap down to update its tabbable nodes properly.\n //\n // If this trap is not top of the stack, don't change any current isolation.\n if (!state.paused) {\n trap._setSubtreeIsolation(false);\n }\n state.alreadySilent.clear();\n removeListeners();\n state.active = false;\n state.paused = false;\n updateObservedNodes();\n\n activeFocusTraps.deactivateTrap(trapStack, trap);\n\n const onDeactivate = getOption(options, 'onDeactivate');\n const onPostDeactivate = getOption(options, 'onPostDeactivate');\n const checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');\n const returnFocus = getOption(\n options,\n 'returnFocus',\n 'returnFocusOnDeactivate'\n );\n\n onDeactivate?.();\n\n const finishDeactivation = () => {\n delay(() => {\n if (returnFocus) {\n tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));\n }\n onPostDeactivate?.();\n });\n };\n\n if (returnFocus && checkCanReturnFocus) {\n checkCanReturnFocus(\n getReturnFocusNode(state.nodeFocusedBeforeActivation)\n ).then(finishDeactivation, finishDeactivation);\n return this;\n }\n\n finishDeactivation();\n return this;\n },\n\n pause(pauseOptions) {\n if (!state.active) {\n return this;\n }\n\n state.manuallyPaused = true;\n\n return this._setPausedState(true, pauseOptions);\n },\n\n unpause(unpauseOptions) {\n if (!state.active) {\n return this;\n }\n\n state.manuallyPaused = false;\n\n if (trapStack[trapStack.length - 1] !== this) {\n return this;\n }\n\n return this._setPausedState(false, unpauseOptions);\n },\n\n updateContainerElements(containerElements) {\n const elementsAsArray = [].concat(containerElements).filter(Boolean);\n\n state.containers = elementsAsArray.map((element) =>\n typeof element === 'string' ? doc.querySelector(element) : element\n );\n\n if (config.isolateSubtrees) {\n collectAdjacentElements(state.containers);\n }\n\n if (state.active) {\n updateTabbableNodes();\n\n if (!state.paused) {\n trap._setSubtreeIsolation(true);\n }\n }\n\n updateObservedNodes();\n\n return this;\n },\n };\n\n Object.defineProperties(trap, {\n _isManuallyPaused: {\n value() {\n return state.manuallyPaused;\n },\n },\n _setPausedState: {\n value(paused, options) {\n if (state.paused === paused) {\n return this;\n }\n\n state.paused = paused;\n\n if (paused) {\n const onPause = getOption(options, 'onPause');\n const onPostPause = getOption(options, 'onPostPause');\n onPause?.();\n\n removeListeners();\n trap._setSubtreeIsolation(false);\n updateObservedNodes();\n\n onPostPause?.();\n } else {\n const onUnpause = getOption(options, 'onUnpause');\n const onPostUnpause = getOption(options, 'onPostUnpause');\n\n onUnpause?.();\n\n const finishUnpause = async () => {\n updateTabbableNodes();\n\n // NOTE: wait for initial focus node to get focused before we potentially isolate\n // the subtrees with aria-hidden while focus is still in some other subtree and\n // not yet in the trap, resulting in some browsers (e.g. Chrome) logging to the\n // console that they, \"Blocked aria-hidden on an element because its descendant\n // retained focus...\"\n await addListeners();\n\n trap._setSubtreeIsolation(true);\n updateObservedNodes();\n onPostUnpause?.();\n };\n\n finishUnpause();\n }\n\n return this;\n },\n },\n _setSubtreeIsolation: {\n value(isEnabled) {\n if (config.isolateSubtrees) {\n state.adjacentElements.forEach((el) => {\n if (isEnabled) {\n switch (config.isolateSubtrees) {\n case 'aria-hidden':\n // check both attribute and property to ensure initial state is captured\n // correctly across different browsers and test environments (like JSDOM)\n if (\n el.ariaHidden === 'true' ||\n el.getAttribute('aria-hidden')?.toLowerCase() === 'true'\n ) {\n state.alreadySilent.add(el);\n }\n\n el.setAttribute('aria-hidden', 'true');\n break;\n\n default:\n // check both attribute and property to ensure initial state is captured\n // correctly across different browsers and test environments (like JSDOM)\n if (el.inert || el.hasAttribute('inert')) {\n state.alreadySilent.add(el);\n }\n el.setAttribute('inert', true);\n break;\n }\n } else {\n if (state.alreadySilent.has(el)) {\n // do nothing\n } else {\n switch (config.isolateSubtrees) {\n case 'aria-hidden':\n el.removeAttribute('aria-hidden');\n break;\n\n default:\n el.removeAttribute('inert');\n break;\n }\n }\n }\n });\n }\n },\n },\n });\n\n // initialize container elements\n trap.updateContainerElements(elements);\n\n return trap;\n};\n\nexport { createFocusTrap };\n"],"names":["activeFocusTraps","getActiveTrap","trapStack","length","activateTrap","trap","pauseTrap","trapIndex","indexOf","splice","push","deactivateTrap","unpauseTrap","activeTrap","_setPausedState","_isManuallyPaused","isTabEvent","e","key","keyCode","isKeyForward","shiftKey","isKeyBackward","delay","fn","setTimeout","valueOrHandler","value","_len","arguments","params","Array","_key","apply","getActualTarget","event","target","shadowRoot","composedPath","internalTrapStack","elements","userOptions","doc","document","config","_objectSpread","returnFocusOnDeactivate","escapeDeactivates","delayInitialFocus","isolateSubtrees","state","containers","containerGroups","tabbableGroups","adjacentElements","Set","alreadySilent","nodeFocusedBeforeActivation","mostRecentlyFocusedNode","active","paused","manuallyPaused","delayInitialFocusTimer","undefined","recentNavEvent","getOption","configOverrideOptions","optionName","configOptionName","findContainerIndex","element","findIndex","_ref","container","tabbableNodes","contains","includes","find","node","getNodeForOption","_ref2","_ref2$hasFallback","hasFallback","_ref2$params","optionValue","_toConsumableArray","Error","concat","querySelector","err","message","getInitialFocusNode","isFocusable","tabbableOptions","activeElement","firstTabbableGroup","firstTabbableNode","updateTabbableNodes","map","tabbable","focusableNodes","focusable","lastTabbableNode","firstDomTabbableNode","isTabbable","lastDomTabbableNode","slice","reverse","posTabIndexesFound","getTabIndex","nextTabbableNode","forward","nodeIdx","el","filter","group","g","getActiveElement","tryFocus","focus","preventScroll","tagName","toLowerCase","select","isSelectableInput","getReturnFocusNode","previousActiveElement","findNextNavNode","_ref3","_ref3$isBackward","isBackward","destinationNode","containerIndex","containerGroup","startOfGroupIndex","_ref4","destinationGroupIndex","destinationGroup","lastOfGroupIndex","_ref5","checkPointerDown","clickOutsideDeactivates","deactivate","returnFocus","allowOutsideClick","preventDefault","checkFocusIn","targetContained","Document","nextNode","stopImmediatePropagation","navAcrossContainers","mruContainerIdx","mruTabIdx","some","n","checkTabKey","checkKeyNav","checkEscapeKey","checkClick","addListeners","promise","Promise","resolve","addEventListener","capture","passive","removeListeners","removeEventListener","mutationObserver","window","MutationObserver","mutations","mutation","from","removedNodes","updateObservedNodes","disconnect","observe","subtree","childList","activate","activateOptions","this","_preexistingTrap$_set","onActivate","onPostActivate","checkCanFocusTrap","preexistingTrap","revertState","_setSubtreeIsolation","call","finishActivation","_ref6","_asyncToGenerator","_regenerator","m","_callee","w","_context","a","then","error","_preexistingTrap$_set2","deactivateOptions","options","onDeactivate","onPostDeactivate","checkCanReturnFocus","clearTimeout","clear","finishDeactivation","pause","pauseOptions","unpause","unpauseOptions","updateContainerElements","containerElements","elementsAsArray","Boolean","_step","containerAncestors","_iterator","_createForOfIteratorHelper","s","done","add","insideShadowRoot","ShadowRoot","getRootNode","current","parent","parentElement","siblings","children","host","_step2","_iterator2","child","f","forEach","collectAdjacentElements","Object","defineProperties","onPause","onPostPause","onUnpause","onPostUnpause","finishUnpause","_ref7","_callee2","_context2","isEnabled","_el$getAttribute","ariaHidden","getAttribute","setAttribute","inert","hasAttribute","has","removeAttribute"],"mappings":";;;;;;wnFAQA,IAAMA,EAAmB,CAEvBC,cAAa,SAACC,GACZ,OAAIA,aAAS,EAATA,EAAWC,QAAS,EACfD,EAAUA,EAAUC,OAAS,GAE/B,IACT,EAGAC,sBAAaF,EAAWG,GAGlBA,IAFeL,EAAiBC,cAAcC,IAGhDF,EAAiBM,UAAUJ,GAG7B,IAAMK,EAAYL,EAAUM,QAAQH,IAClB,IAAdE,GAIFL,EAAUO,OAAOF,EAAW,GAH5BL,EAAUQ,KAAKL,EAMnB,EAGAM,wBAAeT,EAAWG,GACxB,IAAME,EAAYL,EAAUM,QAAQH,IAClB,IAAdE,GACFL,EAAUO,OAAOF,EAAW,GAG9BP,EAAiBY,YAAYV,EAC/B,EAGAI,UAA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aAAa,SAAS,QAI7B,GAAI9M,EAAMM,cAAc2M,IAAIlJ,SAG1B,GACO,gBADCrE,EAAOK,gBAEXgE,EAAGmJ,gBAAgB,oBAInBnJ,EAAGmJ,gBAAgB,QAK7B,GAEJ,KAKJ/P,EAAKmN,wBAAwBhL,GAEtBnC,CACT"}
1
+ {"version":3,"file":"focus-trap.umd.min.js","sources":["../index.js"],"sourcesContent":["import {\n tabbable,\n focusable,\n isFocusable,\n isTabbable,\n getTabIndex,\n} from 'tabbable';\n\nconst activeFocusTraps = {\n // Returns the trap from the top of the stack.\n getActiveTrap(trapStack) {\n if (trapStack?.length > 0) {\n return trapStack[trapStack.length - 1];\n }\n return null;\n },\n\n // Pauses the currently active trap, then adds a new trap to the stack.\n activateTrap(trapStack, trap) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n\n if (trap !== activeTrap) {\n activeFocusTraps.pauseTrap(trapStack);\n }\n\n const trapIndex = trapStack.indexOf(trap);\n if (trapIndex === -1) {\n trapStack.push(trap);\n } else {\n // move this existing trap to the front of the queue\n trapStack.splice(trapIndex, 1);\n trapStack.push(trap);\n }\n },\n\n // Removes the trap from the top of the stack, then unpauses the next trap down.\n deactivateTrap(trapStack, trap) {\n const trapIndex = trapStack.indexOf(trap);\n if (trapIndex !== -1) {\n trapStack.splice(trapIndex, 1);\n }\n\n activeFocusTraps.unpauseTrap(trapStack);\n },\n\n // Pauses the trap at the top of the stack.\n pauseTrap(trapStack) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n activeTrap?._setPausedState(true);\n },\n\n // Unpauses the trap at the top of the stack.\n unpauseTrap(trapStack) {\n const activeTrap = activeFocusTraps.getActiveTrap(trapStack);\n\n if (activeTrap && !activeTrap._isManuallyPaused()) {\n activeTrap._setPausedState(false);\n }\n },\n};\n\nconst isSelectableInput = function (node) {\n return (\n node.tagName &&\n node.tagName.toLowerCase() === 'input' &&\n typeof node.select === 'function'\n );\n};\n\nconst isEscapeEvent = function (e) {\n return e?.key === 'Escape' || e?.key === 'Esc' || e?.keyCode === 27;\n};\n\nconst isTabEvent = function (e) {\n return e?.key === 'Tab' || e?.keyCode === 9;\n};\n\n// checks for TAB by default\nconst isKeyForward = function (e) {\n return isTabEvent(e) && !e.shiftKey;\n};\n\n// checks for SHIFT+TAB by default\nconst isKeyBackward = function (e) {\n return isTabEvent(e) && e.shiftKey;\n};\n\nconst delay = function (fn) {\n return setTimeout(fn, 0);\n};\n\n/**\n * Get an option's value when it could be a plain value, or a handler that provides\n * the value.\n * @param {*} value Option's value to check.\n * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.\n * @returns {*} The `value`, or the handler's returned value.\n */\nconst valueOrHandler = function (value, ...params) {\n return typeof value === 'function' ? value(...params) : value;\n};\n\nconst getActualTarget = function (event) {\n // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the\n // shadow host. However, event.target.composedPath() will be an array of\n // nodes \"clicked\" from inner-most (the actual element inside the shadow) to\n // outer-most (the host HTML document). If we have access to composedPath(),\n // then use its first element; otherwise, fall back to event.target (and\n // this only works for an _open_ shadow DOM; otherwise,\n // composedPath()[0] === event.target always).\n return event.target.shadowRoot && typeof event.composedPath === 'function'\n ? event.composedPath()[0]\n : event.target;\n};\n\n// NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this\n// current instance use the same stack if `userOptions.trapStack` isn't specified\nconst internalTrapStack = [];\n\nconst createFocusTrap = function (elements, userOptions) {\n // SSR: a live trap shouldn't be created in this type of environment so this\n // should be safe code to execute if the `document` option isn't specified\n const doc = userOptions?.document || document;\n\n const trapStack = userOptions?.trapStack || internalTrapStack;\n\n const config = {\n returnFocusOnDeactivate: true,\n escapeDeactivates: true,\n delayInitialFocus: true,\n isolateSubtrees: false,\n isKeyForward,\n isKeyBackward,\n ...userOptions,\n };\n\n const state = {\n // containers given to createFocusTrap()\n /** @type {Array<HTMLElement>} */\n containers: [],\n\n // list of objects identifying tabbable nodes in `containers` in the trap\n // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap\n // is active, but the trap should never get to a state where there isn't at least one group\n // with at least one tabbable node in it (that would lead to an error condition that would\n // result in an error being thrown)\n /** @type {Array<{\n * container: HTMLElement,\n * tabbableNodes: Array<HTMLElement>, // empty if none\n * focusableNodes: Array<HTMLElement>, // empty if none\n * posTabIndexesFound: boolean,\n * firstTabbableNode: HTMLElement|undefined,\n * lastTabbableNode: HTMLElement|undefined,\n * firstDomTabbableNode: HTMLElement|undefined,\n * lastDomTabbableNode: HTMLElement|undefined,\n * nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined\n * }>}\n */\n containerGroups: [], // same order/length as `containers` list\n\n // references to objects in `containerGroups`, but only those that actually have\n // tabbable nodes in them\n // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__\n // the same length\n tabbableGroups: [],\n\n // references to nodes that are siblings to the ancestors of this trap's containers.\n /** @type {Set<HTMLElement>} */\n adjacentElements: new Set(),\n\n // references to nodes that were inert or aria-hidden before the trap was activated.\n /** @type {Set<HTMLElement>} */\n alreadySilent: new Set(),\n nodeFocusedBeforeActivation: null,\n mostRecentlyFocusedNode: null,\n active: false,\n paused: false,\n manuallyPaused: false,\n\n // timer ID for when delayInitialFocus is true and initial focus in this trap\n // has been delayed during activation\n delayInitialFocusTimer: undefined,\n\n // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any\n recentNavEvent: undefined,\n };\n\n let trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later\n\n /**\n * Gets a configuration option value.\n * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,\n * value will be taken from this object. Otherwise, value will be taken from base configuration.\n * @param {string} optionName Name of the option whose value is sought.\n * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`\n * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.\n */\n const getOption = (configOverrideOptions, optionName, configOptionName) => {\n return configOverrideOptions &&\n configOverrideOptions[optionName] !== undefined\n ? configOverrideOptions[optionName]\n : config[configOptionName || optionName];\n };\n\n /**\n * Finds the index of the container that contains the element.\n * @param {HTMLElement} element\n * @param {Event} [event] If available, and `element` isn't directly found in any container,\n * the event's composed path is used to see if includes any known trap containers in the\n * case where the element is inside a Shadow DOM.\n * @returns {number} Index of the container in either `state.containers` or\n * `state.containerGroups` (the order/length of these lists are the same); -1\n * if the element isn't found.\n */\n const findContainerIndex = function (element, event) {\n const composedPath =\n typeof event?.composedPath === 'function'\n ? event.composedPath()\n : undefined;\n // NOTE: search `containerGroups` because it's possible a group contains no tabbable\n // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)\n // and we still need to find the element in there\n return state.containerGroups.findIndex(\n ({ container, tabbableNodes }) =>\n container.contains(element) ||\n // fall back to explicit tabbable search which will take into consideration any\n // web components if the `tabbableOptions.getShadowRoot` option was used for\n // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't\n // look inside web components even if open)\n composedPath?.includes(container) ||\n tabbableNodes.find((node) => node === element)\n );\n };\n\n /**\n * Gets the node for the given option, which is expected to be an option that\n * can be either a DOM node, a string that is a selector to get a node, `false`\n * (if a node is explicitly NOT given), or a function that returns any of these\n * values.\n * @param {string} optionName\n * @param {Object} options\n * @param {boolean} [options.hasFallback] True if the option could be a selector string\n * and the option allows for a fallback scenario in the case where the selector is\n * valid but does not match a node (i.e. the queried node doesn't exist in the DOM).\n * @param {Array} [options.params] Params to pass to the option if it's a function.\n * @returns {undefined | null | false | HTMLElement | SVGElement} Returns\n * `undefined` if the option is not specified; `null` if the option didn't resolve\n * to a node but `options.hasFallback=true`, `false` if the option resolved to `false`\n * (node explicitly not given); otherwise, the resolved DOM node.\n * @throws {Error} If the option is set, not `false`, and is not, or does not\n * resolve to a node, unless the option is a selector string and `options.hasFallback=true`.\n */\n const getNodeForOption = function (\n optionName,\n { hasFallback = false, params = [] } = {}\n ) {\n let optionValue = config[optionName];\n\n if (typeof optionValue === 'function') {\n optionValue = optionValue(...params);\n }\n\n if (optionValue === true) {\n optionValue = undefined; // use default value\n }\n\n if (!optionValue) {\n if (optionValue === undefined || optionValue === false) {\n return optionValue;\n }\n // else, empty string (invalid), null (invalid), 0 (invalid)\n\n throw new Error(\n `\\`${optionName}\\` was specified but was not a node, or did not return a node`\n );\n }\n\n let node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point\n\n if (typeof optionValue === 'string') {\n try {\n node = doc.querySelector(optionValue); // resolve to node, or null if fails\n } catch (err) {\n throw new Error(\n `\\`${optionName}\\` appears to be an invalid selector; error=\"${err.message}\"`\n );\n }\n\n if (!node) {\n if (!hasFallback) {\n throw new Error(\n `\\`${optionName}\\` as selector refers to no known node`\n );\n }\n // else, `node` MUST be `null` because that's what `Document.querySelector()` returns\n // if the selector is valid but doesn't match anything\n }\n }\n\n return node;\n };\n\n const getInitialFocusNode = function () {\n let node = getNodeForOption('initialFocus', { hasFallback: true });\n\n // false explicitly indicates we want no initialFocus at all\n if (node === false) {\n return false;\n }\n\n if (\n node === undefined ||\n (node && !isFocusable(node, config.tabbableOptions))\n ) {\n // option not specified nor focusable: use fallback options\n if (findContainerIndex(doc.activeElement) >= 0) {\n node = doc.activeElement;\n } else {\n const firstTabbableGroup = state.tabbableGroups[0];\n const firstTabbableNode =\n firstTabbableGroup && firstTabbableGroup.firstTabbableNode;\n\n // NOTE: `fallbackFocus` option function cannot return `false` (not supported)\n node = firstTabbableNode || getNodeForOption('fallbackFocus');\n }\n } else if (node === null) {\n // option is a VALID selector string that doesn't yield a node: use the `fallbackFocus`\n // option instead of the default behavior when the option isn't specified at all\n node = getNodeForOption('fallbackFocus');\n }\n\n if (!node) {\n throw new Error(\n 'Your focus-trap needs to have at least one focusable element'\n );\n }\n\n return node;\n };\n\n const updateTabbableNodes = function () {\n state.containerGroups = state.containers.map((container) => {\n const tabbableNodes = tabbable(container, config.tabbableOptions);\n\n // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes\n // are a superset of tabbable nodes since nodes with negative `tabindex` attributes\n // are focusable but not tabbable\n const focusableNodes = focusable(container, config.tabbableOptions);\n\n const firstTabbableNode =\n tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;\n const lastTabbableNode =\n tabbableNodes.length > 0\n ? tabbableNodes[tabbableNodes.length - 1]\n : undefined;\n\n const firstDomTabbableNode = focusableNodes.find((node) =>\n isTabbable(node)\n );\n const lastDomTabbableNode = focusableNodes\n .slice()\n .reverse()\n .find((node) => isTabbable(node));\n\n const posTabIndexesFound = !!tabbableNodes.find(\n (node) => getTabIndex(node) > 0\n );\n\n return {\n container,\n tabbableNodes,\n focusableNodes,\n\n /** True if at least one node with positive `tabindex` was found in this container. */\n posTabIndexesFound,\n\n /** First tabbable node in container, __tabindex__ order; `undefined` if none. */\n firstTabbableNode,\n /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */\n lastTabbableNode,\n\n // NOTE: DOM order is NOT NECESSARILY \"document position\" order, but figuring that out\n // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n // because that API doesn't work with Shadow DOM as well as it should (@see\n // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,\n // to address an edge case related to positive tabindex support, this seems like a much easier,\n // \"close enough most of the time\" alternative for positive tabindexes which should generally\n // be avoided anyway...\n /** First tabbable node in container, __DOM__ order; `undefined` if none. */\n firstDomTabbableNode,\n /** Last tabbable node in container, __DOM__ order; `undefined` if none. */\n lastDomTabbableNode,\n\n /**\n * Finds the __tabbable__ node that follows the given node in the specified direction,\n * in this container, if any.\n * @param {HTMLElement} node\n * @param {boolean} [forward] True if going in forward tab order; false if going\n * in reverse.\n * @returns {HTMLElement|undefined} The next tabbable node, if any.\n */\n nextTabbableNode(node, forward = true) {\n const nodeIdx = tabbableNodes.indexOf(node);\n if (nodeIdx < 0) {\n // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):\n // since `node` should at least have been focusable, we assume that's the case and mimic\n // what browsers do, which is set focus to the next node in __document position order__,\n // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE\n // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to\n // basic DOM order\n if (forward) {\n return focusableNodes\n .slice(focusableNodes.indexOf(node) + 1)\n .find((el) => isTabbable(el));\n }\n\n return focusableNodes\n .slice(0, focusableNodes.indexOf(node))\n .reverse()\n .find((el) => isTabbable(el));\n }\n\n return tabbableNodes[nodeIdx + (forward ? 1 : -1)];\n },\n };\n });\n\n state.tabbableGroups = state.containerGroups.filter(\n (group) => group.tabbableNodes.length > 0\n );\n\n // throw if no groups have tabbable nodes and we don't have a fallback focus node either\n if (\n state.tabbableGroups.length <= 0 &&\n !getNodeForOption('fallbackFocus') // returning false not supported for this option\n ) {\n throw new Error(\n 'Your focus-trap must have at least one container with at least one tabbable node in it at all times'\n );\n }\n\n // NOTE: Positive tabindexes are only properly supported in single-container traps because\n // doing it across multiple containers where tabindexes could be all over the place\n // would require Tabbable to support multiple containers, would require additional\n // specialized Shadow DOM support, and would require Tabbable's multi-container support\n // to look at those containers in document position order rather than user-provided\n // order (as they are treated in Focus-trap, for legacy reasons). See discussion on\n // https://github.com/focus-trap/focus-trap/issues/375 for more details.\n if (\n state.containerGroups.find((g) => g.posTabIndexesFound) &&\n state.containerGroups.length > 1\n ) {\n throw new Error(\n \"At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.\"\n );\n }\n };\n\n /**\n * Gets the current activeElement. If it's a web-component and has open shadow-root\n * it will recursively search inside shadow roots for the \"true\" activeElement.\n *\n * @param {Document | ShadowRoot} el\n *\n * @returns {HTMLElement} The element that currently has the focus\n **/\n const getActiveElement = function (el) {\n const activeElement = el.activeElement;\n\n if (!activeElement) {\n return;\n }\n\n if (\n activeElement.shadowRoot &&\n activeElement.shadowRoot.activeElement !== null\n ) {\n return getActiveElement(activeElement.shadowRoot);\n }\n\n return activeElement;\n };\n\n const tryFocus = function (node) {\n if (node === false) {\n return;\n }\n\n if (node === getActiveElement(document)) {\n return;\n }\n\n if (!node || !node.focus) {\n tryFocus(getInitialFocusNode());\n return;\n }\n\n node.focus({ preventScroll: !!config.preventScroll });\n // NOTE: focus() API does not trigger focusIn event so set MRU node manually\n state.mostRecentlyFocusedNode = node;\n\n if (isSelectableInput(node)) {\n node.select();\n }\n };\n\n const getReturnFocusNode = function (previousActiveElement) {\n const node = getNodeForOption('setReturnFocus', {\n params: [previousActiveElement],\n });\n return node ? node : node === false ? false : previousActiveElement;\n };\n\n /**\n * Finds the next node (in either direction) where focus should move according to a\n * keyboard focus-in event.\n * @param {Object} params\n * @param {Node} [params.target] Known target __from which__ to navigate, if any.\n * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event\n * will be used to determine the `target`). Ignored if `target` is specified.\n * @param {boolean} [params.isBackward] True if focus should move backward.\n * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be\n * determined given the current state of the trap.\n */\n const findNextNavNode = function ({ target, event, isBackward = false }) {\n target = target || getActualTarget(event);\n updateTabbableNodes();\n\n let destinationNode = null;\n\n if (state.tabbableGroups.length > 0) {\n // make sure the target is actually contained in a group\n // NOTE: the target may also be the container itself if it's focusable\n // with tabIndex='-1' and was given initial focus\n const containerIndex = findContainerIndex(target, event);\n const containerGroup =\n containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;\n\n if (containerIndex < 0) {\n // target not found in any group: quite possible focus has escaped the trap,\n // so bring it back into...\n if (isBackward) {\n // ...the last node in the last group\n destinationNode =\n state.tabbableGroups[state.tabbableGroups.length - 1]\n .lastTabbableNode;\n } else {\n // ...the first node in the first group\n destinationNode = state.tabbableGroups[0].firstTabbableNode;\n }\n } else if (isBackward) {\n // REVERSE\n\n // is the target the first tabbable node in a group?\n let startOfGroupIndex = state.tabbableGroups.findIndex(\n ({ firstTabbableNode }) => target === firstTabbableNode\n );\n\n if (\n startOfGroupIndex < 0 &&\n (containerGroup.container === target ||\n (isFocusable(target, config.tabbableOptions) &&\n !isTabbable(target, config.tabbableOptions) &&\n !containerGroup.nextTabbableNode(target, false)))\n ) {\n // an exception case where the target is either the container itself, or\n // a non-tabbable node that was given focus (i.e. tabindex is negative\n // and user clicked on it or node was programmatically given focus)\n // and is not followed by any other tabbable node, in which\n // case, we should handle shift+tab as if focus were on the container's\n // first tabbable node, and go to the last tabbable node of the LAST group\n startOfGroupIndex = containerIndex;\n }\n\n if (startOfGroupIndex >= 0) {\n // YES: then shift+tab should go to the last tabbable node in the\n // previous group (and wrap around to the last tabbable node of\n // the LAST group if it's the first tabbable node of the FIRST group)\n const destinationGroupIndex =\n startOfGroupIndex === 0\n ? state.tabbableGroups.length - 1\n : startOfGroupIndex - 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n\n destinationNode =\n getTabIndex(target) >= 0\n ? destinationGroup.lastTabbableNode\n : destinationGroup.lastDomTabbableNode;\n } else if (!isTabEvent(event)) {\n // user must have customized the nav keys so we have to move focus manually _within_\n // the active group: do this based on the order determined by tabbable()\n destinationNode = containerGroup.nextTabbableNode(target, false);\n }\n } else {\n // FORWARD\n\n // is the target the last tabbable node in a group?\n let lastOfGroupIndex = state.tabbableGroups.findIndex(\n ({ lastTabbableNode }) => target === lastTabbableNode\n );\n\n if (\n lastOfGroupIndex < 0 &&\n (containerGroup.container === target ||\n (isFocusable(target, config.tabbableOptions) &&\n !isTabbable(target, config.tabbableOptions) &&\n !containerGroup.nextTabbableNode(target)))\n ) {\n // an exception case where the target is the container itself, or\n // a non-tabbable node that was given focus (i.e. tabindex is negative\n // and user clicked on it or node was programmatically given focus)\n // and is not followed by any other tabbable node, in which\n // case, we should handle tab as if focus were on the container's\n // last tabbable node, and go to the first tabbable node of the FIRST group\n lastOfGroupIndex = containerIndex;\n }\n\n if (lastOfGroupIndex >= 0) {\n // YES: then tab should go to the first tabbable node in the next\n // group (and wrap around to the first tabbable node of the FIRST\n // group if it's the last tabbable node of the LAST group)\n const destinationGroupIndex =\n lastOfGroupIndex === state.tabbableGroups.length - 1\n ? 0\n : lastOfGroupIndex + 1;\n\n const destinationGroup = state.tabbableGroups[destinationGroupIndex];\n\n destinationNode =\n getTabIndex(target) >= 0\n ? destinationGroup.firstTabbableNode\n : destinationGroup.firstDomTabbableNode;\n } else if (!isTabEvent(event)) {\n // user must have customized the nav keys so we have to move focus manually _within_\n // the active group: do this based on the order determined by tabbable()\n destinationNode = containerGroup.nextTabbableNode(target);\n }\n }\n } else {\n // no groups available\n // NOTE: the fallbackFocus option does not support returning false to opt-out\n destinationNode = getNodeForOption('fallbackFocus');\n }\n\n return destinationNode;\n };\n\n // This needs to be done on mousedown and touchstart instead of click\n // so that it precedes the focus event.\n const checkPointerDown = function (e) {\n const target = getActualTarget(e);\n\n if (findContainerIndex(target, e) >= 0) {\n // allow the click since it occurred inside the trap\n return;\n }\n\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n // immediately deactivate the trap\n trap.deactivate({\n // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,\n // which will result in the outside click setting focus to the node\n // that was clicked (and if not focusable, to \"nothing\"); by setting\n // `returnFocus: true`, we'll attempt to re-focus the node originally-focused\n // on activation (or the configured `setReturnFocus` node), whether the\n // outside click was on a focusable node or not\n returnFocus: config.returnFocusOnDeactivate,\n });\n return;\n }\n\n // This is needed for mobile devices.\n // (If we'll only let `click` events through,\n // then on mobile they will be blocked anyways if `touchstart` is blocked.)\n if (valueOrHandler(config.allowOutsideClick, e)) {\n // allow the click outside the trap to take place\n return;\n }\n\n // otherwise, prevent the click\n e.preventDefault();\n };\n\n // In case focus escapes the trap for some strange reason, pull it back in.\n // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected\n // scrolling if the node that got focused was out of view; there's nothing we can do to\n // prevent that from happening by the time we discover that focus escaped\n const checkFocusIn = function (event) {\n const target = getActualTarget(event);\n const targetContained = findContainerIndex(target, event) >= 0;\n\n // In Firefox when you Tab out of an iframe the Document is briefly focused.\n if (targetContained || target instanceof Document) {\n if (targetContained) {\n state.mostRecentlyFocusedNode = target;\n }\n } else {\n // escaped! pull it back in to where it just left\n event.stopImmediatePropagation();\n\n // focus will escape if the MRU node had a positive tab index and user tried to nav forward;\n // it will also escape if the MRU node had a 0 tab index and user tried to nav backward\n // toward a node with a positive tab index\n let nextNode; // next node to focus, if we find one\n let navAcrossContainers = true;\n if (state.mostRecentlyFocusedNode) {\n if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {\n // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...\n const mruContainerIdx = findContainerIndex(\n state.mostRecentlyFocusedNode\n );\n // there MAY not be any tabbable nodes in the container if there are at least 2 containers\n // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container\n // with at least one tabbable node in order to function, so this could be the other container\n // with nothing tabbable in it)\n const { tabbableNodes } = state.containerGroups[mruContainerIdx];\n if (tabbableNodes.length > 0) {\n // MRU tab index MAY not be found if the MRU node is focusable but not tabbable\n const mruTabIdx = tabbableNodes.findIndex(\n (node) => node === state.mostRecentlyFocusedNode\n );\n if (mruTabIdx >= 0) {\n if (config.isKeyForward(state.recentNavEvent)) {\n if (mruTabIdx + 1 < tabbableNodes.length) {\n nextNode = tabbableNodes[mruTabIdx + 1];\n navAcrossContainers = false;\n }\n // else, don't wrap within the container as focus should move to next/previous\n // container\n } else {\n if (mruTabIdx - 1 >= 0) {\n nextNode = tabbableNodes[mruTabIdx - 1];\n navAcrossContainers = false;\n }\n // else, don't wrap within the container as focus should move to next/previous\n // container\n }\n // else, don't find in container order without considering direction too\n }\n }\n // else, no tabbable nodes in that container (which means we must have at least one other\n // container with at least one tabbable node in it, otherwise focus-trap would've thrown\n // an error the last time updateTabbableNodes() was run): find next node among all known\n // containers\n } else {\n // check to see if there's at least one tabbable node with a positive tab index inside\n // the trap because focus seems to escape when navigating backward from a tabbable node\n // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with\n // the greatest positive tab index like it should)\n if (\n !state.containerGroups.some((g) =>\n g.tabbableNodes.some((n) => getTabIndex(n) > 0)\n )\n ) {\n // no containers with tabbable nodes with positive tab indexes which means the focus\n // escaped for some other reason and we should just execute the fallback to the\n // MRU node or initial focus node, if any\n navAcrossContainers = false;\n }\n }\n } else {\n // no MRU node means we're likely in some initial condition when the trap has just\n // been activated and initial focus hasn't been given yet, in which case we should\n // fall through to trying to focus the initial focus node, which is what should\n // happen below at this point in the logic\n navAcrossContainers = false;\n }\n\n if (navAcrossContainers) {\n nextNode = findNextNavNode({\n // move FROM the MRU node, not event-related node (which will be the node that is\n // outside the trap causing the focus escape we're trying to fix)\n target: state.mostRecentlyFocusedNode,\n isBackward: config.isKeyBackward(state.recentNavEvent),\n });\n }\n\n if (nextNode) {\n tryFocus(nextNode);\n } else {\n tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());\n }\n }\n\n state.recentNavEvent = undefined; // clear\n };\n\n // Hijack key nav events on the first and last focusable nodes of the trap,\n // in order to prevent focus from escaping. If it escapes for even a\n // moment it can end up scrolling the page and causing confusion so we\n // kind of need to capture the action at the keydown phase.\n const checkKeyNav = function (event, isBackward = false) {\n state.recentNavEvent = event;\n\n const destinationNode = findNextNavNode({ event, isBackward });\n if (destinationNode) {\n if (isTabEvent(event)) {\n // since tab natively moves focus, we wouldn't have a destination node unless we\n // were on the edge of a container and had to move to the next/previous edge, in\n // which case we want to prevent default to keep the browser from moving focus\n // to where it normally would\n event.preventDefault();\n }\n tryFocus(destinationNode);\n }\n // else, let the browser take care of [shift+]tab and move the focus\n };\n\n const checkTabKey = function (event) {\n if (config.isKeyForward(event) || config.isKeyBackward(event)) {\n checkKeyNav(event, config.isKeyBackward(event));\n }\n };\n\n // we use a different event phase for the Escape key to allow canceling the event and checking for this in escapeDeactivates\n const checkEscapeKey = function (event) {\n if (\n isEscapeEvent(event) &&\n valueOrHandler(config.escapeDeactivates, event) !== false\n ) {\n event.preventDefault();\n trap.deactivate();\n }\n };\n\n const checkClick = function (e) {\n const target = getActualTarget(e);\n\n if (findContainerIndex(target, e) >= 0) {\n return;\n }\n\n if (valueOrHandler(config.clickOutsideDeactivates, e)) {\n return;\n }\n\n if (valueOrHandler(config.allowOutsideClick, e)) {\n return;\n }\n\n e.preventDefault();\n e.stopImmediatePropagation();\n };\n\n //\n // EVENT LISTENERS\n //\n\n /**\n * Adds listeners to the document necessary for trapping focus and attempts to set focus\n * to the configured initial focus node. Does nothing if the trap isn't active.\n * @returns {Promise<void>} Resolved (always) once the initial focus node has been focused.\n * Also resolved if the trap isn't active.\n */\n const addListeners = function () {\n if (!state.active) {\n return Promise.resolve();\n }\n\n // There can be only one listening focus trap at a time\n activeFocusTraps.activateTrap(trapStack, trap);\n\n // Delay ensures that the focused element doesn't capture the event\n // that caused the focus trap activation.\n /** @type {Promise<void>} */\n let promise;\n if (config.delayInitialFocus) {\n // NOTE: Promise constructor callback is called synchronously, which is what we want\n // since we need to capture the timer ID immediately\n promise = new Promise((resolve) => {\n state.delayInitialFocusTimer = delay(function () {\n tryFocus(getInitialFocusNode());\n resolve();\n });\n });\n } else {\n promise = Promise.resolve();\n tryFocus(getInitialFocusNode());\n }\n\n doc.addEventListener('focusin', checkFocusIn, true);\n doc.addEventListener('mousedown', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('touchstart', checkPointerDown, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('click', checkClick, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkTabKey, {\n capture: true,\n passive: false,\n });\n doc.addEventListener('keydown', checkEscapeKey);\n\n return promise;\n };\n\n /**\n * Traverses up the DOM from each of `containers`, collecting references to\n * the elements that are siblings to `container` or an ancestor of `container`.\n * @param {Array<HTMLElement>} containers\n */\n const collectAdjacentElements = function (containers) {\n // Re-activate all adjacent elements & clear previous collection.\n if (state.active && !state.paused) {\n trap._setSubtreeIsolation(false);\n }\n state.adjacentElements.clear();\n state.alreadySilent.clear();\n\n // Collect all ancestors of all containers to avoid redundant processing.\n const containerAncestors = new Set();\n\n const adjacentElements = new Set();\n\n // Compile all elements adjacent to the focus trap containers & lineage.\n for (const container of containers) {\n containerAncestors.add(container);\n let insideShadowRoot =\n typeof ShadowRoot !== 'undefined' &&\n container.getRootNode() instanceof ShadowRoot;\n let current = container;\n while (current) {\n containerAncestors.add(current);\n\n let parent = current.parentElement;\n let siblings = [];\n if (parent) {\n siblings = parent.children;\n } else if (!parent && insideShadowRoot) {\n siblings = current.getRootNode().children;\n parent = current.getRootNode().host;\n insideShadowRoot =\n typeof ShadowRoot !== 'undefined' &&\n parent.getRootNode() instanceof ShadowRoot;\n }\n\n // Add all the children, we'll remove container lineage later.\n for (const child of siblings) {\n adjacentElements.add(child);\n }\n\n current = parent;\n }\n }\n\n // Multi-container traps may overlap.\n // Remove elements within container lineages.\n containerAncestors.forEach((el) => {\n adjacentElements.delete(el);\n });\n\n state.adjacentElements = adjacentElements;\n };\n\n const removeListeners = function () {\n if (!state.active) {\n return;\n }\n\n doc.removeEventListener('focusin', checkFocusIn, true);\n doc.removeEventListener('mousedown', checkPointerDown, true);\n doc.removeEventListener('touchstart', checkPointerDown, true);\n doc.removeEventListener('click', checkClick, true);\n doc.removeEventListener('keydown', checkTabKey, true);\n doc.removeEventListener('keydown', checkEscapeKey);\n\n return trap;\n };\n\n //\n // MUTATION OBSERVER\n //\n\n const checkDomRemoval = function (mutations) {\n const isFocusedNodeRemoved = mutations.some(function (mutation) {\n const removedNodes = Array.from(mutation.removedNodes);\n return removedNodes.some(function (node) {\n return node === state.mostRecentlyFocusedNode;\n });\n });\n\n // If the currently focused is removed then browsers will move focus to the\n // <body> element. If this happens, try to move focus back into the trap.\n if (isFocusedNodeRemoved) {\n tryFocus(getInitialFocusNode());\n }\n };\n\n // Use MutationObserver - if supported - to detect if focused node is removed\n // from the DOM.\n const mutationObserver =\n typeof window !== 'undefined' && 'MutationObserver' in window\n ? new MutationObserver(checkDomRemoval)\n : undefined;\n\n const updateObservedNodes = function () {\n if (!mutationObserver) {\n return;\n }\n\n mutationObserver.disconnect();\n if (state.active && !state.paused) {\n state.containers.map(function (container) {\n mutationObserver.observe(container, {\n subtree: true,\n childList: true,\n });\n });\n }\n };\n\n //\n // TRAP DEFINITION\n //\n\n trap = {\n get active() {\n return state.active;\n },\n\n get paused() {\n return state.paused;\n },\n\n activate(activateOptions) {\n if (state.active) {\n return this;\n }\n\n const onActivate = getOption(activateOptions, 'onActivate');\n const onPostActivate = getOption(activateOptions, 'onPostActivate');\n const checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');\n\n // If a currently-active trap is isolating its subtree, we need to remove\n // that isolation to allow the new trap to find tabbable nodes.\n const preexistingTrap = activeFocusTraps.getActiveTrap(trapStack);\n let revertState = false;\n if (preexistingTrap && !preexistingTrap.paused) {\n // [#1729] method MAY not exist if using `trapStack` option to share stack with older\n // versions of Focus-trap in the same DOM so use optional chaining here just in case\n // since this is a trap we may not have created from this instance of the library\n preexistingTrap._setSubtreeIsolation?.(false);\n revertState = true;\n }\n\n try {\n if (!checkCanFocusTrap) {\n updateTabbableNodes();\n }\n\n state.active = true;\n state.paused = false;\n state.nodeFocusedBeforeActivation = getActiveElement(doc);\n\n onActivate?.({ trap });\n\n const finishActivation = async () => {\n if (checkCanFocusTrap) {\n updateTabbableNodes();\n }\n\n // NOTE: wait for initial focus node to get focused before we potentially isolate\n // the subtrees with aria-hidden while focus is still in some other subtree and\n // not yet in the trap, resulting in some browsers (e.g. Chrome) logging to the\n // console that they, \"Blocked aria-hidden on an element because its descendant\n // retained focus...\"\n await addListeners();\n\n trap._setSubtreeIsolation(true);\n updateObservedNodes();\n onPostActivate?.({ trap });\n };\n\n if (checkCanFocusTrap) {\n checkCanFocusTrap(state.containers.concat()).then(\n finishActivation,\n finishActivation\n );\n return this;\n }\n\n finishActivation();\n } catch (error) {\n // If our activation throws an exception and the stack hasn't changed,\n // we need to re-enable the prior trap's subtree isolation.\n if (\n preexistingTrap === activeFocusTraps.getActiveTrap(trapStack) &&\n revertState\n ) {\n // [#1729] method MAY not exist if using `trapStack` option to share stack with older\n // versions of Focus-trap in the same DOM so use optional chaining here just in case\n // since this is a trap we may not have created from this instance of the library\n preexistingTrap._setSubtreeIsolation?.(true);\n }\n throw error;\n }\n return this;\n },\n\n deactivate(deactivateOptions) {\n if (!state.active) {\n return this;\n }\n\n const options = {\n onDeactivate: config.onDeactivate,\n onPostDeactivate: config.onPostDeactivate,\n checkCanReturnFocus: config.checkCanReturnFocus,\n ...deactivateOptions,\n };\n\n clearTimeout(state.delayInitialFocusTimer); // noop if undefined\n state.delayInitialFocusTimer = undefined;\n\n // Prior to removing this trap from the trapStack, we need to remove any applications of `inert`.\n // This allows the next trap down to update its tabbable nodes properly.\n //\n // If this trap is not top of the stack, don't change any current isolation.\n if (!state.paused) {\n trap._setSubtreeIsolation(false);\n }\n state.alreadySilent.clear();\n removeListeners();\n state.active = false;\n state.paused = false;\n updateObservedNodes();\n\n activeFocusTraps.deactivateTrap(trapStack, trap);\n\n const onDeactivate = getOption(options, 'onDeactivate');\n const onPostDeactivate = getOption(options, 'onPostDeactivate');\n const checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');\n const returnFocus = getOption(\n options,\n 'returnFocus',\n 'returnFocusOnDeactivate'\n );\n\n onDeactivate?.({ trap });\n\n const finishDeactivation = () => {\n delay(() => {\n if (returnFocus) {\n tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));\n }\n onPostDeactivate?.({ trap });\n });\n };\n\n if (returnFocus && checkCanReturnFocus) {\n checkCanReturnFocus(\n getReturnFocusNode(state.nodeFocusedBeforeActivation)\n ).then(finishDeactivation, finishDeactivation);\n return this;\n }\n\n finishDeactivation();\n return this;\n },\n\n pause(pauseOptions) {\n if (!state.active) {\n return this;\n }\n\n state.manuallyPaused = true;\n\n return this._setPausedState(true, pauseOptions);\n },\n\n unpause(unpauseOptions) {\n if (!state.active) {\n return this;\n }\n\n state.manuallyPaused = false;\n\n if (trapStack[trapStack.length - 1] !== this) {\n return this;\n }\n\n return this._setPausedState(false, unpauseOptions);\n },\n\n updateContainerElements(containerElements) {\n const elementsAsArray = [].concat(containerElements).filter(Boolean);\n\n state.containers = elementsAsArray.map((element) =>\n typeof element === 'string' ? doc.querySelector(element) : element\n );\n\n if (config.isolateSubtrees) {\n collectAdjacentElements(state.containers);\n }\n\n if (state.active) {\n updateTabbableNodes();\n\n if (!state.paused) {\n trap._setSubtreeIsolation(true);\n }\n }\n\n updateObservedNodes();\n\n return this;\n },\n };\n\n Object.defineProperties(trap, {\n _isManuallyPaused: {\n value() {\n return state.manuallyPaused;\n },\n },\n _setPausedState: {\n value(paused, options) {\n if (state.paused === paused) {\n return this;\n }\n\n state.paused = paused;\n\n if (paused) {\n const onPause = getOption(options, 'onPause');\n const onPostPause = getOption(options, 'onPostPause');\n onPause?.({ trap });\n\n removeListeners();\n trap._setSubtreeIsolation(false);\n updateObservedNodes();\n\n onPostPause?.({ trap });\n } else {\n const onUnpause = getOption(options, 'onUnpause');\n const onPostUnpause = getOption(options, 'onPostUnpause');\n\n onUnpause?.({ trap });\n\n const finishUnpause = async () => {\n updateTabbableNodes();\n\n // NOTE: wait for initial focus node to get focused before we potentially isolate\n // the subtrees with aria-hidden while focus is still in some other subtree and\n // not yet in the trap, resulting in some browsers (e.g. Chrome) logging to the\n // console that they, \"Blocked aria-hidden on an element because its descendant\n // retained focus...\"\n await addListeners();\n\n trap._setSubtreeIsolation(true);\n updateObservedNodes();\n onPostUnpause?.({ trap });\n };\n\n finishUnpause();\n }\n\n return this;\n },\n },\n _setSubtreeIsolation: {\n value(isEnabled) {\n if (config.isolateSubtrees) {\n state.adjacentElements.forEach((el) => {\n if (isEnabled) {\n switch (config.isolateSubtrees) {\n case 'aria-hidden':\n // check both attribute and property to ensure initial state is captured\n // correctly across different browsers and test environments (like JSDOM)\n if (\n el.ariaHidden === 'true' ||\n el.getAttribute('aria-hidden')?.toLowerCase() === 'true'\n ) {\n state.alreadySilent.add(el);\n }\n\n el.setAttribute('aria-hidden', 'true');\n break;\n\n default:\n // check both attribute and property to ensure initial state is captured\n // correctly across different browsers and test environments (like JSDOM)\n if (el.inert || el.hasAttribute('inert')) {\n state.alreadySilent.add(el);\n }\n el.setAttribute('inert', true);\n break;\n }\n } else {\n if (state.alreadySilent.has(el)) {\n // do nothing\n } else {\n switch (config.isolateSubtrees) {\n case 'aria-hidden':\n el.removeAttribute('aria-hidden');\n break;\n\n default:\n el.removeAttribute('inert');\n break;\n }\n }\n }\n });\n }\n },\n },\n });\n\n // initialize container elements\n trap.updateContainerElements(elements);\n\n return trap;\n};\n\nexport { createFocusTrap };\n"],"names":["activeFocusTraps","getActiveTrap","trapStack","length","activateTrap","trap","pauseTrap","trapIndex","indexOf","splice","push","deactivateTrap","unpauseTrap","activeTrap","_setPausedState","_isManuallyPaused","isTabEvent","e","key","keyCode","isKeyForward","shiftKey","isKeyBackward","delay","fn","setTimeout","valueOrHandler","value","_len","arguments","params","Array","_key","apply","getActualTarget","event","target","shadowRoot","composedPath","internalTrapStack","elements","userOptions","doc","document","config","_objectSpread","returnFocusOnDeactivate","escapeDeactivates","delayInitialFocus","isolateSubtrees","state","containers","containerGroups","tabbableGroups","adjacentElements","Set","alreadySilent","nodeFocusedBeforeActivation","mostRecentlyFocusedNode","active","paused","manuallyPaused","delayInitialFocusTimer","undefined","recentNavEvent","getOption","configOverrideOptions","optionName","configOptionName","findContainerIndex","element","findIndex","_ref","container","tabbableNodes","contains","includes","find","node","getNodeForOption","_ref2","_ref2$hasFallback","hasFallback","_ref2$params","optionValue","_toConsumableArray","Error","concat","querySelector","err","message","getInitialFocusNode","isFocusable","tabbableOptions","activeElement","firstTabbableGroup","firstTabbableNode","updateTabbableNodes","map","tabbable","focusableNodes","focusable","lastTabbableNode","firstDomTabbableNode","isTabbable","lastDomTabbableNode","slice","reverse","posTabIndexesFound","getTabIndex","nextTabbableNode","forward","nodeIdx","el","filter","group","g","getActiveElement","tryFocus","focus","preventScroll","tagName","toLowerCase","select","isSelectableInput","getReturnFocusNode","previousActiveElement","findNextNavNode","_ref3","_ref3$isBackward","isBackward","destinationNode","containerIndex","containerGroup","startOfGroupIndex","_ref4","destinationGroupIndex","destinationGroup","lastOfGroupIndex","_ref5","checkPointerDown","clickOutsideDeactivates","deactivate","returnFocus","allowOutsideClick","preventDefault","checkFocusIn","targetContained","Document","nextNode","stopImmediatePropagation","navAcrossContainers","mruContainerIdx","mruTabIdx","some","n","checkTabKey","checkKeyNav","checkEscapeKey","checkClick","addListeners","promise","Promise","resolve","addEventListener","capture","passive","removeListeners","removeEventListener","mutationObserver","window","MutationObserver","mutations","mutation","from","removedNodes","updateObservedNodes","disconnect","observe","subtree","childList","activate","activateOptions","this","_preexistingTrap$_set","onActivate","onPostActivate","checkCanFocusTrap","preexistingTrap","revertState","_setSubtreeIsolation","call","finishActivation","_ref6","_asyncToGenerator","_regenerator","m","_callee","w","_context","a","then","error","_preexistingTrap$_set2","deactivateOptions","options","onDeactivate","onPostDeactivate","checkCanReturnFocus","clearTimeout","clear","finishDeactivation","pause","pauseOptions","unpause","unpauseOptions","updateContainerElements","containerElements","elementsAsArray","Boolean","_step","containerAncestors","_iterator","_createForOfIteratorHelper","s","done","add","insideShadowRoot","ShadowRoot","getRootNode","current","parent","parentElement","siblings","children","host","_step2","_iterator2","child","f","forEach","collectAdjacentElements","Object","defineProperties","onPause","onPostPause","onUnpause","onPostUnpause","finishUnpause","_ref7","_callee2","_context2","isEnabled","_el$getAttribute","ariaHidden","getAttribute","setAttribute","inert","hasAttribute","has","removeAttribute"],"mappings":";;;;;;wnFAQA,IAAMA,EAAmB,CAEvBC,cAAa,SAACC,GACZ,OAAIA,aAAS,EAATA,EAAWC,QAAS,EACfD,EAAUA,EAAUC,OAAS,GAE/B,IACT,EAGAC,sBAAaF,EAAWG,GAGlBA,IAFeL,EAAiBC,cAAcC,IAGhDF,EAAiBM,UAAUJ,GAG7B,IAAMK,EAAYL,EAAUM,QAAQH,IAClB,IAAdE,GAIFL,EAAUO,OAAOF,EAAW,GAH5BL,EAAUQ,KAAKL,EAMnB,EAGAM,wBAAeT,EAAWG,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I,EACrC,GAAID,EACF,GACO,gBADChN,EAAOK,gBAKS,SAAlBgE,EAAG6I,YAC+C,UAApB,QAA9BD,EAAA5I,EAAG8I,aAAa,sBAAc,IAAAF,OAAA,EAA9BA,EAAgCnI,gBAEhCxE,EAAMM,cAAc0K,IAAIjH,GAG1BA,EAAG+I,aAAa,cAAe,aAM3B/I,EAAGgJ,OAAShJ,EAAGiJ,aAAa,WAC9BhN,EAAMM,cAAc0K,IAAIjH,GAE1BA,EAAG+I,aAAa,SAAS,QAI7B,GAAI9M,EAAMM,cAAc2M,IAAIlJ,SAG1B,GACO,gBADCrE,EAAOK,gBAEXgE,EAAGmJ,gBAAgB,oBAInBnJ,EAAGmJ,gBAAgB,QAK7B,GAEJ,KAKJ/P,EAAKmN,wBAAwBhL,GAEtBnC,CACT"}
package/index.d.ts CHANGED
@@ -27,42 +27,52 @@ declare module 'focus-trap' {
27
27
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- Reserving ability to add/remove properties in the future
28
28
  export interface FocusTrapTabbableOptions extends TabbableCheckOptions {}
29
29
 
30
+ /**
31
+ * Standard non-positional parameters for lifecycle hooks in {@link Options}.
32
+ */
33
+ export type LifecycleParameters = {
34
+ /**
35
+ * The focus trap associated with the lifecycle hook.
36
+ */
37
+ trap: FocusTrap;
38
+ };
39
+
30
40
  export interface Options {
31
41
  /**
32
42
  * A function that will be called **before** sending focus to the
33
43
  * target element upon activation.
34
44
  */
35
- onActivate?: () => void;
45
+ onActivate?: (params: LifecycleParameters) => void;
36
46
 
37
47
  /**
38
48
  * A function that will be called **after** focus has been sent to the
39
49
  * target element upon activation.
40
50
  */
41
- onPostActivate?: () => void;
51
+ onPostActivate?: (params: LifecycleParameters) => void;
42
52
 
43
53
  /**
44
54
  * A function that will be called immediately after the trap's state is updated to be paused.
45
55
  */
46
- onPause?: () => void;
56
+ onPause?: (params: LifecycleParameters) => void;
47
57
 
48
58
  /**
49
59
  * A function that will be called after the trap has been completely paused and is no longer
50
60
  * managing/trapping focus.
51
61
  */
52
- onPostPause?: () => void;
62
+ onPostPause?: (params: LifecycleParameters) => void;
53
63
 
54
64
  /**
55
65
  * A function that will be called immediately after the trap's state is updated to be active
56
66
  * again, but prior to updating its knowledge of what nodes are tabbable within its containers,
57
67
  * and prior to actively managing/trapping focus.
58
68
  */
59
- onUnpause?: () => void;
69
+ onUnpause?: (params: LifecycleParameters) => void;
60
70
 
61
71
  /**
62
72
  * A function that will be called after the trap has been completely unpaused and is once
63
73
  * again managing/trapping focus.
64
74
  */
65
- onPostUnpause?: () => void;
75
+ onPostUnpause?: (params: LifecycleParameters) => void;
66
76
 
67
77
  /**
68
78
  * A function for determining if it is safe to send focus to the focus trap
@@ -71,26 +81,29 @@ declare module 'focus-trap' {
71
81
  * It should return a promise that only resolves once all the listed `containers`
72
82
  * are able to receive focus.
73
83
  *
74
- * The purpose of this is to prevent early focus-trap activation on animated
84
+ * This option exists to prevent early focus-trap activation on animated
75
85
  * dialogs that fade in and out. When a dialog fades in, there is a brief delay
76
86
  * between the activation of the trap and the trap element being focusable.
87
+ *
88
+ * 🔺 It does not matter whether the Promise resolves or rejects, only that it
89
+ * settles. A rejected Promise will not result in cancellation of trap activation.
77
90
  */
78
91
  checkCanFocusTrap?: (
79
92
  containers: Array<HTMLElement | SVGElement>
80
- ) => Promise<void>;
93
+ ) => Promise<unknown>;
81
94
 
82
95
  /**
83
96
  * A function that will be called **before** sending focus to the
84
97
  * trigger element upon deactivation.
85
98
  */
86
- onDeactivate?: () => void;
99
+ onDeactivate?: (params: LifecycleParameters) => void;
87
100
 
88
101
  /**
89
102
  * A function that will be called after the trap is deactivated, after `onDeactivate`.
90
103
  * If `returnFocus` was set, it will be called **after** focus has been sent to the trigger
91
104
  * element upon deactivation; otherwise, it will be called after deactivation completes.
92
105
  */
93
- onPostDeactivate?: () => void;
106
+ onPostDeactivate?: (params: LifecycleParameters) => void;
94
107
  /**
95
108
  * A function for determining if it is safe to send focus back to the `trigger` element.
96
109
  *
package/index.js CHANGED
@@ -1059,7 +1059,7 @@ const createFocusTrap = function (elements, userOptions) {
1059
1059
  state.paused = false;
1060
1060
  state.nodeFocusedBeforeActivation = getActiveElement(doc);
1061
1061
 
1062
- onActivate?.();
1062
+ onActivate?.({ trap });
1063
1063
 
1064
1064
  const finishActivation = async () => {
1065
1065
  if (checkCanFocusTrap) {
@@ -1075,7 +1075,7 @@ const createFocusTrap = function (elements, userOptions) {
1075
1075
 
1076
1076
  trap._setSubtreeIsolation(true);
1077
1077
  updateObservedNodes();
1078
- onPostActivate?.();
1078
+ onPostActivate?.({ trap });
1079
1079
  };
1080
1080
 
1081
1081
  if (checkCanFocusTrap) {
@@ -1143,14 +1143,14 @@ const createFocusTrap = function (elements, userOptions) {
1143
1143
  'returnFocusOnDeactivate'
1144
1144
  );
1145
1145
 
1146
- onDeactivate?.();
1146
+ onDeactivate?.({ trap });
1147
1147
 
1148
1148
  const finishDeactivation = () => {
1149
1149
  delay(() => {
1150
1150
  if (returnFocus) {
1151
1151
  tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1152
1152
  }
1153
- onPostDeactivate?.();
1153
+ onPostDeactivate?.({ trap });
1154
1154
  });
1155
1155
  };
1156
1156
 
@@ -1231,18 +1231,18 @@ const createFocusTrap = function (elements, userOptions) {
1231
1231
  if (paused) {
1232
1232
  const onPause = getOption(options, 'onPause');
1233
1233
  const onPostPause = getOption(options, 'onPostPause');
1234
- onPause?.();
1234
+ onPause?.({ trap });
1235
1235
 
1236
1236
  removeListeners();
1237
1237
  trap._setSubtreeIsolation(false);
1238
1238
  updateObservedNodes();
1239
1239
 
1240
- onPostPause?.();
1240
+ onPostPause?.({ trap });
1241
1241
  } else {
1242
1242
  const onUnpause = getOption(options, 'onUnpause');
1243
1243
  const onPostUnpause = getOption(options, 'onPostUnpause');
1244
1244
 
1245
- onUnpause?.();
1245
+ onUnpause?.({ trap });
1246
1246
 
1247
1247
  const finishUnpause = async () => {
1248
1248
  updateTabbableNodes();
@@ -1256,7 +1256,7 @@ const createFocusTrap = function (elements, userOptions) {
1256
1256
 
1257
1257
  trap._setSubtreeIsolation(true);
1258
1258
  updateObservedNodes();
1259
- onPostUnpause?.();
1259
+ onPostUnpause?.({ trap });
1260
1260
  };
1261
1261
 
1262
1262
  finishUnpause();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "focus-trap",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "Trap focus within a DOM node.",
5
5
  "main": "dist/focus-trap.js",
6
6
  "module": "dist/focus-trap.esm.js",
@@ -31,7 +31,7 @@
31
31
  "build": "npm run clean && npm run compile",
32
32
  "start": "npm run compile:demo -- --watch --environment SERVE,RELOAD",
33
33
  "start:cypress": "npm run compile:demo -- --environment SERVE,IS_CYPRESS_ENV:\"$CYPRESS_BROWSER\"",
34
- "test:types": "tsc index.d.ts",
34
+ "test:types": "tsc",
35
35
  "test:unit": "jest",
36
36
  "test:coverage": "jest --coverage",
37
37
  "test:e2e": "ELECTRON_ENABLE_LOGGING=1 start-server-and-test start:cypress 9966 'cypress run --browser $CYPRESS_BROWSER --headless'",
@@ -69,51 +69,51 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@babel/cli": "^7.28.6",
72
- "@babel/core": "^7.28.6",
72
+ "@babel/core": "^7.29.0",
73
73
  "@babel/eslint-parser": "^7.28.6",
74
74
  "@babel/eslint-plugin": "^7.27.1",
75
- "@babel/preset-env": "^7.28.6",
76
- "@changesets/cli": "^2.29.8",
75
+ "@babel/preset-env": "^7.29.2",
76
+ "@changesets/cli": "^2.31.0",
77
77
  "@eslint/js": "^9.39.2",
78
- "@rollup/plugin-babel": "^6.1.0",
79
- "@rollup/plugin-commonjs": "^29.0.0",
78
+ "@rollup/plugin-babel": "^7.0.0",
79
+ "@rollup/plugin-commonjs": "^29.0.2",
80
80
  "@rollup/plugin-node-resolve": "^16.0.3",
81
81
  "@rollup/plugin-replace": "^6.0.3",
82
- "@rollup/plugin-terser": "^0.4.4",
82
+ "@rollup/plugin-terser": "^1.0.0",
83
83
  "@testing-library/cypress": "^10.1.0",
84
84
  "@testing-library/dom": "^10.4.1",
85
85
  "@testing-library/jest-dom": "^6.9.1",
86
86
  "@testing-library/user-event": "^14.6.1",
87
87
  "@types/jest": "^30.0.0",
88
- "@types/jquery": "^3.5.33",
89
- "@types/node": "^25.0.10",
90
- "@typescript-eslint/eslint-plugin": "^8.54.0",
91
- "@typescript-eslint/parser": "^8.53.1",
88
+ "@types/jquery": "^4.0.0",
89
+ "@types/node": "^25.6.0",
90
+ "@typescript-eslint/eslint-plugin": "^8.59.0",
91
+ "@typescript-eslint/parser": "^8.58.2",
92
92
  "all-contributors-cli": "^6.26.1",
93
- "babel-jest": "^30.1.2",
94
- "babel-loader": "^10.0.0",
93
+ "babel-jest": "^30.3.0",
94
+ "babel-loader": "^10.1.1",
95
95
  "cross-env": "^10.1.0",
96
- "cypress": "^15.9.0",
96
+ "cypress": "^15.14.1",
97
97
  "cypress-plugin-tab": "^1.0.5",
98
98
  "eslint": "^9.39.2",
99
99
  "eslint-config-prettier": "^10.1.8",
100
- "eslint-import-resolver-node": "^0.3.9",
100
+ "eslint-import-resolver-node": "^0.3.10",
101
101
  "eslint-import-resolver-typescript": "^4.4.4",
102
- "eslint-plugin-cypress": "^5.2.1",
102
+ "eslint-plugin-cypress": "^6.3.1",
103
103
  "eslint-plugin-import": "^2.32.0",
104
- "eslint-plugin-jest": "^29.12.1",
104
+ "eslint-plugin-jest": "^29.15.2",
105
105
  "eslint-plugin-jest-dom": "^5.5.0",
106
- "eslint-plugin-testing-library": "^7.15.4",
107
- "globals": "^17.2.0",
108
- "jest": "^30.2.0",
109
- "jest-environment-jsdom": "^30.2.0",
106
+ "eslint-plugin-testing-library": "^7.16.2",
107
+ "globals": "^17.5.0",
108
+ "jest": "^30.3.0",
109
+ "jest-environment-jsdom": "^30.3.0",
110
110
  "jest-watch-typeahead": "^3.0.1",
111
111
  "onchange": "^7.1.0",
112
- "prettier": "^3.8.1",
113
- "rollup": "^4.57.0",
112
+ "prettier": "^3.8.3",
113
+ "rollup": "^4.60.2",
114
114
  "rollup-plugin-livereload": "^2.0.5",
115
115
  "rollup-plugin-serve": "^3.0.0",
116
- "start-server-and-test": "^2.1.3",
117
- "typescript": "^5.9.3"
116
+ "start-server-and-test": "^3.0.2",
117
+ "typescript": "^6.0.3"
118
118
  }
119
119
  }