@react-aria/focus 3.19.0 → 3.19.1

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,5 +1,6 @@
1
1
  var $1c7f9157d722357d$exports = require("./focusSafely.main.js");
2
2
  var $d5156037ad898a4d$exports = require("./isElementVisible.main.js");
3
+ var $euGna$reactariainteractions = require("@react-aria/interactions");
3
4
  var $euGna$reactariautils = require("@react-aria/utils");
4
5
  var $euGna$react = require("react");
5
6
 
@@ -32,6 +33,7 @@ $parcel$export(module.exports, "createFocusManager", () => $a7a032acae3ddda9$exp
32
33
 
33
34
 
34
35
 
36
+
35
37
  const $a7a032acae3ddda9$var$FocusContext = /*#__PURE__*/ (0, ($parcel$interopDefault($euGna$react))).createContext(null);
36
38
  const $a7a032acae3ddda9$var$RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';
37
39
  let $a7a032acae3ddda9$var$activeScope = null;
@@ -226,7 +228,7 @@ const $a7a032acae3ddda9$var$focusableElements = [
226
228
  'embed',
227
229
  'audio[controls]',
228
230
  'video[controls]',
229
- '[contenteditable]'
231
+ '[contenteditable]:not([contenteditable^="false"])'
230
232
  ];
231
233
  const $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
232
234
  $a7a032acae3ddda9$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
@@ -296,8 +298,13 @@ function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
296
298
  // Firefox doesn't shift focus back to the Dialog properly without this
297
299
  if (raf.current) cancelAnimationFrame(raf.current);
298
300
  raf.current = requestAnimationFrame(()=>{
301
+ // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor
302
+ // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.
303
+ // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.
304
+ let modality = (0, $euGna$reactariainteractions.getInteractionModality)();
305
+ let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && (0, $euGna$reactariautils.isAndroid)() && (0, $euGna$reactariautils.isChrome)();
299
306
  // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
300
- if (ownerDocument.activeElement && $a7a032acae3ddda9$var$shouldContainFocus(scopeRef) && !$a7a032acae3ddda9$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
307
+ if (!shouldSkipFocusRestore && ownerDocument.activeElement && $a7a032acae3ddda9$var$shouldContainFocus(scopeRef) && !$a7a032acae3ddda9$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
301
308
  $a7a032acae3ddda9$var$activeScope = scopeRef;
302
309
  if (ownerDocument.body.contains(e.target)) {
303
310
  var _focusedNode_current;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAwDD,MAAM,mDAAe,CAAA,GAAA,sCAAI,EAAE,aAAa,CAAuB;AAC/D,MAAM,4CAAsB;AAE5B,IAAI,oCAAwB;AAYrB,SAAS,0CAAW,KAAsB;IAC/C,IAAI,YAAC,QAAQ,WAAE,OAAO,gBAAE,YAAY,aAAE,SAAS,EAAC,GAAG;IACnD,IAAI,WAAW,CAAA,GAAA,mBAAK,EAAmB;IACvC,IAAI,SAAS,CAAA,GAAA,mBAAK,EAAmB;IACrC,IAAI,WAAW,CAAA,GAAA,mBAAK,EAAa,EAAE;IACnC,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,uBAAS,EAAE,uCAAiB,CAAC;IAEhD,4FAA4F;IAC5F,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,+BAAS;sBAAC;QAAQ,IAAI;QAAC;KAAS;IAE7D,CAAA,GAAA,qCAAc,EAAE;QACd,+FAA+F;QAC/F,mGAAmG;QACnG,mGAAmG;QACnG,gEAAgE;QACh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AC,KAAK,QAAQ;IACnC;IAEA,wBAAwB;IACxB,CAAC,SAAS,OAAiB,IAAI,CAAC,IAAI,EAAuB;QACzD,IAAI,KAAK,QAAQ,IAAI,MACnB,MAAM;QAER,IAAI,KAAK,QAAQ,CAAC,IAAI,GAAG,GACvB,KAAK,IAAI,SAAS,KAAK,QAAQ,CAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC;IAG3B;IAEA,QAAc;YAGyB;QAFrC,IAAI,UAAU,IAAI;YAEmB;QADrC,KAAK,IAAI,QAAQ,IAAI,CAAC,QAAQ,GAC5B,QAAQ,WAAW,CAAC,KAAK,QAAQ,EAAE,CAAA,yBAAA,eAAA,KAAK,MAAM,cAAX,mCAAA,aAAa,QAAQ,cAArB,mCAAA,wBAAyB,MAAM,KAAK,aAAa;QAEtF,OAAO;IACT;IApFA,aAAc;aAFN,UAAU,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,+BAAS;YAAC,UAAU;QAAI;QACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI;IAClC;AAkFF;AAEA,MAAM;IAUJ,SAAS,IAAc,EAAE;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAClB,KAAK,MAAM,GAAG,IAAI;IACpB;IACA,YAAY,IAAc,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,MAAM,GAAG;IAChB;IAVA,YAAY,KAA2B,CAAE;aAHlC,WAA0B,IAAI;aAC9B,UAAU;QAGf,IAAI,CAAC,QAAQ,GAAG,MAAM,QAAQ;IAChC;AASF;AAEO,IAAI,4CAAiB,IAAI","sources":["packages/@react-aria/focus/src/FocusScope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusSafely} from './focusSafely';\nimport {getOwnerDocument, useLayoutEffect} from '@react-aria/utils';\nimport {isElementVisible} from './isElementVisible';\nimport React, {ReactNode, useContext, useEffect, useMemo, useRef} from 'react';\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: ReactNode,\n\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean,\n\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean,\n\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element,\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean,\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean,\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast(opts?: FocusManagerOptions): FocusableElement | null\n}\n\ntype ScopeRef = RefObject<Element[] | null> | null;\ninterface IFocusContext {\n focusManager: FocusManager,\n parentNode: TreeNode | null\n}\n\nconst FocusContext = React.createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';\n\nlet activeScope: ScopeRef = null;\n\n// This is a hacky DOM-based implementation of a FocusScope until this RFC lands in React:\n// https://github.com/reactjs/rfcs/pull/109\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nexport function FocusScope(props: FocusScopeProps) {\n let {children, contain, restoreFocus, autoFocus} = props;\n let startRef = useRef<HTMLSpanElement>(null);\n let endRef = useRef<HTMLSpanElement>(null);\n let scopeRef = useRef<Element[]>([]);\n let {parentNode} = useContext(FocusContext) || {};\n\n // Create a tree node here so we can add children to it even before it is added to the tree.\n let node = useMemo(() => new TreeNode({scopeRef}), [scopeRef]);\n\n useLayoutEffect(() => {\n // If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),\n // use the active scope as the parent instead of the parent from context. Layout effects run bottom\n // up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope\n // that is being added should get the activeScope as its parent.\n let parent = parentNode || focusScopeTree.root;\n if (focusScopeTree.getTreeNode(parent.scopeRef) && activeScope && !isAncestorScope(activeScope, parent.scopeRef)) {\n let activeNode = focusScopeTree.getTreeNode(activeScope);\n if (activeNode) {\n parent = activeNode;\n }\n }\n\n // Add the node to the parent, and to the tree.\n parent.addChild(node);\n focusScopeTree.addNode(node);\n }, [node, parentNode]);\n\n useLayoutEffect(() => {\n let node = focusScopeTree.getTreeNode(scopeRef);\n if (node) {\n node.contain = !!contain;\n }\n }, [contain]);\n\n useLayoutEffect(() => {\n // Find all rendered nodes between the sentinels and add them to the scope.\n let node = startRef.current?.nextSibling!;\n let nodes: Element[] = [];\n let stopPropagation = e => e.stopPropagation();\n while (node && node !== endRef.current) {\n nodes.push(node as Element);\n // Stop custom restore focus event from propagating to parent focus scopes.\n node.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n node = node.nextSibling as Element;\n }\n\n scopeRef.current = nodes;\n\n return () => {\n for (let node of nodes) {\n node.removeEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n };\n }, [children]);\n\n useActiveScopeTracker(scopeRef, restoreFocus, contain);\n useFocusContainment(scopeRef, contain);\n useRestoreFocus(scopeRef, restoreFocus, contain);\n useAutoFocus(scopeRef, autoFocus);\n\n // This needs to be an effect so that activeScope is updated after the FocusScope tree is complete.\n // It cannot be a useLayoutEffect because the parent of this node hasn't been attached in the tree yet.\n useEffect(() => {\n const activeElement = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement;\n let scope: TreeNode | null = null;\n\n if (isElementInScope(activeElement, scopeRef.current)) {\n // We need to traverse the focusScope tree and find the bottom most scope that\n // contains the active element and set that as the activeScope.\n for (let node of focusScopeTree.traverse()) {\n if (node.scopeRef && isElementInScope(activeElement, node.scopeRef.current)) {\n scope = node;\n }\n }\n\n if (scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n }, [scopeRef]);\n\n // This layout effect cleanup is so that the tree node is removed synchronously with react before the RAF\n // in useRestoreFocus cleanup runs.\n useLayoutEffect(() => {\n return () => {\n // Scope may have been re-parented.\n let parentScope = focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n focusScopeTree.removeTreeNode(scopeRef);\n };\n }, [scopeRef]);\n\n let focusManager = useMemo(() => createFocusManagerForScope(scopeRef), []);\n let value = useMemo(() => ({\n focusManager,\n parentNode: node\n }), [node, focusManager]);\n\n return (\n <FocusContext.Provider value={value}>\n <span data-focus-scope-start hidden ref={startRef} />\n {children}\n <span data-focus-scope-end hidden ref={endRef} />\n </FocusContext.Provider>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function useFocusManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = sentinel;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[scope.length - 1].nextElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = sentinel;\n previousNode = walker.previousNode() as FocusableElement;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n },\n focusFirst(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[0].previousElementSibling!;\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[scope.length - 1].nextElementSibling!;\n let previousNode = walker.previousNode() as FocusableElement;\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n }\n };\n}\n\nconst focusableElements = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]'\n];\n\nconst FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';\n\nfocusableElements.push('[tabindex]:not([tabindex=\"-1\"]):not([disabled])');\nconst TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex=\"-1\"]),');\n\nexport function isFocusable(element: HTMLElement) {\n return element.matches(FOCUSABLE_ELEMENT_SELECTOR);\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return scope[0].parentElement!;\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: boolean) {\n let focusedNode = useRef<FocusableElement>(undefined);\n\n let raf = useRef<ReturnType<typeof requestAnimationFrame>>(undefined);\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n if (!contain) {\n // if contain was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n raf.current = undefined;\n }\n return;\n }\n\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n // Handle the Tab key to contain focus within the scope\n let onKeyDown = (e) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement;\n let scope = scopeRef.current;\n if (!scope || !isElementInScope(focusedElement, scope)) {\n return;\n }\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable: true}, scope);\n if (!focusedElement) {\n return;\n }\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n if (!nextElement) {\n walker.currentNode = e.shiftKey ? scope[scope.length - 1].nextElementSibling! : scope[0].previousElementSibling!;\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n }\n\n e.preventDefault();\n if (nextElement) {\n focusElement(nextElement, true);\n }\n };\n\n let onFocus = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) && isElementInScope(e.target, scopeRef.current)) {\n activeScope = scopeRef;\n focusedNode.current = e.target;\n } else if (shouldContainFocus(scopeRef) && !isElementInChildScope(e.target, scopeRef)) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode.current) {\n focusedNode.current.focus();\n } else if (activeScope && activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode.current = e.target;\n }\n };\n\n let onBlur = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n raf.current = requestAnimationFrame(() => {\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n if (ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {\n activeScope = scopeRef;\n if (ownerDocument.body.contains(e.target)) {\n focusedNode.current = e.target;\n focusedNode.current?.focus();\n } else if (activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n }\n });\n };\n\n ownerDocument.addEventListener('keydown', onKeyDown, false);\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.addEventListener('focusout', onBlur, false));\n return () => {\n ownerDocument.removeEventListener('keydown', onKeyDown, false);\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.removeEventListener('focusout', onBlur, false));\n };\n }, [scopeRef, contain]);\n\n // This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur\n\n useLayoutEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, [raf]);\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n if (!scope) {\n return false;\n }\n return scope.some(node => node.contains(element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {\n if (s && isElementInScope(element, s.current)) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element) {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (element != null && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (element != null) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(scope: Element[], tabbable = true) {\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n return nextNode as FocusableElement;\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable:boolean = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {\n const autoFocusRef = React.useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n if (!isElementInScope(ownerDocument.activeElement, activeScope.current) && scopeRef.current) {\n focusFirstInScope(scopeRef.current);\n }\n }\n autoFocusRef.current = false;\n }, [scopeRef]);\n}\n\nfunction useActiveScopeTracker(scopeRef: RefObject<Element[] | null>, restore?: boolean, contain?: boolean) {\n // tracks the active scope, in case restore and contain are both false.\n // if either are true, this is tracked in useRestoreFocus or useFocusContainment.\n useLayoutEffect(() => {\n if (restore || contain) {\n return;\n }\n\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n let onFocus = (e) => {\n let target = e.target as Element;\n if (isElementInScope(target, scopeRef.current)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n }, [scopeRef, restore, contain]);\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction useRestoreFocus(scopeRef: RefObject<Element[] | null>, restoreFocus?: boolean, contain?: boolean) {\n // create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.\n // eslint-disable-next-line no-restricted-globals\n const nodeToRestoreRef = useRef(typeof document !== 'undefined' ? getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement as FocusableElement : null);\n\n // restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n if (!restoreFocus || contain) {\n return;\n }\n\n let onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(ownerDocument.activeElement, scopeRef.current)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scopeRef, contain]);\n\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement as FocusableElement;\n if (!isElementInChildScope(focusedElement, scopeRef) || !shouldRestoreFocus(scopeRef)) {\n return;\n }\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // Create a DOM tree walker that matches all tabbable elements\n let walker = getFocusableTreeWalker(ownerDocument.body, {tabbable: true});\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n\n if (!nodeToRestore || !ownerDocument.body.contains(nodeToRestore) || nodeToRestore === ownerDocument.body) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if ((!nextElement || !isElementInChildScope(nextElement, scopeRef)) && nodeToRestore) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n } while (isElementInChildScope(nextElement, scopeRef));\n\n e.preventDefault();\n e.stopPropagation();\n if (nextElement) {\n focusElement(nextElement, true);\n } else {\n // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)\n // then move focus to the body.\n // Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)\n if (!isElementInAnyScope(nodeToRestore)) {\n focusedElement.blur();\n } else {\n focusElement(nodeToRestore, true);\n }\n }\n }\n };\n\n if (!contain) {\n ownerDocument.addEventListener('keydown', onKeyDown, true);\n }\n\n return () => {\n if (!contain) {\n ownerDocument.removeEventListener('keydown', onKeyDown, true);\n }\n };\n }, [scopeRef, restoreFocus, contain]);\n\n // useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n treeNode.nodeToRestore = nodeToRestoreRef.current ?? undefined;\n return () => {\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n if (\n restoreFocus\n && nodeToRestore\n && (\n ((ownerDocument.activeElement && isElementInChildScope(ownerDocument.activeElement, scopeRef)) || (ownerDocument.activeElement === ownerDocument.body && shouldRestoreFocus(scopeRef)))\n )\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n let clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.nodeToRestore && treeNode.nodeToRestore.isConnected) {\n restoreFocusToElement(treeNode.nodeToRestore);\n return;\n }\n treeNode = treeNode.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.scopeRef && treeNode.scopeRef.current && focusScopeTree.getTreeNode(treeNode.scopeRef)) {\n let node = getFirstInScope(treeNode.scopeRef.current, true);\n restoreFocusToElement(node);\n return;\n }\n treeNode = treeNode.parent;\n }\n }\n });\n }\n };\n }, [scopeRef, restoreFocus]);\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (node.dispatchEvent(new CustomEvent(RESTORE_FOCUS_EVENT, {bubbles: true, cancelable: true}))) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[]) {\n let selector = opts?.tabbable ? TABBABLE_ELEMENT_SELECTOR : FOCUSABLE_ELEMENT_SELECTOR;\n let walker = getOwnerDocument(root).createTreeWalker(\n root,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (opts?.from?.contains(node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if ((node as Element).matches(selector)\n && isElementVisible(node as Element)\n && (!scope || isElementInScope(node as Element, scope))\n && (!opts?.accept || opts.accept(node as Element))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n }\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(ref: RefObject<Element | null>, defaultOptions: FocusManagerOptions = {}): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n }\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = root;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n } else {\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = root;\n let lastNode = last(walker);\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n previousNode = lastNode;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode ?? null;\n },\n focusFirst(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\n\nclass Tree {\n root: TreeNode;\n private fastMap = new Map<ScopeRef, TreeNode>();\n\n constructor() {\n this.root = new TreeNode({scopeRef: null});\n this.fastMap.set(null, this.root);\n }\n\n get size() {\n return this.fastMap.size;\n }\n\n getTreeNode(data: ScopeRef) {\n return this.fastMap.get(data);\n }\n\n addTreeNode(scopeRef: ScopeRef, parent: ScopeRef, nodeToRestore?: FocusableElement) {\n let parentNode = this.fastMap.get(parent ?? null);\n if (!parentNode) {\n return;\n }\n let node = new TreeNode({scopeRef});\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n\n addNode(node: TreeNode) {\n this.fastMap.set(node.scopeRef, node);\n }\n\n removeTreeNode(scopeRef: ScopeRef) {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n let node = this.fastMap.get(scopeRef);\n if (!node) {\n return;\n }\n let parentNode = node.parent;\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (let current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef.current &&\n isElementInScope(current.nodeToRestore, node.scopeRef.current)\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n let children = node.children;\n if (parentNode) {\n parentNode.removeChild(node);\n if (children.size > 0) {\n children.forEach(child => parentNode && parentNode.addChild(child));\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (node.scopeRef != null) {\n yield node;\n }\n if (node.children.size > 0) {\n for (let child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n\n clone(): Tree {\n let newTree = new Tree();\n for (let node of this.traverse()) {\n newTree.addTreeNode(node.scopeRef, node.parent?.scopeRef ?? null, node.nodeToRestore);\n }\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children: Set<TreeNode> = new Set();\n public contain = false;\n\n constructor(props: {scopeRef: ScopeRef}) {\n this.scopeRef = props.scopeRef;\n }\n addChild(node: TreeNode) {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode) {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport let focusScopeTree = new T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,UAAU,IAAI;YAEmB;QADrC,KAAK,IAAI,QAAQ,IAAI,CAAC,QAAQ,GAC5B,QAAQ,WAAW,CAAC,KAAK,QAAQ,EAAE,CAAA,yBAAA,eAAA,KAAK,MAAM,cAAX,mCAAA,aAAa,QAAQ,cAArB,mCAAA,wBAAyB,MAAM,KAAK,aAAa;QAEtF,OAAO;IACT;IApFA,aAAc;aAFN,UAAU,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,+BAAS;YAAC,UAAU;QAAI;QACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI;IAClC;AAkFF;AAEA,MAAM;IAUJ,SAAS,IAAc,EAAE;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAClB,KAAK,MAAM,GAAG,IAAI;IACpB;IACA,YAAY,IAAc,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,MAAM,GAAG;IAChB;IAVA,YAAY,KAA2B,CAAE;aAHlC,WAA0B,IAAI;aAC9B,UAAU;QAGf,IAAI,CAAC,QAAQ,GAAG,MAAM,QAAQ;IAChC;AASF;AAEO,IAAI,4CAAiB,IAAI","sources":["packages/@react-aria/focus/src/FocusScope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusSafely} from './focusSafely';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {getOwnerDocument, isAndroid, isChrome, useLayoutEffect} from '@react-aria/utils';\nimport {isElementVisible} from './isElementVisible';\nimport React, {ReactNode, useContext, useEffect, useMemo, useRef} from 'react';\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: ReactNode,\n\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean,\n\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean,\n\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element,\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean,\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean,\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast(opts?: FocusManagerOptions): FocusableElement | null\n}\n\ntype ScopeRef = RefObject<Element[] | null> | null;\ninterface IFocusContext {\n focusManager: FocusManager,\n parentNode: TreeNode | null\n}\n\nconst FocusContext = React.createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';\n\nlet activeScope: ScopeRef = null;\n\n// This is a hacky DOM-based implementation of a FocusScope until this RFC lands in React:\n// https://github.com/reactjs/rfcs/pull/109\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nexport function FocusScope(props: FocusScopeProps) {\n let {children, contain, restoreFocus, autoFocus} = props;\n let startRef = useRef<HTMLSpanElement>(null);\n let endRef = useRef<HTMLSpanElement>(null);\n let scopeRef = useRef<Element[]>([]);\n let {parentNode} = useContext(FocusContext) || {};\n\n // Create a tree node here so we can add children to it even before it is added to the tree.\n let node = useMemo(() => new TreeNode({scopeRef}), [scopeRef]);\n\n useLayoutEffect(() => {\n // If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),\n // use the active scope as the parent instead of the parent from context. Layout effects run bottom\n // up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope\n // that is being added should get the activeScope as its parent.\n let parent = parentNode || focusScopeTree.root;\n if (focusScopeTree.getTreeNode(parent.scopeRef) && activeScope && !isAncestorScope(activeScope, parent.scopeRef)) {\n let activeNode = focusScopeTree.getTreeNode(activeScope);\n if (activeNode) {\n parent = activeNode;\n }\n }\n\n // Add the node to the parent, and to the tree.\n parent.addChild(node);\n focusScopeTree.addNode(node);\n }, [node, parentNode]);\n\n useLayoutEffect(() => {\n let node = focusScopeTree.getTreeNode(scopeRef);\n if (node) {\n node.contain = !!contain;\n }\n }, [contain]);\n\n useLayoutEffect(() => {\n // Find all rendered nodes between the sentinels and add them to the scope.\n let node = startRef.current?.nextSibling!;\n let nodes: Element[] = [];\n let stopPropagation = e => e.stopPropagation();\n while (node && node !== endRef.current) {\n nodes.push(node as Element);\n // Stop custom restore focus event from propagating to parent focus scopes.\n node.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n node = node.nextSibling as Element;\n }\n\n scopeRef.current = nodes;\n\n return () => {\n for (let node of nodes) {\n node.removeEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n };\n }, [children]);\n\n useActiveScopeTracker(scopeRef, restoreFocus, contain);\n useFocusContainment(scopeRef, contain);\n useRestoreFocus(scopeRef, restoreFocus, contain);\n useAutoFocus(scopeRef, autoFocus);\n\n // This needs to be an effect so that activeScope is updated after the FocusScope tree is complete.\n // It cannot be a useLayoutEffect because the parent of this node hasn't been attached in the tree yet.\n useEffect(() => {\n const activeElement = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement;\n let scope: TreeNode | null = null;\n\n if (isElementInScope(activeElement, scopeRef.current)) {\n // We need to traverse the focusScope tree and find the bottom most scope that\n // contains the active element and set that as the activeScope.\n for (let node of focusScopeTree.traverse()) {\n if (node.scopeRef && isElementInScope(activeElement, node.scopeRef.current)) {\n scope = node;\n }\n }\n\n if (scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n }, [scopeRef]);\n\n // This layout effect cleanup is so that the tree node is removed synchronously with react before the RAF\n // in useRestoreFocus cleanup runs.\n useLayoutEffect(() => {\n return () => {\n // Scope may have been re-parented.\n let parentScope = focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n focusScopeTree.removeTreeNode(scopeRef);\n };\n }, [scopeRef]);\n\n let focusManager = useMemo(() => createFocusManagerForScope(scopeRef), []);\n let value = useMemo(() => ({\n focusManager,\n parentNode: node\n }), [node, focusManager]);\n\n return (\n <FocusContext.Provider value={value}>\n <span data-focus-scope-start hidden ref={startRef} />\n {children}\n <span data-focus-scope-end hidden ref={endRef} />\n </FocusContext.Provider>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function useFocusManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = sentinel;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[scope.length - 1].nextElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = sentinel;\n previousNode = walker.previousNode() as FocusableElement;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n },\n focusFirst(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[0].previousElementSibling!;\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[scope.length - 1].nextElementSibling!;\n let previousNode = walker.previousNode() as FocusableElement;\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n }\n };\n}\n\nconst focusableElements = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable^=\"false\"])'\n];\n\nconst FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';\n\nfocusableElements.push('[tabindex]:not([tabindex=\"-1\"]):not([disabled])');\nconst TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex=\"-1\"]),');\n\nexport function isFocusable(element: HTMLElement) {\n return element.matches(FOCUSABLE_ELEMENT_SELECTOR);\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return scope[0].parentElement!;\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: boolean) {\n let focusedNode = useRef<FocusableElement>(undefined);\n\n let raf = useRef<ReturnType<typeof requestAnimationFrame>>(undefined);\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n if (!contain) {\n // if contain was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n raf.current = undefined;\n }\n return;\n }\n\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n // Handle the Tab key to contain focus within the scope\n let onKeyDown = (e) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement;\n let scope = scopeRef.current;\n if (!scope || !isElementInScope(focusedElement, scope)) {\n return;\n }\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable: true}, scope);\n if (!focusedElement) {\n return;\n }\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n if (!nextElement) {\n walker.currentNode = e.shiftKey ? scope[scope.length - 1].nextElementSibling! : scope[0].previousElementSibling!;\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n }\n\n e.preventDefault();\n if (nextElement) {\n focusElement(nextElement, true);\n }\n };\n\n let onFocus = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) && isElementInScope(e.target, scopeRef.current)) {\n activeScope = scopeRef;\n focusedNode.current = e.target;\n } else if (shouldContainFocus(scopeRef) && !isElementInChildScope(e.target, scopeRef)) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode.current) {\n focusedNode.current.focus();\n } else if (activeScope && activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode.current = e.target;\n }\n };\n\n let onBlur = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n raf.current = requestAnimationFrame(() => {\n // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor\n // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.\n // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.\n let modality = getInteractionModality();\n let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && isAndroid() && isChrome();\n\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n if (!shouldSkipFocusRestore && ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {\n activeScope = scopeRef;\n if (ownerDocument.body.contains(e.target)) {\n focusedNode.current = e.target;\n focusedNode.current?.focus();\n } else if (activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n }\n });\n };\n\n ownerDocument.addEventListener('keydown', onKeyDown, false);\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.addEventListener('focusout', onBlur, false));\n return () => {\n ownerDocument.removeEventListener('keydown', onKeyDown, false);\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.removeEventListener('focusout', onBlur, false));\n };\n }, [scopeRef, contain]);\n\n // This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur\n\n useLayoutEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, [raf]);\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n if (!scope) {\n return false;\n }\n return scope.some(node => node.contains(element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {\n if (s && isElementInScope(element, s.current)) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element) {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (element != null && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (element != null) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(scope: Element[], tabbable = true) {\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n return nextNode as FocusableElement;\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable:boolean = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {\n const autoFocusRef = React.useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n if (!isElementInScope(ownerDocument.activeElement, activeScope.current) && scopeRef.current) {\n focusFirstInScope(scopeRef.current);\n }\n }\n autoFocusRef.current = false;\n }, [scopeRef]);\n}\n\nfunction useActiveScopeTracker(scopeRef: RefObject<Element[] | null>, restore?: boolean, contain?: boolean) {\n // tracks the active scope, in case restore and contain are both false.\n // if either are true, this is tracked in useRestoreFocus or useFocusContainment.\n useLayoutEffect(() => {\n if (restore || contain) {\n return;\n }\n\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n let onFocus = (e) => {\n let target = e.target as Element;\n if (isElementInScope(target, scopeRef.current)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n }, [scopeRef, restore, contain]);\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction useRestoreFocus(scopeRef: RefObject<Element[] | null>, restoreFocus?: boolean, contain?: boolean) {\n // create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.\n // eslint-disable-next-line no-restricted-globals\n const nodeToRestoreRef = useRef(typeof document !== 'undefined' ? getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement as FocusableElement : null);\n\n // restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n if (!restoreFocus || contain) {\n return;\n }\n\n let onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(ownerDocument.activeElement, scopeRef.current)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scopeRef, contain]);\n\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement as FocusableElement;\n if (!isElementInChildScope(focusedElement, scopeRef) || !shouldRestoreFocus(scopeRef)) {\n return;\n }\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // Create a DOM tree walker that matches all tabbable elements\n let walker = getFocusableTreeWalker(ownerDocument.body, {tabbable: true});\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n\n if (!nodeToRestore || !ownerDocument.body.contains(nodeToRestore) || nodeToRestore === ownerDocument.body) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if ((!nextElement || !isElementInChildScope(nextElement, scopeRef)) && nodeToRestore) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n } while (isElementInChildScope(nextElement, scopeRef));\n\n e.preventDefault();\n e.stopPropagation();\n if (nextElement) {\n focusElement(nextElement, true);\n } else {\n // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)\n // then move focus to the body.\n // Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)\n if (!isElementInAnyScope(nodeToRestore)) {\n focusedElement.blur();\n } else {\n focusElement(nodeToRestore, true);\n }\n }\n }\n };\n\n if (!contain) {\n ownerDocument.addEventListener('keydown', onKeyDown, true);\n }\n\n return () => {\n if (!contain) {\n ownerDocument.removeEventListener('keydown', onKeyDown, true);\n }\n };\n }, [scopeRef, restoreFocus, contain]);\n\n // useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n treeNode.nodeToRestore = nodeToRestoreRef.current ?? undefined;\n return () => {\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n if (\n restoreFocus\n && nodeToRestore\n && (\n ((ownerDocument.activeElement && isElementInChildScope(ownerDocument.activeElement, scopeRef)) || (ownerDocument.activeElement === ownerDocument.body && shouldRestoreFocus(scopeRef)))\n )\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n let clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.nodeToRestore && treeNode.nodeToRestore.isConnected) {\n restoreFocusToElement(treeNode.nodeToRestore);\n return;\n }\n treeNode = treeNode.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.scopeRef && treeNode.scopeRef.current && focusScopeTree.getTreeNode(treeNode.scopeRef)) {\n let node = getFirstInScope(treeNode.scopeRef.current, true);\n restoreFocusToElement(node);\n return;\n }\n treeNode = treeNode.parent;\n }\n }\n });\n }\n };\n }, [scopeRef, restoreFocus]);\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (node.dispatchEvent(new CustomEvent(RESTORE_FOCUS_EVENT, {bubbles: true, cancelable: true}))) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[]) {\n let selector = opts?.tabbable ? TABBABLE_ELEMENT_SELECTOR : FOCUSABLE_ELEMENT_SELECTOR;\n let walker = getOwnerDocument(root).createTreeWalker(\n root,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (opts?.from?.contains(node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if ((node as Element).matches(selector)\n && isElementVisible(node as Element)\n && (!scope || isElementInScope(node as Element, scope))\n && (!opts?.accept || opts.accept(node as Element))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n }\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(ref: RefObject<Element | null>, defaultOptions: FocusManagerOptions = {}): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n }\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = root;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n } else {\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = root;\n let lastNode = last(walker);\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n previousNode = lastNode;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode ?? null;\n },\n focusFirst(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\n\nclass Tree {\n root: TreeNode;\n private fastMap = new Map<ScopeRef, TreeNode>();\n\n constructor() {\n this.root = new TreeNode({scopeRef: null});\n this.fastMap.set(null, this.root);\n }\n\n get size() {\n return this.fastMap.size;\n }\n\n getTreeNode(data: ScopeRef) {\n return this.fastMap.get(data);\n }\n\n addTreeNode(scopeRef: ScopeRef, parent: ScopeRef, nodeToRestore?: FocusableElement) {\n let parentNode = this.fastMap.get(parent ?? null);\n if (!parentNode) {\n return;\n }\n let node = new TreeNode({scopeRef});\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n\n addNode(node: TreeNode) {\n this.fastMap.set(node.scopeRef, node);\n }\n\n removeTreeNode(scopeRef: ScopeRef) {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n let node = this.fastMap.get(scopeRef);\n if (!node) {\n return;\n }\n let parentNode = node.parent;\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (let current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef.current &&\n isElementInScope(current.nodeToRestore, node.scopeRef.current)\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n let children = node.children;\n if (parentNode) {\n parentNode.removeChild(node);\n if (children.size > 0) {\n children.forEach(child => parentNode && parentNode.addChild(child));\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (node.scopeRef != null) {\n yield node;\n }\n if (node.children.size > 0) {\n for (let child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n\n clone(): Tree {\n let newTree = new Tree();\n for (let node of this.traverse()) {\n newTree.addTreeNode(node.scopeRef, node.parent?.scopeRef ?? null, node.nodeToRestore);\n }\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children: Set<TreeNode> = new Set();\n public contain = false;\n\n constructor(props: {scopeRef: ScopeRef}) {\n this.scopeRef = props.scopeRef;\n }\n addChild(node: TreeNode) {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode) {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport let focusScopeTree = new Tree();\n"],"names":[],"version":3,"file":"FocusScope.main.js.map"}
@@ -1,6 +1,7 @@
1
1
  import {focusSafely as $6a99195332edec8b$export$80f3e147d781571c} from "./focusSafely.mjs";
2
2
  import {isElementVisible as $645f2e67b85a24c9$export$e989c0fffaa6b27a} from "./isElementVisible.mjs";
3
- import {useLayoutEffect as $cgawC$useLayoutEffect, getOwnerDocument as $cgawC$getOwnerDocument} from "@react-aria/utils";
3
+ import {getInteractionModality as $cgawC$getInteractionModality} from "@react-aria/interactions";
4
+ import {useLayoutEffect as $cgawC$useLayoutEffect, getOwnerDocument as $cgawC$getOwnerDocument, isAndroid as $cgawC$isAndroid, isChrome as $cgawC$isChrome} from "@react-aria/utils";
4
5
  import $cgawC$react, {useRef as $cgawC$useRef, useContext as $cgawC$useContext, useMemo as $cgawC$useMemo, useEffect as $cgawC$useEffect} from "react";
5
6
 
6
7
  /*
@@ -17,6 +18,7 @@ import $cgawC$react, {useRef as $cgawC$useRef, useContext as $cgawC$useContext,
17
18
 
18
19
 
19
20
 
21
+
20
22
  const $9bf71ea28793e738$var$FocusContext = /*#__PURE__*/ (0, $cgawC$react).createContext(null);
21
23
  const $9bf71ea28793e738$var$RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';
22
24
  let $9bf71ea28793e738$var$activeScope = null;
@@ -211,7 +213,7 @@ const $9bf71ea28793e738$var$focusableElements = [
211
213
  'embed',
212
214
  'audio[controls]',
213
215
  'video[controls]',
214
- '[contenteditable]'
216
+ '[contenteditable]:not([contenteditable^="false"])'
215
217
  ];
216
218
  const $9bf71ea28793e738$var$FOCUSABLE_ELEMENT_SELECTOR = $9bf71ea28793e738$var$focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
217
219
  $9bf71ea28793e738$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
@@ -281,8 +283,13 @@ function $9bf71ea28793e738$var$useFocusContainment(scopeRef, contain) {
281
283
  // Firefox doesn't shift focus back to the Dialog properly without this
282
284
  if (raf.current) cancelAnimationFrame(raf.current);
283
285
  raf.current = requestAnimationFrame(()=>{
286
+ // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor
287
+ // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.
288
+ // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.
289
+ let modality = (0, $cgawC$getInteractionModality)();
290
+ let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && (0, $cgawC$isAndroid)() && (0, $cgawC$isChrome)();
284
291
  // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
285
- if (ownerDocument.activeElement && $9bf71ea28793e738$var$shouldContainFocus(scopeRef) && !$9bf71ea28793e738$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
292
+ if (!shouldSkipFocusRestore && ownerDocument.activeElement && $9bf71ea28793e738$var$shouldContainFocus(scopeRef) && !$9bf71ea28793e738$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
286
293
  $9bf71ea28793e738$var$activeScope = scopeRef;
287
294
  if (ownerDocument.body.contains(e.target)) {
288
295
  var _focusedNode_current;
@@ -1,6 +1,7 @@
1
1
  import {focusSafely as $6a99195332edec8b$export$80f3e147d781571c} from "./focusSafely.module.js";
2
2
  import {isElementVisible as $645f2e67b85a24c9$export$e989c0fffaa6b27a} from "./isElementVisible.module.js";
3
- import {useLayoutEffect as $cgawC$useLayoutEffect, getOwnerDocument as $cgawC$getOwnerDocument} from "@react-aria/utils";
3
+ import {getInteractionModality as $cgawC$getInteractionModality} from "@react-aria/interactions";
4
+ import {useLayoutEffect as $cgawC$useLayoutEffect, getOwnerDocument as $cgawC$getOwnerDocument, isAndroid as $cgawC$isAndroid, isChrome as $cgawC$isChrome} from "@react-aria/utils";
4
5
  import $cgawC$react, {useRef as $cgawC$useRef, useContext as $cgawC$useContext, useMemo as $cgawC$useMemo, useEffect as $cgawC$useEffect} from "react";
5
6
 
6
7
  /*
@@ -17,6 +18,7 @@ import $cgawC$react, {useRef as $cgawC$useRef, useContext as $cgawC$useContext,
17
18
 
18
19
 
19
20
 
21
+
20
22
  const $9bf71ea28793e738$var$FocusContext = /*#__PURE__*/ (0, $cgawC$react).createContext(null);
21
23
  const $9bf71ea28793e738$var$RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';
22
24
  let $9bf71ea28793e738$var$activeScope = null;
@@ -211,7 +213,7 @@ const $9bf71ea28793e738$var$focusableElements = [
211
213
  'embed',
212
214
  'audio[controls]',
213
215
  'video[controls]',
214
- '[contenteditable]'
216
+ '[contenteditable]:not([contenteditable^="false"])'
215
217
  ];
216
218
  const $9bf71ea28793e738$var$FOCUSABLE_ELEMENT_SELECTOR = $9bf71ea28793e738$var$focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
217
219
  $9bf71ea28793e738$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
@@ -281,8 +283,13 @@ function $9bf71ea28793e738$var$useFocusContainment(scopeRef, contain) {
281
283
  // Firefox doesn't shift focus back to the Dialog properly without this
282
284
  if (raf.current) cancelAnimationFrame(raf.current);
283
285
  raf.current = requestAnimationFrame(()=>{
286
+ // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor
287
+ // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.
288
+ // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.
289
+ let modality = (0, $cgawC$getInteractionModality)();
290
+ let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && (0, $cgawC$isAndroid)() && (0, $cgawC$isChrome)();
284
291
  // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
285
- if (ownerDocument.activeElement && $9bf71ea28793e738$var$shouldContainFocus(scopeRef) && !$9bf71ea28793e738$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
292
+ if (!shouldSkipFocusRestore && ownerDocument.activeElement && $9bf71ea28793e738$var$shouldContainFocus(scopeRef) && !$9bf71ea28793e738$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
286
293
  $9bf71ea28793e738$var$activeScope = scopeRef;
287
294
  if (ownerDocument.body.contains(e.target)) {
288
295
  var _focusedNode_current;
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAwDD,MAAM,mDAAe,CAAA,GAAA,YAAI,EAAE,aAAa,CAAuB;AAC/D,MAAM,4CAAsB;AAE5B,IAAI,oCAAwB;AAYrB,SAAS,0CAAW,KAAsB;IAC/C,IAAI,YAAC,QAAQ,WAAE,OAAO,gBAAE,YAAY,aAAE,SAAS,EAAC,GAAG;IACnD,IAAI,WAAW,CAAA,GAAA,aAAK,EAAmB;IACvC,IAAI,SAAS,CAAA,GAAA,aAAK,EAAmB;IACrC,IAAI,WAAW,CAAA,GAAA,aAAK,EAAa,EAAE;IACnC,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,iBAAS,EAAE,uCAAiB,CAAC;IAEhD,4FAA4F;IAC5F,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,+BAAS;sBAAC;QAAQ,IAAI;QAAC;KAAS;IAE7D,CAAA,GAAA,sBAAc,EAAE;QACd,+FAA+F;QAC/F,mGAAmG;QACnG,mGAAmG;QACnG,gEAAgE;QAChE,IAAI,SAAS,cAAc,0CAAe,IAAI;QAC9C,IAAI,0CAAe,WAAW,CAAC,OAAO,QAAQ,KAAK,qCAAe,CAAC,sCAAgB,mCAAa,OAAO,QAAQ,GAAG;YAChH,IAAI,aAAa,0CAAe,WAAW,CAAC;YAC5C,IAAI,YACF,SAAS;QAEb;QAEA,+CAA+C;QAC/C,OAAO,QAAQ,CAAC;QAChB,0CAAe,OAAO,CAAC;IACzB,GAAG;QAAC;QAAM;KAAW;IAErB,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,OAAO,0CAAe,WAAW,CAAC;QACtC,IAAI,MACF,KAA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EAAE,CAAA,yBAAA,eAAA,KAAK,MAAM,cAAX,mCAAA,aAAa,QAAQ,cAArB,mCAAA,wBAAyB,MAAM,KAAK,aAAa;QAEtF,OAAO;IACT;IApFA,aAAc;aAFN,UAAU,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,+BAAS;YAAC,UAAU;QAAI;QACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI;IAClC;AAkFF;AAEA,MAAM;IAUJ,SAAS,IAAc,EAAE;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAClB,KAAK,MAAM,GAAG,IAAI;IACpB;IACA,YAAY,IAAc,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,MAAM,GAAG;IAChB;IAVA,YAAY,KAA2B,CAAE;aAHlC,WAA0B,IAAI;aAC9B,UAAU;QAGf,IAAI,CAAC,QAAQ,GAAG,MAAM,QAAQ;IAChC;AASF;AAEO,IAAI,4CAAiB,IAAI","sources":["packages/@react-aria/focus/src/FocusScope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusSafely} from './focusSafely';\nimport {getOwnerDocument, useLayoutEffect} from '@react-aria/utils';\nimport {isElementVisible} from './isElementVisible';\nimport React, {ReactNode, useContext, useEffect, useMemo, useRef} from 'react';\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: ReactNode,\n\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean,\n\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean,\n\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element,\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean,\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean,\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast(opts?: FocusManagerOptions): FocusableElement | null\n}\n\ntype ScopeRef = RefObject<Element[] | null> | null;\ninterface IFocusContext {\n focusManager: FocusManager,\n parentNode: TreeNode | null\n}\n\nconst FocusContext = React.createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';\n\nlet activeScope: ScopeRef = null;\n\n// This is a hacky DOM-based implementation of a FocusScope until this RFC lands in React:\n// https://github.com/reactjs/rfcs/pull/109\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nexport function FocusScope(props: FocusScopeProps) {\n let {children, contain, restoreFocus, autoFocus} = props;\n let startRef = useRef<HTMLSpanElement>(null);\n let endRef = useRef<HTMLSpanElement>(null);\n let scopeRef = useRef<Element[]>([]);\n let {parentNode} = useContext(FocusContext) || {};\n\n // Create a tree node here so we can add children to it even before it is added to the tree.\n let node = useMemo(() => new TreeNode({scopeRef}), [scopeRef]);\n\n useLayoutEffect(() => {\n // If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),\n // use the active scope as the parent instead of the parent from context. Layout effects run bottom\n // up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope\n // that is being added should get the activeScope as its parent.\n let parent = parentNode || focusScopeTree.root;\n if (focusScopeTree.getTreeNode(parent.scopeRef) && activeScope && !isAncestorScope(activeScope, parent.scopeRef)) {\n let activeNode = focusScopeTree.getTreeNode(activeScope);\n if (activeNode) {\n parent = activeNode;\n }\n }\n\n // Add the node to the parent, and to the tree.\n parent.addChild(node);\n focusScopeTree.addNode(node);\n }, [node, parentNode]);\n\n useLayoutEffect(() => {\n let node = focusScopeTree.getTreeNode(scopeRef);\n if (node) {\n node.contain = !!contain;\n }\n }, [contain]);\n\n useLayoutEffect(() => {\n // Find all rendered nodes between the sentinels and add them to the scope.\n let node = startRef.current?.nextSibling!;\n let nodes: Element[] = [];\n let stopPropagation = e => e.stopPropagation();\n while (node && node !== endRef.current) {\n nodes.push(node as Element);\n // Stop custom restore focus event from propagating to parent focus scopes.\n node.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n node = node.nextSibling as Element;\n }\n\n scopeRef.current = nodes;\n\n return () => {\n for (let node of nodes) {\n node.removeEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n };\n }, [children]);\n\n useActiveScopeTracker(scopeRef, restoreFocus, contain);\n useFocusContainment(scopeRef, contain);\n useRestoreFocus(scopeRef, restoreFocus, contain);\n useAutoFocus(scopeRef, autoFocus);\n\n // This needs to be an effect so that activeScope is updated after the FocusScope tree is complete.\n // It cannot be a useLayoutEffect because the parent of this node hasn't been attached in the tree yet.\n useEffect(() => {\n const activeElement = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement;\n let scope: TreeNode | null = null;\n\n if (isElementInScope(activeElement, scopeRef.current)) {\n // We need to traverse the focusScope tree and find the bottom most scope that\n // contains the active element and set that as the activeScope.\n for (let node of focusScopeTree.traverse()) {\n if (node.scopeRef && isElementInScope(activeElement, node.scopeRef.current)) {\n scope = node;\n }\n }\n\n if (scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n }, [scopeRef]);\n\n // This layout effect cleanup is so that the tree node is removed synchronously with react before the RAF\n // in useRestoreFocus cleanup runs.\n useLayoutEffect(() => {\n return () => {\n // Scope may have been re-parented.\n let parentScope = focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n focusScopeTree.removeTreeNode(scopeRef);\n };\n }, [scopeRef]);\n\n let focusManager = useMemo(() => createFocusManagerForScope(scopeRef), []);\n let value = useMemo(() => ({\n focusManager,\n parentNode: node\n }), [node, focusManager]);\n\n return (\n <FocusContext.Provider value={value}>\n <span data-focus-scope-start hidden ref={startRef} />\n {children}\n <span data-focus-scope-end hidden ref={endRef} />\n </FocusContext.Provider>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function useFocusManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = sentinel;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[scope.length - 1].nextElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = sentinel;\n previousNode = walker.previousNode() as FocusableElement;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n },\n focusFirst(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[0].previousElementSibling!;\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[scope.length - 1].nextElementSibling!;\n let previousNode = walker.previousNode() as FocusableElement;\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n }\n };\n}\n\nconst focusableElements = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]'\n];\n\nconst FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';\n\nfocusableElements.push('[tabindex]:not([tabindex=\"-1\"]):not([disabled])');\nconst TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex=\"-1\"]),');\n\nexport function isFocusable(element: HTMLElement) {\n return element.matches(FOCUSABLE_ELEMENT_SELECTOR);\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return scope[0].parentElement!;\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: boolean) {\n let focusedNode = useRef<FocusableElement>(undefined);\n\n let raf = useRef<ReturnType<typeof requestAnimationFrame>>(undefined);\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n if (!contain) {\n // if contain was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n raf.current = undefined;\n }\n return;\n }\n\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n // Handle the Tab key to contain focus within the scope\n let onKeyDown = (e) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement;\n let scope = scopeRef.current;\n if (!scope || !isElementInScope(focusedElement, scope)) {\n return;\n }\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable: true}, scope);\n if (!focusedElement) {\n return;\n }\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n if (!nextElement) {\n walker.currentNode = e.shiftKey ? scope[scope.length - 1].nextElementSibling! : scope[0].previousElementSibling!;\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n }\n\n e.preventDefault();\n if (nextElement) {\n focusElement(nextElement, true);\n }\n };\n\n let onFocus = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) && isElementInScope(e.target, scopeRef.current)) {\n activeScope = scopeRef;\n focusedNode.current = e.target;\n } else if (shouldContainFocus(scopeRef) && !isElementInChildScope(e.target, scopeRef)) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode.current) {\n focusedNode.current.focus();\n } else if (activeScope && activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode.current = e.target;\n }\n };\n\n let onBlur = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n raf.current = requestAnimationFrame(() => {\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n if (ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {\n activeScope = scopeRef;\n if (ownerDocument.body.contains(e.target)) {\n focusedNode.current = e.target;\n focusedNode.current?.focus();\n } else if (activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n }\n });\n };\n\n ownerDocument.addEventListener('keydown', onKeyDown, false);\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.addEventListener('focusout', onBlur, false));\n return () => {\n ownerDocument.removeEventListener('keydown', onKeyDown, false);\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.removeEventListener('focusout', onBlur, false));\n };\n }, [scopeRef, contain]);\n\n // This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur\n\n useLayoutEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, [raf]);\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n if (!scope) {\n return false;\n }\n return scope.some(node => node.contains(element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {\n if (s && isElementInScope(element, s.current)) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element) {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (element != null && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (element != null) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(scope: Element[], tabbable = true) {\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n return nextNode as FocusableElement;\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable:boolean = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {\n const autoFocusRef = React.useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n if (!isElementInScope(ownerDocument.activeElement, activeScope.current) && scopeRef.current) {\n focusFirstInScope(scopeRef.current);\n }\n }\n autoFocusRef.current = false;\n }, [scopeRef]);\n}\n\nfunction useActiveScopeTracker(scopeRef: RefObject<Element[] | null>, restore?: boolean, contain?: boolean) {\n // tracks the active scope, in case restore and contain are both false.\n // if either are true, this is tracked in useRestoreFocus or useFocusContainment.\n useLayoutEffect(() => {\n if (restore || contain) {\n return;\n }\n\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n let onFocus = (e) => {\n let target = e.target as Element;\n if (isElementInScope(target, scopeRef.current)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n }, [scopeRef, restore, contain]);\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction useRestoreFocus(scopeRef: RefObject<Element[] | null>, restoreFocus?: boolean, contain?: boolean) {\n // create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.\n // eslint-disable-next-line no-restricted-globals\n const nodeToRestoreRef = useRef(typeof document !== 'undefined' ? getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement as FocusableElement : null);\n\n // restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n if (!restoreFocus || contain) {\n return;\n }\n\n let onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(ownerDocument.activeElement, scopeRef.current)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scopeRef, contain]);\n\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement as FocusableElement;\n if (!isElementInChildScope(focusedElement, scopeRef) || !shouldRestoreFocus(scopeRef)) {\n return;\n }\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // Create a DOM tree walker that matches all tabbable elements\n let walker = getFocusableTreeWalker(ownerDocument.body, {tabbable: true});\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n\n if (!nodeToRestore || !ownerDocument.body.contains(nodeToRestore) || nodeToRestore === ownerDocument.body) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if ((!nextElement || !isElementInChildScope(nextElement, scopeRef)) && nodeToRestore) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n } while (isElementInChildScope(nextElement, scopeRef));\n\n e.preventDefault();\n e.stopPropagation();\n if (nextElement) {\n focusElement(nextElement, true);\n } else {\n // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)\n // then move focus to the body.\n // Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)\n if (!isElementInAnyScope(nodeToRestore)) {\n focusedElement.blur();\n } else {\n focusElement(nodeToRestore, true);\n }\n }\n }\n };\n\n if (!contain) {\n ownerDocument.addEventListener('keydown', onKeyDown, true);\n }\n\n return () => {\n if (!contain) {\n ownerDocument.removeEventListener('keydown', onKeyDown, true);\n }\n };\n }, [scopeRef, restoreFocus, contain]);\n\n // useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n treeNode.nodeToRestore = nodeToRestoreRef.current ?? undefined;\n return () => {\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n if (\n restoreFocus\n && nodeToRestore\n && (\n ((ownerDocument.activeElement && isElementInChildScope(ownerDocument.activeElement, scopeRef)) || (ownerDocument.activeElement === ownerDocument.body && shouldRestoreFocus(scopeRef)))\n )\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n let clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.nodeToRestore && treeNode.nodeToRestore.isConnected) {\n restoreFocusToElement(treeNode.nodeToRestore);\n return;\n }\n treeNode = treeNode.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.scopeRef && treeNode.scopeRef.current && focusScopeTree.getTreeNode(treeNode.scopeRef)) {\n let node = getFirstInScope(treeNode.scopeRef.current, true);\n restoreFocusToElement(node);\n return;\n }\n treeNode = treeNode.parent;\n }\n }\n });\n }\n };\n }, [scopeRef, restoreFocus]);\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (node.dispatchEvent(new CustomEvent(RESTORE_FOCUS_EVENT, {bubbles: true, cancelable: true}))) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[]) {\n let selector = opts?.tabbable ? TABBABLE_ELEMENT_SELECTOR : FOCUSABLE_ELEMENT_SELECTOR;\n let walker = getOwnerDocument(root).createTreeWalker(\n root,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (opts?.from?.contains(node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if ((node as Element).matches(selector)\n && isElementVisible(node as Element)\n && (!scope || isElementInScope(node as Element, scope))\n && (!opts?.accept || opts.accept(node as Element))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n }\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(ref: RefObject<Element | null>, defaultOptions: FocusManagerOptions = {}): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n }\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = root;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n } else {\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = root;\n let lastNode = last(walker);\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n previousNode = lastNode;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode ?? null;\n },\n focusFirst(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\n\nclass Tree {\n root: TreeNode;\n private fastMap = new Map<ScopeRef, TreeNode>();\n\n constructor() {\n this.root = new TreeNode({scopeRef: null});\n this.fastMap.set(null, this.root);\n }\n\n get size() {\n return this.fastMap.size;\n }\n\n getTreeNode(data: ScopeRef) {\n return this.fastMap.get(data);\n }\n\n addTreeNode(scopeRef: ScopeRef, parent: ScopeRef, nodeToRestore?: FocusableElement) {\n let parentNode = this.fastMap.get(parent ?? null);\n if (!parentNode) {\n return;\n }\n let node = new TreeNode({scopeRef});\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n\n addNode(node: TreeNode) {\n this.fastMap.set(node.scopeRef, node);\n }\n\n removeTreeNode(scopeRef: ScopeRef) {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n let node = this.fastMap.get(scopeRef);\n if (!node) {\n return;\n }\n let parentNode = node.parent;\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (let current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef.current &&\n isElementInScope(current.nodeToRestore, node.scopeRef.current)\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n let children = node.children;\n if (parentNode) {\n parentNode.removeChild(node);\n if (children.size > 0) {\n children.forEach(child => parentNode && parentNode.addChild(child));\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (node.scopeRef != null) {\n yield node;\n }\n if (node.children.size > 0) {\n for (let child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n\n clone(): Tree {\n let newTree = new Tree();\n for (let node of this.traverse()) {\n newTree.addTreeNode(node.scopeRef, node.parent?.scopeRef ?? null, node.nodeToRestore);\n }\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children: Set<TreeNode> = new Set();\n public contain = false;\n\n constructor(props: {scopeRef: ScopeRef}) {\n this.scopeRef = props.scopeRef;\n }\n addChild(node: TreeNode) {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode) {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport let focusScopeTree = new Tree();\n"],"names":[],"version":3,"file":"FocusScope.module.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAyDD,MAAM,mDAAe,CAAA,GAAA,YAAI,EAAE,aAAa,CAAuB;AAC/D,MAAM,4CAAsB;AAE5B,IAAI,oCAAwB;AAYrB,SAAS,0CAAW,KAAsB;IAC/C,IAAI,YAAC,QAAQ,WAAE,OAAO,gBAAE,YAAY,aAAE,SAAS,EAAC,GAAG;IACnD,IAAI,WAAW,CAAA,GAAA,aAAK,EAAmB;IACvC,IAAI,SAAS,CAAA,GAAA,aAAK,EAAmB;IACrC,IAAI,W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AAc,EAAE;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAClB,KAAK,MAAM,GAAG,IAAI;IACpB;IACA,YAAY,IAAc,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,KAAK,MAAM,GAAG;IAChB;IAVA,YAAY,KAA2B,CAAE;aAHlC,WAA0B,IAAI;aAC9B,UAAU;QAGf,IAAI,CAAC,QAAQ,GAAG,MAAM,QAAQ;IAChC;AASF;AAEO,IAAI,4CAAiB,IAAI","sources":["packages/@react-aria/focus/src/FocusScope.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusSafely} from './focusSafely';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport {getOwnerDocument, isAndroid, isChrome, useLayoutEffect} from '@react-aria/utils';\nimport {isElementVisible} from './isElementVisible';\nimport React, {ReactNode, useContext, useEffect, useMemo, useRef} from 'react';\n\nexport interface FocusScopeProps {\n /** The contents of the focus scope. */\n children: ReactNode,\n\n /**\n * Whether to contain focus inside the scope, so users cannot\n * move focus outside, for example in a modal dialog.\n */\n contain?: boolean,\n\n /**\n * Whether to restore focus back to the element that was focused\n * when the focus scope mounted, after the focus scope unmounts.\n */\n restoreFocus?: boolean,\n\n /** Whether to auto focus the first focusable element in the focus scope on mount. */\n autoFocus?: boolean\n}\n\nexport interface FocusManagerOptions {\n /** The element to start searching from. The currently focused element by default. */\n from?: Element,\n /** Whether to only include tabbable elements, or all focusable elements. */\n tabbable?: boolean,\n /** Whether focus should wrap around when it reaches the end of the scope. */\n wrap?: boolean,\n /** A callback that determines whether the given element is focused. */\n accept?: (node: Element) => boolean\n}\n\nexport interface FocusManager {\n /** Moves focus to the next focusable or tabbable element in the focus scope. */\n focusNext(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the previous focusable or tabbable element in the focus scope. */\n focusPrevious(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the first focusable or tabbable element in the focus scope. */\n focusFirst(opts?: FocusManagerOptions): FocusableElement | null,\n /** Moves focus to the last focusable or tabbable element in the focus scope. */\n focusLast(opts?: FocusManagerOptions): FocusableElement | null\n}\n\ntype ScopeRef = RefObject<Element[] | null> | null;\ninterface IFocusContext {\n focusManager: FocusManager,\n parentNode: TreeNode | null\n}\n\nconst FocusContext = React.createContext<IFocusContext | null>(null);\nconst RESTORE_FOCUS_EVENT = 'react-aria-focus-scope-restore';\n\nlet activeScope: ScopeRef = null;\n\n// This is a hacky DOM-based implementation of a FocusScope until this RFC lands in React:\n// https://github.com/reactjs/rfcs/pull/109\n\n/**\n * A FocusScope manages focus for its descendants. It supports containing focus inside\n * the scope, restoring focus to the previously focused element on unmount, and auto\n * focusing children on mount. It also acts as a container for a programmatic focus\n * management interface that can be used to move focus forward and back in response\n * to user events.\n */\nexport function FocusScope(props: FocusScopeProps) {\n let {children, contain, restoreFocus, autoFocus} = props;\n let startRef = useRef<HTMLSpanElement>(null);\n let endRef = useRef<HTMLSpanElement>(null);\n let scopeRef = useRef<Element[]>([]);\n let {parentNode} = useContext(FocusContext) || {};\n\n // Create a tree node here so we can add children to it even before it is added to the tree.\n let node = useMemo(() => new TreeNode({scopeRef}), [scopeRef]);\n\n useLayoutEffect(() => {\n // If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),\n // use the active scope as the parent instead of the parent from context. Layout effects run bottom\n // up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope\n // that is being added should get the activeScope as its parent.\n let parent = parentNode || focusScopeTree.root;\n if (focusScopeTree.getTreeNode(parent.scopeRef) && activeScope && !isAncestorScope(activeScope, parent.scopeRef)) {\n let activeNode = focusScopeTree.getTreeNode(activeScope);\n if (activeNode) {\n parent = activeNode;\n }\n }\n\n // Add the node to the parent, and to the tree.\n parent.addChild(node);\n focusScopeTree.addNode(node);\n }, [node, parentNode]);\n\n useLayoutEffect(() => {\n let node = focusScopeTree.getTreeNode(scopeRef);\n if (node) {\n node.contain = !!contain;\n }\n }, [contain]);\n\n useLayoutEffect(() => {\n // Find all rendered nodes between the sentinels and add them to the scope.\n let node = startRef.current?.nextSibling!;\n let nodes: Element[] = [];\n let stopPropagation = e => e.stopPropagation();\n while (node && node !== endRef.current) {\n nodes.push(node as Element);\n // Stop custom restore focus event from propagating to parent focus scopes.\n node.addEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n node = node.nextSibling as Element;\n }\n\n scopeRef.current = nodes;\n\n return () => {\n for (let node of nodes) {\n node.removeEventListener(RESTORE_FOCUS_EVENT, stopPropagation);\n }\n };\n }, [children]);\n\n useActiveScopeTracker(scopeRef, restoreFocus, contain);\n useFocusContainment(scopeRef, contain);\n useRestoreFocus(scopeRef, restoreFocus, contain);\n useAutoFocus(scopeRef, autoFocus);\n\n // This needs to be an effect so that activeScope is updated after the FocusScope tree is complete.\n // It cannot be a useLayoutEffect because the parent of this node hasn't been attached in the tree yet.\n useEffect(() => {\n const activeElement = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement;\n let scope: TreeNode | null = null;\n\n if (isElementInScope(activeElement, scopeRef.current)) {\n // We need to traverse the focusScope tree and find the bottom most scope that\n // contains the active element and set that as the activeScope.\n for (let node of focusScopeTree.traverse()) {\n if (node.scopeRef && isElementInScope(activeElement, node.scopeRef.current)) {\n scope = node;\n }\n }\n\n if (scope === focusScopeTree.getTreeNode(scopeRef)) {\n activeScope = scope.scopeRef;\n }\n }\n }, [scopeRef]);\n\n // This layout effect cleanup is so that the tree node is removed synchronously with react before the RAF\n // in useRestoreFocus cleanup runs.\n useLayoutEffect(() => {\n return () => {\n // Scope may have been re-parented.\n let parentScope = focusScopeTree.getTreeNode(scopeRef)?.parent?.scopeRef ?? null;\n\n if (\n (scopeRef === activeScope || isAncestorScope(scopeRef, activeScope)) &&\n (!parentScope || focusScopeTree.getTreeNode(parentScope))\n ) {\n activeScope = parentScope;\n }\n focusScopeTree.removeTreeNode(scopeRef);\n };\n }, [scopeRef]);\n\n let focusManager = useMemo(() => createFocusManagerForScope(scopeRef), []);\n let value = useMemo(() => ({\n focusManager,\n parentNode: node\n }), [node, focusManager]);\n\n return (\n <FocusContext.Provider value={value}>\n <span data-focus-scope-start hidden ref={startRef} />\n {children}\n <span data-focus-scope-end hidden ref={endRef} />\n </FocusContext.Provider>\n );\n}\n\n/**\n * Returns a FocusManager interface for the parent FocusScope.\n * A FocusManager can be used to programmatically move focus within\n * a FocusScope, e.g. in response to user events like keyboard navigation.\n */\nexport function useFocusManager(): FocusManager | undefined {\n return useContext(FocusContext)?.focusManager;\n}\n\nfunction createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = sentinel;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = {}) {\n let scope = scopeRef.current!;\n let {from, tabbable, wrap, accept} = opts;\n let node = from || getOwnerDocument(scope[0]).activeElement!;\n let sentinel = scope[scope.length - 1].nextElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = isElementInScope(node, scope) ? node : sentinel;\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = sentinel;\n previousNode = walker.previousNode() as FocusableElement;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n },\n focusFirst(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[0].previousElementSibling!;\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = {}) {\n let scope = scopeRef.current!;\n let {tabbable, accept} = opts;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);\n walker.currentNode = scope[scope.length - 1].nextElementSibling!;\n let previousNode = walker.previousNode() as FocusableElement;\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode;\n }\n };\n}\n\nconst focusableElements = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable^=\"false\"])'\n];\n\nconst FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';\n\nfocusableElements.push('[tabindex]:not([tabindex=\"-1\"]):not([disabled])');\nconst TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex=\"-1\"]),');\n\nexport function isFocusable(element: HTMLElement) {\n return element.matches(FOCUSABLE_ELEMENT_SELECTOR);\n}\n\nfunction getScopeRoot(scope: Element[]) {\n return scope[0].parentElement!;\n}\n\nfunction shouldContainFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.contain) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return true;\n}\n\nfunction useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: boolean) {\n let focusedNode = useRef<FocusableElement>(undefined);\n\n let raf = useRef<ReturnType<typeof requestAnimationFrame>>(undefined);\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n if (!contain) {\n // if contain was changed, then we should cancel any ongoing waits to pull focus back into containment\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n raf.current = undefined;\n }\n return;\n }\n\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n // Handle the Tab key to contain focus within the scope\n let onKeyDown = (e) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement;\n let scope = scopeRef.current;\n if (!scope || !isElementInScope(focusedElement, scope)) {\n return;\n }\n\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable: true}, scope);\n if (!focusedElement) {\n return;\n }\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n if (!nextElement) {\n walker.currentNode = e.shiftKey ? scope[scope.length - 1].nextElementSibling! : scope[0].previousElementSibling!;\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n }\n\n e.preventDefault();\n if (nextElement) {\n focusElement(nextElement, true);\n }\n };\n\n let onFocus = (e) => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) && isElementInScope(e.target, scopeRef.current)) {\n activeScope = scopeRef;\n focusedNode.current = e.target;\n } else if (shouldContainFocus(scopeRef) && !isElementInChildScope(e.target, scopeRef)) {\n // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),\n // restore focus to the previously focused node or the first tabbable element in the active scope.\n if (focusedNode.current) {\n focusedNode.current.focus();\n } else if (activeScope && activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n } else if (shouldContainFocus(scopeRef)) {\n focusedNode.current = e.target;\n }\n };\n\n let onBlur = (e) => {\n // Firefox doesn't shift focus back to the Dialog properly without this\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n raf.current = requestAnimationFrame(() => {\n // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor\n // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.\n // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.\n let modality = getInteractionModality();\n let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && isAndroid() && isChrome();\n\n // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe\n if (!shouldSkipFocusRestore && ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {\n activeScope = scopeRef;\n if (ownerDocument.body.contains(e.target)) {\n focusedNode.current = e.target;\n focusedNode.current?.focus();\n } else if (activeScope.current) {\n focusFirstInScope(activeScope.current);\n }\n }\n });\n };\n\n ownerDocument.addEventListener('keydown', onKeyDown, false);\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.addEventListener('focusout', onBlur, false));\n return () => {\n ownerDocument.removeEventListener('keydown', onKeyDown, false);\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n scope?.forEach(element => element.removeEventListener('focusout', onBlur, false));\n };\n }, [scopeRef, contain]);\n\n // This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur\n\n useLayoutEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, [raf]);\n}\n\nfunction isElementInAnyScope(element: Element) {\n return isElementInChildScope(element);\n}\n\nfunction isElementInScope(element?: Element | null, scope?: Element[] | null) {\n if (!element) {\n return false;\n }\n if (!scope) {\n return false;\n }\n return scope.some(node => node.contains(element));\n}\n\nfunction isElementInChildScope(element: Element, scope: ScopeRef = null) {\n // If the element is within a top layer element (e.g. toasts), always allow moving focus there.\n if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {\n return true;\n }\n\n // node.contains in isElementInScope covers child scopes that are also DOM children,\n // but does not cover child scopes in portals.\n for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {\n if (s && isElementInScope(element, s.current)) {\n return true;\n }\n }\n\n return false;\n}\n\n/** @private */\nexport function isElementInChildOfActiveScope(element: Element) {\n return isElementInChildScope(element, activeScope);\n}\n\nfunction isAncestorScope(ancestor: ScopeRef, scope: ScopeRef) {\n let parent = focusScopeTree.getTreeNode(scope)?.parent;\n while (parent) {\n if (parent.scopeRef === ancestor) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n}\n\nfunction focusElement(element: FocusableElement | null, scroll = false) {\n if (element != null && !scroll) {\n try {\n focusSafely(element);\n } catch {\n // ignore\n }\n } else if (element != null) {\n try {\n element.focus();\n } catch {\n // ignore\n }\n }\n}\n\nfunction getFirstInScope(scope: Element[], tabbable = true) {\n let sentinel = scope[0].previousElementSibling!;\n let scopeRoot = getScopeRoot(scope);\n let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope);\n walker.currentNode = sentinel;\n let nextNode = walker.nextNode();\n\n // If the scope does not contain a tabbable element, use the first focusable element.\n if (tabbable && !nextNode) {\n scopeRoot = getScopeRoot(scope);\n walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope);\n walker.currentNode = sentinel;\n nextNode = walker.nextNode();\n }\n\n return nextNode as FocusableElement;\n}\n\nfunction focusFirstInScope(scope: Element[], tabbable:boolean = true) {\n focusElement(getFirstInScope(scope, tabbable));\n}\n\nfunction useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {\n const autoFocusRef = React.useRef(autoFocus);\n useEffect(() => {\n if (autoFocusRef.current) {\n activeScope = scopeRef;\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n if (!isElementInScope(ownerDocument.activeElement, activeScope.current) && scopeRef.current) {\n focusFirstInScope(scopeRef.current);\n }\n }\n autoFocusRef.current = false;\n }, [scopeRef]);\n}\n\nfunction useActiveScopeTracker(scopeRef: RefObject<Element[] | null>, restore?: boolean, contain?: boolean) {\n // tracks the active scope, in case restore and contain are both false.\n // if either are true, this is tracked in useRestoreFocus or useFocusContainment.\n useLayoutEffect(() => {\n if (restore || contain) {\n return;\n }\n\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n\n let onFocus = (e) => {\n let target = e.target as Element;\n if (isElementInScope(target, scopeRef.current)) {\n activeScope = scopeRef;\n } else if (!isElementInAnyScope(target)) {\n activeScope = null;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n }, [scopeRef, restore, contain]);\n}\n\nfunction shouldRestoreFocus(scopeRef: ScopeRef) {\n let scope = focusScopeTree.getTreeNode(activeScope);\n while (scope && scope.scopeRef !== scopeRef) {\n if (scope.nodeToRestore) {\n return false;\n }\n\n scope = scope.parent;\n }\n\n return scope?.scopeRef === scopeRef;\n}\n\nfunction useRestoreFocus(scopeRef: RefObject<Element[] | null>, restoreFocus?: boolean, contain?: boolean) {\n // create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.\n // eslint-disable-next-line no-restricted-globals\n const nodeToRestoreRef = useRef(typeof document !== 'undefined' ? getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined).activeElement as FocusableElement : null);\n\n // restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus\n // restoring-non-containing scopes should only care if they become active so they can perform the restore\n useLayoutEffect(() => {\n let scope = scopeRef.current;\n const ownerDocument = getOwnerDocument(scope ? scope[0] : undefined);\n if (!restoreFocus || contain) {\n return;\n }\n\n let onFocus = () => {\n // If focusing an element in a child scope of the currently active scope, the child becomes active.\n // Moving out of the active scope to an ancestor is not allowed.\n if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&\n isElementInScope(ownerDocument.activeElement, scopeRef.current)\n ) {\n activeScope = scopeRef;\n }\n };\n\n ownerDocument.addEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.addEventListener('focusin', onFocus, false));\n return () => {\n ownerDocument.removeEventListener('focusin', onFocus, false);\n scope?.forEach(element => element.removeEventListener('focusin', onFocus, false));\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scopeRef, contain]);\n\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n // Handle the Tab key so that tabbing out of the scope goes to the next element\n // after the node that had focus when the scope mounted. This is important when\n // using portals for overlays, so that focus goes to the expected element when\n // tabbing out of the overlay.\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {\n return;\n }\n\n let focusedElement = ownerDocument.activeElement as FocusableElement;\n if (!isElementInChildScope(focusedElement, scopeRef) || !shouldRestoreFocus(scopeRef)) {\n return;\n }\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // Create a DOM tree walker that matches all tabbable elements\n let walker = getFocusableTreeWalker(ownerDocument.body, {tabbable: true});\n\n // Find the next tabbable element after the currently focused element\n walker.currentNode = focusedElement;\n let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n\n if (!nodeToRestore || !ownerDocument.body.contains(nodeToRestore) || nodeToRestore === ownerDocument.body) {\n nodeToRestore = undefined;\n treeNode.nodeToRestore = undefined;\n }\n\n // If there is no next element, or it is outside the current scope, move focus to the\n // next element after the node to restore to instead.\n if ((!nextElement || !isElementInChildScope(nextElement, scopeRef)) && nodeToRestore) {\n walker.currentNode = nodeToRestore;\n\n // Skip over elements within the scope, in case the scope immediately follows the node to restore.\n do {\n nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;\n } while (isElementInChildScope(nextElement, scopeRef));\n\n e.preventDefault();\n e.stopPropagation();\n if (nextElement) {\n focusElement(nextElement, true);\n } else {\n // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)\n // then move focus to the body.\n // Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)\n if (!isElementInAnyScope(nodeToRestore)) {\n focusedElement.blur();\n } else {\n focusElement(nodeToRestore, true);\n }\n }\n }\n };\n\n if (!contain) {\n ownerDocument.addEventListener('keydown', onKeyDown, true);\n }\n\n return () => {\n if (!contain) {\n ownerDocument.removeEventListener('keydown', onKeyDown, true);\n }\n };\n }, [scopeRef, restoreFocus, contain]);\n\n // useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.\n useLayoutEffect(() => {\n const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);\n\n if (!restoreFocus) {\n return;\n }\n\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n treeNode.nodeToRestore = nodeToRestoreRef.current ?? undefined;\n return () => {\n let treeNode = focusScopeTree.getTreeNode(scopeRef);\n if (!treeNode) {\n return;\n }\n let nodeToRestore = treeNode.nodeToRestore;\n\n // if we already lost focus to the body and this was the active scope, then we should attempt to restore\n if (\n restoreFocus\n && nodeToRestore\n && (\n ((ownerDocument.activeElement && isElementInChildScope(ownerDocument.activeElement, scopeRef)) || (ownerDocument.activeElement === ownerDocument.body && shouldRestoreFocus(scopeRef)))\n )\n ) {\n // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it\n let clonedTree = focusScopeTree.clone();\n requestAnimationFrame(() => {\n // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere\n if (ownerDocument.activeElement === ownerDocument.body) {\n // look up the tree starting with our scope to find a nodeToRestore still in the DOM\n let treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.nodeToRestore && treeNode.nodeToRestore.isConnected) {\n restoreFocusToElement(treeNode.nodeToRestore);\n return;\n }\n treeNode = treeNode.parent;\n }\n\n // If no nodeToRestore was found, focus the first element in the nearest\n // ancestor scope that is still in the tree.\n treeNode = clonedTree.getTreeNode(scopeRef);\n while (treeNode) {\n if (treeNode.scopeRef && treeNode.scopeRef.current && focusScopeTree.getTreeNode(treeNode.scopeRef)) {\n let node = getFirstInScope(treeNode.scopeRef.current, true);\n restoreFocusToElement(node);\n return;\n }\n treeNode = treeNode.parent;\n }\n }\n });\n }\n };\n }, [scopeRef, restoreFocus]);\n}\n\nfunction restoreFocusToElement(node: FocusableElement) {\n // Dispatch a custom event that parent elements can intercept to customize focus restoration.\n // For example, virtualized collection components reuse DOM elements, so the original element\n // might still exist in the DOM but representing a different item.\n if (node.dispatchEvent(new CustomEvent(RESTORE_FOCUS_EVENT, {bubbles: true, cancelable: true}))) {\n focusElement(node);\n }\n}\n\n/**\n * Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}\n * that matches all focusable/tabbable elements.\n */\nexport function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[]) {\n let selector = opts?.tabbable ? TABBABLE_ELEMENT_SELECTOR : FOCUSABLE_ELEMENT_SELECTOR;\n let walker = getOwnerDocument(root).createTreeWalker(\n root,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode(node) {\n // Skip nodes inside the starting node.\n if (opts?.from?.contains(node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if ((node as Element).matches(selector)\n && isElementVisible(node as Element)\n && (!scope || isElementInScope(node as Element, scope))\n && (!opts?.accept || opts.accept(node as Element))\n ) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n }\n }\n );\n\n if (opts?.from) {\n walker.currentNode = opts.from;\n }\n\n return walker;\n}\n\n/**\n * Creates a FocusManager object that can be used to move focus within an element.\n */\nexport function createFocusManager(ref: RefObject<Element | null>, defaultOptions: FocusManagerOptions = {}): FocusManager {\n return {\n focusNext(opts: FocusManagerOptions = {}) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n }\n let nextNode = walker.nextNode() as FocusableElement;\n if (!nextNode && wrap) {\n walker.currentNode = root;\n nextNode = walker.nextNode() as FocusableElement;\n }\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusPrevious(opts: FocusManagerOptions = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {from, tabbable = defaultOptions.tabbable, wrap = defaultOptions.wrap, accept = defaultOptions.accept} = opts;\n let node = from || getOwnerDocument(root).activeElement;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n if (root.contains(node)) {\n walker.currentNode = node!;\n } else {\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n let previousNode = walker.previousNode() as FocusableElement;\n if (!previousNode && wrap) {\n walker.currentNode = root;\n let lastNode = last(walker);\n if (!lastNode) {\n // couldn't wrap\n return null;\n }\n previousNode = lastNode;\n }\n if (previousNode) {\n focusElement(previousNode, true);\n }\n return previousNode ?? null;\n },\n focusFirst(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let nextNode = walker.nextNode() as FocusableElement;\n if (nextNode) {\n focusElement(nextNode, true);\n }\n return nextNode;\n },\n focusLast(opts = defaultOptions) {\n let root = ref.current;\n if (!root) {\n return null;\n }\n let {tabbable = defaultOptions.tabbable, accept = defaultOptions.accept} = opts;\n let walker = getFocusableTreeWalker(root, {tabbable, accept});\n let next = last(walker);\n if (next) {\n focusElement(next, true);\n }\n return next ?? null;\n }\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n\n\nclass Tree {\n root: TreeNode;\n private fastMap = new Map<ScopeRef, TreeNode>();\n\n constructor() {\n this.root = new TreeNode({scopeRef: null});\n this.fastMap.set(null, this.root);\n }\n\n get size() {\n return this.fastMap.size;\n }\n\n getTreeNode(data: ScopeRef) {\n return this.fastMap.get(data);\n }\n\n addTreeNode(scopeRef: ScopeRef, parent: ScopeRef, nodeToRestore?: FocusableElement) {\n let parentNode = this.fastMap.get(parent ?? null);\n if (!parentNode) {\n return;\n }\n let node = new TreeNode({scopeRef});\n parentNode.addChild(node);\n node.parent = parentNode;\n this.fastMap.set(scopeRef, node);\n if (nodeToRestore) {\n node.nodeToRestore = nodeToRestore;\n }\n }\n\n addNode(node: TreeNode) {\n this.fastMap.set(node.scopeRef, node);\n }\n\n removeTreeNode(scopeRef: ScopeRef) {\n // never remove the root\n if (scopeRef === null) {\n return;\n }\n let node = this.fastMap.get(scopeRef);\n if (!node) {\n return;\n }\n let parentNode = node.parent;\n // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing\n // if we are, then replace the siblings restore with the restore from the scope we're removing\n for (let current of this.traverse()) {\n if (\n current !== node &&\n node.nodeToRestore &&\n current.nodeToRestore &&\n node.scopeRef &&\n node.scopeRef.current &&\n isElementInScope(current.nodeToRestore, node.scopeRef.current)\n ) {\n current.nodeToRestore = node.nodeToRestore;\n }\n }\n let children = node.children;\n if (parentNode) {\n parentNode.removeChild(node);\n if (children.size > 0) {\n children.forEach(child => parentNode && parentNode.addChild(child));\n }\n }\n\n this.fastMap.delete(node.scopeRef);\n }\n\n // Pre Order Depth First\n *traverse(node: TreeNode = this.root): Generator<TreeNode> {\n if (node.scopeRef != null) {\n yield node;\n }\n if (node.children.size > 0) {\n for (let child of node.children) {\n yield* this.traverse(child);\n }\n }\n }\n\n clone(): Tree {\n let newTree = new Tree();\n for (let node of this.traverse()) {\n newTree.addTreeNode(node.scopeRef, node.parent?.scopeRef ?? null, node.nodeToRestore);\n }\n return newTree;\n }\n}\n\nclass TreeNode {\n public scopeRef: ScopeRef;\n public nodeToRestore?: FocusableElement;\n public parent?: TreeNode;\n public children: Set<TreeNode> = new Set();\n public contain = false;\n\n constructor(props: {scopeRef: ScopeRef}) {\n this.scopeRef = props.scopeRef;\n }\n addChild(node: TreeNode) {\n this.children.add(node);\n node.parent = this;\n }\n removeChild(node: TreeNode) {\n this.children.delete(node);\n node.parent = undefined;\n }\n}\n\nexport let focusScopeTree = new Tree();\n"],"names":[],"version":3,"file":"FocusScope.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -127,7 +127,10 @@ export interface FocusableProviderProps extends DOMAttributes {
127
127
  /** The child element to provide DOM props to. */
128
128
  children?: ReactNode;
129
129
  }
130
- export let FocusableProvider: React.ForwardRefExoticComponent<FocusableProviderProps & React.RefAttributes<FocusableElement>>;
130
+ /**
131
+ * Provides DOM props to the nearest focusable child.
132
+ */
133
+ export const FocusableProvider: React.ForwardRefExoticComponent<FocusableProviderProps & React.RefAttributes<FocusableElement>>;
131
134
  export interface FocusableAria {
132
135
  /** Props for the focusable element. */
133
136
  focusableProps: DOMAttributes;
@@ -1 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gB,GAAG,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,aAAa,CAwBjK;AC/ED;IACE,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAOD;;;GAGG;AACH,oCAAoC,GAAG,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAmClH","sources":["packages/@react-aria/focus/src/packages/@react-aria/focus/src/focusSafely.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/isElementVisible.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/FocusScope.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useFocusRing.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/FocusRing.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useFocusable.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useHasTabbableChild.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/index.ts","packages/@react-aria/focus/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {FocusScope, useFocusManager, getFocusableTreeWalker, createFocusManager, isElementInChildOfActiveScope, isFocusable} from './FocusScope';\nexport {FocusRing} from './FocusRing';\nexport {FocusableProvider, useFocusable} from './useFocusable';\nexport {useFocusRing} from './useFocusRing';\nexport {focusSafely} from './focusSafely';\nexport {useHasTabbableChild} from './useHasTabbableChild';\n\nexport type {FocusScopeProps, FocusManager, FocusManagerOptions} from './FocusScope';\nexport type {FocusRingProps} from './FocusRing';\nexport type {FocusableAria, FocusableOptions, FocusableProviderProps} from './useFocusable';\nexport type {AriaFocusRingProps, FocusRingAria} from './useFocusRing';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAgBA;;;GAGG;AACH,4BAA4B,OAAO,EAAE,gBAAgB,QAkBpD;AEnBD;IACE,uCAAuC;IACvC,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,qFAAqF;IACrF,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;IACE,qFAAqF;IACrF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6EAA6E;IAC7E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAA;CACpC;AAED;IACE,gFAAgF;IAChF,SAAS,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC/D,oFAAoF;IACpF,aAAa,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,CAAC;IACnE,iFAAiF;IACjF,UAAU,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9D,gFAAgF;IAClF,SAAS,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,CAAA;CAC/D;AAgBD;;;;;;GAMG;AACH,2BAA2B,KAAK,EAAE,eAAe,qBAgHhD;AAED;;;;GAIG;AACH,mCAAmC,YAAY,GAAG,SAAS,CAE1D;AAwFD,4BAA4B,OAAO,EAAE,WA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D;IACjD,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAiBD;;GAEG;AACH,OAAO,MAAM,kHAaX,CAAC;AAEH;IACE,uCAAuC;IACvC,cAAc,EAAE,aAAa,CAAA;CAC9B;AAED;;GAEG;AACH,6BAA6B,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,aAAa,CAwBjK;AC5ED;IACE,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAOD;;;GAGG;AACH,oCAAoC,GAAG,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAmClH","sources":["packages/@react-aria/focus/src/packages/@react-aria/focus/src/focusSafely.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/isElementVisible.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/FocusScope.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useFocusRing.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/FocusRing.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useFocusable.tsx","packages/@react-aria/focus/src/packages/@react-aria/focus/src/useHasTabbableChild.ts","packages/@react-aria/focus/src/packages/@react-aria/focus/src/index.ts","packages/@react-aria/focus/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {FocusScope, useFocusManager, getFocusableTreeWalker, createFocusManager, isElementInChildOfActiveScope, isFocusable} from './FocusScope';\nexport {FocusRing} from './FocusRing';\nexport {FocusableProvider, useFocusable} from './useFocusable';\nexport {useFocusRing} from './useFocusRing';\nexport {focusSafely} from './focusSafely';\nexport {useHasTabbableChild} from './useHasTabbableChild';\n\nexport type {FocusScopeProps, FocusManager, FocusManagerOptions} from './FocusScope';\nexport type {FocusRingProps} from './FocusRing';\nexport type {FocusableAria, FocusableOptions, FocusableProviderProps} from './useFocusable';\nexport type {AriaFocusRingProps, FocusRingAria} from './useFocusRing';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -36,9 +36,7 @@ function $fb504d83237fd6ac$var$useFocusableContext(ref) {
36
36
  let { ref: _, ...otherProps } = context;
37
37
  return otherProps;
38
38
  }
39
- /**
40
- * Provides DOM props to the nearest focusable child.
41
- */ function $fb504d83237fd6ac$var$FocusableProvider(props, ref) {
39
+ const $fb504d83237fd6ac$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($ggOO2$react))).forwardRef(function FocusableProvider(props, ref) {
42
40
  let { children: children, ...otherProps } = props;
43
41
  let objRef = (0, $ggOO2$reactariautils.useObjectRef)(ref);
44
42
  let context = {
@@ -48,8 +46,7 @@ function $fb504d83237fd6ac$var$useFocusableContext(ref) {
48
46
  return /*#__PURE__*/ (0, ($parcel$interopDefault($ggOO2$react))).createElement($fb504d83237fd6ac$var$FocusableContext.Provider, {
49
47
  value: context
50
48
  }, children);
51
- }
52
- let $fb504d83237fd6ac$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($ggOO2$react))).forwardRef($fb504d83237fd6ac$var$FocusableProvider);
49
+ });
53
50
  function $fb504d83237fd6ac$export$4c014de7c8940b4c(props, domRef) {
54
51
  let { focusProps: focusProps } = (0, $ggOO2$reactariainteractions.useFocus)(props);
55
52
  let { keyboardProps: keyboardProps } = (0, $ggOO2$reactariainteractions.useKeyboard)(props);
@@ -1 +1 @@
1
- {"mappings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AAU,MAAM,mBAAmB,IAAI,CAAC,MAAM,UAAU,GAAG,KAAK;QAClE,GACA;IAEJ;AACF","sources":["packages/@react-aria/focus/src/useFocusable.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, MutableRefObject, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus, useKeyboard} from '@react-aria/interactions';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\nlet FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nfunction FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n}\n\nlet _FocusableProvider = React.forwardRef(FocusableProvider);\nexport {_FocusableProvider as FocusableProvider};\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined\n },\n interactionProps\n )\n };\n}\n"],"names":[],"version":3,"file":"useFocusable.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAsBD,IAAI,uDAAmB,CAAA,GAAA,sCAAI,EAAE,aAAa,CAA+B;AAEzE,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,uBAAS,EAAE,2CAAqB,CAAC;IAC/C,CAAA,GAAA,gCAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAKO,MAAM,yDAAoB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,kBAAkB,KAA6B,EAAE,GAAmC;IAC7I,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAChC,IAAI,SAAS,CAAA,GAAA,kCAAW,EAAE;IAC1B,IAAI,UAAU;QACZ,GAAG,UAAU;QACb,KAAK;IACP;IAEA,qBACE,0DAAC,uCAAiB,QAAQ;QAAC,OAAO;OAC/B;AAGP;AAUO,SAAS,0CAA4D,KAA0B,EAAE,MAA0C;IAChJ,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;IAC5B,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,wCAAU,EAAE;IAClC,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,0CAAoB;IACnC,IAAI,mBAAmB,MAAM,UAAU,GAAG,CAAC,IAAI;IAC/C,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE,MAAM,SAAS;IAEzC,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,aAAa,OAAO,IAAI,OAAO,OAAO,EACxC,CAAA,GAAA,qCAAU,EAAE,OAAO,OAAO;QAE5B,aAAa,OAAO,GAAG;IACzB,GAAG;QAAC;KAAO;IAEX,OAAO;QACL,gBAAgB,CAAA,GAAA,gCAAS,EACvB;YACE,GAAG,YAAY;YACf,UAAU,MAAM,mBAAmB,IAAI,CAAC,MAAM,UAAU,GAAG,KAAK;QAClE,GACA;IAEJ;AACF","sources":["packages/@react-aria/focus/src/useFocusable.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, MutableRefObject, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus, useKeyboard} from '@react-aria/interactions';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\nlet FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider = React.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n});\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined\n },\n interactionProps\n )\n };\n}\n"],"names":[],"version":3,"file":"useFocusable.main.js.map"}
@@ -25,9 +25,7 @@ function $e6afbd83fe6ebbd2$var$useFocusableContext(ref) {
25
25
  let { ref: _, ...otherProps } = context;
26
26
  return otherProps;
27
27
  }
28
- /**
29
- * Provides DOM props to the nearest focusable child.
30
- */ function $e6afbd83fe6ebbd2$var$FocusableProvider(props, ref) {
28
+ const $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $h8xso$react).forwardRef(function FocusableProvider(props, ref) {
31
29
  let { children: children, ...otherProps } = props;
32
30
  let objRef = (0, $h8xso$useObjectRef)(ref);
33
31
  let context = {
@@ -37,8 +35,7 @@ function $e6afbd83fe6ebbd2$var$useFocusableContext(ref) {
37
35
  return /*#__PURE__*/ (0, $h8xso$react).createElement($e6afbd83fe6ebbd2$var$FocusableContext.Provider, {
38
36
  value: context
39
37
  }, children);
40
- }
41
- let $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $h8xso$react).forwardRef($e6afbd83fe6ebbd2$var$FocusableProvider);
38
+ });
42
39
  function $e6afbd83fe6ebbd2$export$4c014de7c8940b4c(props, domRef) {
43
40
  let { focusProps: focusProps } = (0, $h8xso$useFocus)(props);
44
41
  let { keyboardProps: keyboardProps } = (0, $h8xso$useKeyboard)(props);
@@ -25,9 +25,7 @@ function $e6afbd83fe6ebbd2$var$useFocusableContext(ref) {
25
25
  let { ref: _, ...otherProps } = context;
26
26
  return otherProps;
27
27
  }
28
- /**
29
- * Provides DOM props to the nearest focusable child.
30
- */ function $e6afbd83fe6ebbd2$var$FocusableProvider(props, ref) {
28
+ const $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $h8xso$react).forwardRef(function FocusableProvider(props, ref) {
31
29
  let { children: children, ...otherProps } = props;
32
30
  let objRef = (0, $h8xso$useObjectRef)(ref);
33
31
  let context = {
@@ -37,8 +35,7 @@ function $e6afbd83fe6ebbd2$var$useFocusableContext(ref) {
37
35
  return /*#__PURE__*/ (0, $h8xso$react).createElement($e6afbd83fe6ebbd2$var$FocusableContext.Provider, {
38
36
  value: context
39
37
  }, children);
40
- }
41
- let $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $h8xso$react).forwardRef($e6afbd83fe6ebbd2$var$FocusableProvider);
38
+ });
42
39
  function $e6afbd83fe6ebbd2$export$4c014de7c8940b4c(props, domRef) {
43
40
  let { focusProps: focusProps } = (0, $h8xso$useFocus)(props);
44
41
  let { keyboardProps: keyboardProps } = (0, $h8xso$useKeyboard)(props);
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAsBD,IAAI,uDAAmB,CAAA,GAAA,YAAI,EAAE,aAAa,CAA+B;AAEzE,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,iBAAS,EAAE,2CAAqB,CAAC;IAC/C,CAAA,GAAA,iBAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAEA;;CAEC,GACD,SAAS,wCAAkB,KAA6B,EAAE,GAAmC;IAC3F,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAChC,IAAI,SAAS,CAAA,GAAA,mBAAW,EAAE;IAC1B,IAAI,UAAU;QACZ,GAAG,UAAU;QACb,KAAK;IACP;IAEA,qBACE,gCAAC,uCAAiB,QAAQ;QAAC,OAAO;OAC/B;AAGP;AAEA,IAAI,yDAAqB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC;AAWnC,SAAS,0CAA4D,KAA0B,EAAE,MAA0C;IAChJ,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;IAC5B,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;IAClC,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,0CAAoB;IACnC,IAAI,mBAAmB,MAAM,UAAU,GAAG,CAAC,IAAI;IAC/C,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE,MAAM,SAAS;IAEzC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,aAAa,OAAO,IAAI,OAAO,OAAO,EACxC,CAAA,GAAA,yCAAU,EAAE,OAAO,OAAO;QAE5B,aAAa,OAAO,GAAG;IACzB,GAAG;QAAC;KAAO;IAEX,OAAO;QACL,gBAAgB,CAAA,GAAA,iBAAS,EACvB;YACE,GAAG,YAAY;YACf,UAAU,MAAM,mBAAmB,IAAI,CAAC,MAAM,UAAU,GAAG,KAAK;QAClE,GACA;IAEJ;AACF","sources":["packages/@react-aria/focus/src/useFocusable.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, MutableRefObject, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus, useKeyboard} from '@react-aria/interactions';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\nlet FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nfunction FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n}\n\nlet _FocusableProvider = React.forwardRef(FocusableProvider);\nexport {_FocusableProvider as FocusableProvider};\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined\n },\n interactionProps\n )\n };\n}\n"],"names":[],"version":3,"file":"useFocusable.module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAsBD,IAAI,uDAAmB,CAAA,GAAA,YAAI,EAAE,aAAa,CAA+B;AAEzE,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,iBAAS,EAAE,2CAAqB,CAAC;IAC/C,CAAA,GAAA,iBAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAKO,MAAM,yDAAoB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,kBAAkB,KAA6B,EAAE,GAAmC;IAC7I,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAChC,IAAI,SAAS,CAAA,GAAA,mBAAW,EAAE;IAC1B,IAAI,UAAU;QACZ,GAAG,UAAU;QACb,KAAK;IACP;IAEA,qBACE,gCAAC,uCAAiB,QAAQ;QAAC,OAAO;OAC/B;AAGP;AAUO,SAAS,0CAA4D,KAA0B,EAAE,MAA0C;IAChJ,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;IAC5B,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;IAClC,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,0CAAoB;IACnC,IAAI,mBAAmB,MAAM,UAAU,GAAG,CAAC,IAAI;IAC/C,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE,MAAM,SAAS;IAEzC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,aAAa,OAAO,IAAI,OAAO,OAAO,EACxC,CAAA,GAAA,yCAAU,EAAE,OAAO,OAAO;QAE5B,aAAa,OAAO,GAAG;IACzB,GAAG;QAAC;KAAO;IAEX,OAAO;QACL,gBAAgB,CAAA,GAAA,iBAAS,EACvB;YACE,GAAG,YAAY;YACf,UAAU,MAAM,mBAAmB,IAAI,CAAC,MAAM,UAAU,GAAG,KAAK;QAClE,GACA;IAEJ;AACF","sources":["packages/@react-aria/focus/src/useFocusable.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, MutableRefObject, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus, useKeyboard} from '@react-aria/interactions';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\nlet FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider = React.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n});\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined\n },\n interactionProps\n )\n };\n}\n"],"names":[],"version":3,"file":"useFocusable.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/focus",
3
- "version": "3.19.0",
3
+ "version": "3.19.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,17 +22,18 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/interactions": "^3.22.5",
26
- "@react-aria/utils": "^3.26.0",
27
- "@react-types/shared": "^3.26.0",
25
+ "@react-aria/interactions": "^3.23.0",
26
+ "@react-aria/utils": "^3.27.0",
27
+ "@react-types/shared": "^3.27.0",
28
28
  "@swc/helpers": "^0.5.0",
29
29
  "clsx": "^2.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
32
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
33
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
38
+ "gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
38
39
  }
@@ -12,7 +12,8 @@
12
12
 
13
13
  import {FocusableElement, RefObject} from '@react-types/shared';
14
14
  import {focusSafely} from './focusSafely';
15
- import {getOwnerDocument, useLayoutEffect} from '@react-aria/utils';
15
+ import {getInteractionModality} from '@react-aria/interactions';
16
+ import {getOwnerDocument, isAndroid, isChrome, useLayoutEffect} from '@react-aria/utils';
16
17
  import {isElementVisible} from './isElementVisible';
17
18
  import React, {ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
18
19
 
@@ -280,7 +281,7 @@ const focusableElements = [
280
281
  'embed',
281
282
  'audio[controls]',
282
283
  'video[controls]',
283
- '[contenteditable]'
284
+ '[contenteditable]:not([contenteditable^="false"])'
284
285
  ];
285
286
 
286
287
  const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
@@ -381,8 +382,14 @@ function useFocusContainment(scopeRef: RefObject<Element[] | null>, contain?: bo
381
382
  cancelAnimationFrame(raf.current);
382
383
  }
383
384
  raf.current = requestAnimationFrame(() => {
385
+ // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor
386
+ // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.
387
+ // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.
388
+ let modality = getInteractionModality();
389
+ let shouldSkipFocusRestore = (modality === 'virtual' || modality === null) && isAndroid() && isChrome();
390
+
384
391
  // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
385
- if (ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
392
+ if (!shouldSkipFocusRestore && ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
386
393
  activeScope = scopeRef;
387
394
  if (ownerDocument.body.contains(e.target)) {
388
395
  focusedNode.current = e.target;
@@ -44,7 +44,7 @@ function useFocusableContext(ref: RefObject<FocusableElement | null>): Focusable
44
44
  /**
45
45
  * Provides DOM props to the nearest focusable child.
46
46
  */
47
- function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {
47
+ export const FocusableProvider = React.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {
48
48
  let {children, ...otherProps} = props;
49
49
  let objRef = useObjectRef(ref);
50
50
  let context = {
@@ -57,10 +57,7 @@ function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<Focu
57
57
  {children}
58
58
  </FocusableContext.Provider>
59
59
  );
60
- }
61
-
62
- let _FocusableProvider = React.forwardRef(FocusableProvider);
63
- export {_FocusableProvider as FocusableProvider};
60
+ });
64
61
 
65
62
  export interface FocusableAria {
66
63
  /** Props for the focusable element. */