@solid2-aria/core 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/NOTICE.txt +33 -11
- package/dist/browser/actiongroup/create-action-group.js +2 -1
- package/dist/browser/actiongroup/create-action-group.js.map +1 -1
- package/dist/browser/combobox/create-combo-box.js +2 -2
- package/dist/browser/combobox/create-combo-box.js.map +1 -1
- package/dist/browser/dnd/drag-preview.js +7 -8
- package/dist/browser/dnd/drag-preview.js.map +1 -1
- package/dist/browser/focus/focus-scope.js +2 -2
- package/dist/browser/focus/focus-scope.js.map +1 -1
- package/dist/browser/focus/virtual-focus.d.ts +1 -0
- package/dist/browser/focus/virtual-focus.js +20 -5
- package/dist/browser/focus/virtual-focus.js.map +1 -1
- package/dist/browser/grid/create-grid-cell.js +4 -4
- package/dist/browser/grid/create-grid-cell.js.map +1 -1
- package/dist/browser/gridlist/create-grid-list-item.js +3 -3
- package/dist/browser/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/browser/interactions/create-hover.js +6 -3
- package/dist/browser/interactions/create-hover.js.map +1 -1
- package/dist/browser/interactions/create-press.js +5 -4
- package/dist/browser/interactions/create-press.js.map +1 -1
- package/dist/browser/interactions/utils.js +4 -3
- package/dist/browser/interactions/utils.js.map +1 -1
- package/dist/browser/landmark/create-landmark.js +2 -2
- package/dist/browser/landmark/create-landmark.js.map +1 -1
- package/dist/browser/overlays/aria-hide-outside.js +5 -3
- package/dist/browser/overlays/aria-hide-outside.js.map +1 -1
- package/dist/browser/overlays/calculate-position.js +3 -3
- package/dist/browser/overlays/calculate-position.js.map +1 -1
- package/dist/browser/overlays/create-modal.js +15 -18
- package/dist/browser/overlays/create-modal.js.map +1 -1
- package/dist/browser/overlays/create-prevent-scroll.js +3 -3
- package/dist/browser/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/browser/overlays/overlay.js +7 -8
- package/dist/browser/overlays/overlay.js.map +1 -1
- package/dist/browser/select/create-select.js +1 -1
- package/dist/browser/select/create-select.js.map +1 -1
- package/dist/browser/select/hidden-select.js +61 -64
- package/dist/browser/select/hidden-select.js.map +1 -1
- package/dist/browser/selection/create-selectable-item.js +2 -2
- package/dist/browser/selection/create-selectable-item.js.map +1 -1
- package/dist/browser/selection/create-type-select.js +11 -3
- package/dist/browser/selection/create-type-select.js.map +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/browser/tokenfield/create-token-field.js +3 -3
- package/dist/browser/tokenfield/create-token-field.js.map +1 -1
- package/dist/browser/tokenfield/create-token.js +2 -1
- package/dist/browser/tokenfield/create-token.js.map +1 -1
- package/dist/browser/toolbar/create-toolbar.js +2 -2
- package/dist/browser/toolbar/create-toolbar.js.map +1 -1
- package/dist/browser/utils/dom-helpers.d.ts +2 -15
- package/dist/browser/utils/dom-helpers.js +1 -28
- package/dist/browser/utils/dom-helpers.js.map +1 -1
- package/dist/browser/utils/dom-value.js +2 -1
- package/dist/browser/utils/dom-value.js.map +1 -1
- package/dist/browser/utils/get-scroll-parent.js +3 -2
- package/dist/browser/utils/get-scroll-parent.js.map +1 -1
- package/dist/browser/utils/get-scroll-parents.js +2 -1
- package/dist/browser/utils/get-scroll-parents.js.map +1 -1
- package/dist/browser/utils/is-element-visible.js +3 -1
- package/dist/browser/utils/is-element-visible.js.map +1 -1
- package/dist/browser/utils/is-focusable.js +2 -1
- package/dist/browser/utils/is-focusable.js.map +1 -1
- package/dist/browser/utils/shadowdom/dom-functions.d.ts +8 -0
- package/dist/browser/utils/shadowdom/dom-functions.js +26 -7
- package/dist/browser/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/browser/utils/type-helpers.d.ts +42 -0
- package/dist/browser/utils/type-helpers.js +55 -0
- package/dist/browser/utils/type-helpers.js.map +1 -0
- package/dist/server/actiongroup/create-action-group.js +2 -1
- package/dist/server/actiongroup/create-action-group.js.map +1 -1
- package/dist/server/combobox/create-combo-box.js +2 -2
- package/dist/server/combobox/create-combo-box.js.map +1 -1
- package/dist/server/dnd/drag-preview.js +9 -12
- package/dist/server/dnd/drag-preview.js.map +1 -1
- package/dist/server/focus/focus-scope.js +2 -2
- package/dist/server/focus/focus-scope.js.map +1 -1
- package/dist/server/focus/virtual-focus.js +20 -5
- package/dist/server/focus/virtual-focus.js.map +1 -1
- package/dist/server/grid/create-grid-cell.js +4 -4
- package/dist/server/grid/create-grid-cell.js.map +1 -1
- package/dist/server/gridlist/create-grid-list-item.js +3 -3
- package/dist/server/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/server/interactions/create-hover.js +6 -3
- package/dist/server/interactions/create-hover.js.map +1 -1
- package/dist/server/interactions/create-press.js +5 -4
- package/dist/server/interactions/create-press.js.map +1 -1
- package/dist/server/interactions/utils.js +4 -3
- package/dist/server/interactions/utils.js.map +1 -1
- package/dist/server/landmark/create-landmark.js +2 -2
- package/dist/server/landmark/create-landmark.js.map +1 -1
- package/dist/server/overlays/aria-hide-outside.js +5 -3
- package/dist/server/overlays/aria-hide-outside.js.map +1 -1
- package/dist/server/overlays/calculate-position.js +3 -3
- package/dist/server/overlays/calculate-position.js.map +1 -1
- package/dist/server/overlays/create-modal.js +7 -27
- package/dist/server/overlays/create-modal.js.map +1 -1
- package/dist/server/overlays/create-prevent-scroll.js +3 -3
- package/dist/server/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/server/overlays/overlay.js +8 -18
- package/dist/server/overlays/overlay.js.map +1 -1
- package/dist/server/select/create-select.js +1 -1
- package/dist/server/select/create-select.js.map +1 -1
- package/dist/server/select/hidden-select.js +85 -138
- package/dist/server/select/hidden-select.js.map +1 -1
- package/dist/server/selection/create-selectable-item.js +2 -2
- package/dist/server/selection/create-selectable-item.js.map +1 -1
- package/dist/server/selection/create-type-select.js +11 -3
- package/dist/server/selection/create-type-select.js.map +1 -1
- package/dist/server/selection/list-keyboard-delegate.js +1 -1
- package/dist/server/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/server/tokenfield/create-token-field.js +3 -3
- package/dist/server/tokenfield/create-token-field.js.map +1 -1
- package/dist/server/tokenfield/create-token.js +2 -1
- package/dist/server/tokenfield/create-token.js.map +1 -1
- package/dist/server/toolbar/create-toolbar.js +2 -2
- package/dist/server/toolbar/create-toolbar.js.map +1 -1
- package/dist/server/utils/dom-helpers.js +1 -28
- package/dist/server/utils/dom-helpers.js.map +1 -1
- package/dist/server/utils/dom-value.js +2 -1
- package/dist/server/utils/dom-value.js.map +1 -1
- package/dist/server/utils/get-scroll-parent.js +3 -2
- package/dist/server/utils/get-scroll-parent.js.map +1 -1
- package/dist/server/utils/get-scroll-parents.js +2 -1
- package/dist/server/utils/get-scroll-parents.js.map +1 -1
- package/dist/server/utils/is-element-visible.js +3 -1
- package/dist/server/utils/is-element-visible.js.map +1 -1
- package/dist/server/utils/is-focusable.js +2 -1
- package/dist/server/utils/is-focusable.js.map +1 -1
- package/dist/server/utils/shadowdom/dom-functions.js +26 -7
- package/dist/server/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/server/utils/type-helpers.js +55 -0
- package/dist/server/utils/type-helpers.js.map +1 -0
- package/dist/server/virtualizer/scroll-view.js +3 -1
- package/dist/server/virtualizer/scroll-view.js.map +1 -1
- package/package.json +16 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-grid-list-item.js","names":[],"sources":["../../../src/gridlist/create-grid-list-item.ts"],"sourcesContent":["/*\n * Copyright 2022 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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/gridlist/useGridListItem.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { getChildNodes } from \"@solid2-aria/stately/collections/get-child-nodes\";\nimport type { ListState } from \"@solid2-aria/stately/list/create-list-state\";\nimport type { TreeState } from \"@solid2-aria/stately/tree/create-tree-state\";\nimport type {\n FocusableElement,\n Key,\n Node as RSNode,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { untrack, omit, merge, createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getFocusableTreeWalker } from \"../focus/focus-scope\";\nimport { createLocale } from \"../i18n/i18n-provider\";\nimport { isFocusVisible } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { createSelectableItem } from \"../selection/create-selectable-item\";\nimport type { SelectableItemStates } from \"../selection/create-selectable-item\";\nimport type { FocusEvent, KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { chain } from \"../utils/chain\";\nimport { createEvent } from \"../utils/create-event\";\nimport { createSlotId } from \"../utils/create-id\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { elementOrNull, focusableElementOrNull } from \"../utils/dom-value\";\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isPropagationStopped } from \"../utils/is-propagation-stopped\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { createSyntheticLinkProps } from \"../utils/open-link\";\nimport { requireValue } from \"../utils/require-value\";\nimport { scrollIntoViewport } from \"../utils/scroll-into-view\";\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { getRowId, listMap } from \"./utils\";\n\nexport interface AriaGridListItemOptions {\n /**\n * An object representing the list item. Contains all the relevant information that makes up the\n * list row.\n */\n node: RSNode<unknown>;\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: boolean;\n /**\n * Whether the row or its first focusable child element should be focused when the row is\n * focused.\n *\n * @default 'row'\n */\n focusMode?: \"child\" | \"row\";\n /**\n * Whether the row should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows with arrow keys while\n * focus is on an interactive child element within the row.\n */\n allowsArrowNavigation?: boolean;\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes;\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes;\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes;\n}\n\nconst EXPANSION_KEYS: Record<\"expand\" | \"collapse\", Record<string, string>> = {\n collapse: {\n ltr: \"ArrowLeft\",\n rtl: \"ArrowRight\",\n },\n expand: {\n ltr: \"ArrowRight\",\n rtl: \"ArrowLeft\",\n },\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n *\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function createGridListItem<T>(\n props: AriaGridListItemOptions,\n state: ListState<T> | TreeState<T>,\n ref: Accessor<FocusableElement | null>\n): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n const _result0 = props;\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n const _result1 = createLocale();\n\n const listData = requireValue(\n listMap.get(state),\n \"Expected listMap.get(state)\"\n );\n\n const descriptionId = createSlotId();\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused: Key | null = null;\n\n const focus = () => {\n const refElement = ref();\n\n if (refElement === null) {\n return;\n }\n\n if ((_result0.focusMode ?? \"row\") === \"child\") {\n // If focus is already on a focusable child within the row, early return so we don't shift focus\n if (\n isFocusWithin(refElement) &&\n refElement !== getActiveElement(getOwnerDocument(refElement))\n ) {\n return;\n }\n\n const treeWalker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n const focusable = focusableElementOrNull(treeWalker.firstChild());\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(focusable),\n });\n\n return;\n }\n }\n\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n };\n\n const hasLink = createMemo(() =>\n state.selectionManager.isLink(props.node.key)\n );\n\n const hasChildRows = createMemo(\n () =>\n isTruthy(props.hasChildItems) ||\n [...getChildNodes(props.node, state.collection)].some(\n (child) => child.type === \"item\"\n )\n );\n\n const onAction = createMemo((): undefined | ((key: Key) => void) => {\n if (listData.onAction) {\n return listData.onAction;\n }\n\n if (\n \"expandedKeys\" in state &&\n !hasLink() &&\n state.selectionManager.selectionMode === \"none\" &&\n hasChildRows()\n ) {\n return () => {\n state.toggleKey(props.node.key);\n };\n }\n\n return undefined;\n });\n\n const treeGridRowProps = createMemo<DOMAttributes>(() => {\n const { node } = props;\n\n if (!isTruthy(node) || !(\"expandedKeys\" in state)) {\n return {};\n }\n\n const parent = isPresent(node.parentKey)\n ? state.collection.getItem(node.parentKey)\n : null;\n\n const siblings = (\n parent\n ? [...getChildNodes(parent, state.collection)]\n : [...state.collection]\n ).filter((row) => row.type === \"item\" && row.parentKey === node.parentKey);\n\n const position = siblings.findIndex((row) => row.key === node.key);\n\n return {\n \"aria-expanded\": ariaValue(\n hasChildRows() ? state.expandedKeys.has(node.key) : undefined\n ),\n \"aria-level\": node.level + 1,\n \"aria-posinset\": position === -1 ? undefined : position + 1,\n \"aria-setsize\": siblings.length,\n };\n });\n\n const _result2 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get linkBehavior() {\n return listData.linkBehavior;\n },\n get onAction() {\n return onAction() ||\n isTruthy(getCollectionNodeProps(_result0.node)?.onAction)\n ? chain(\n getCollectionNodeProps(_result0.node)?.onAction,\n onAction() ? () => onAction()?.(_result0.node.key) : undefined\n )\n : undefined;\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return (\n getTruthyValue(props.shouldSelectOnPressUp) ??\n listData.shouldSelectOnPressUp\n );\n },\n });\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n if (\n handleTreeExpansionKeys(\n e,\n state,\n _result0.node,\n hasChildRows(),\n _result1.direction,\n activeElement,\n refElement,\n _result0.allowsArrowNavigation\n )\n ) {\n return;\n }\n\n switch (e.key) {\n case \"ArrowLeft\": {\n if (listData.keyboardNavigationBehavior === \"arrow\") {\n // Find the next focusable element within the row.\n const focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(refElement),\n });\n } else if (_result1.direction === \"rtl\") {\n focusSafely(refElement);\n scrollIntoViewport(refElement, {\n containingElement: getScrollParent(refElement),\n });\n } else {\n walker.currentNode = refElement;\n const lastElement = last(walker);\n\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {\n containingElement: getScrollParent(refElement),\n });\n }\n }\n }\n\n break;\n }\n\n case \"ArrowRight\": {\n if (listData.keyboardNavigationBehavior === \"arrow\") {\n const focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(refElement),\n });\n } else if (_result1.direction === \"ltr\") {\n focusSafely(refElement);\n scrollIntoViewport(refElement, {\n containingElement: getScrollParent(refElement),\n });\n } else {\n walker.currentNode = refElement;\n const lastElement = last(walker);\n\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {\n containingElement: getScrollParent(refElement),\n });\n }\n }\n }\n\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {\n e.stopPropagation();\n e.preventDefault();\n refElement.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n const onFocus = (e: FocusEvent<FocusableElement>) => {\n keyWhenFocused = _result0.node.key;\n\n if (getEventTarget(e) !== ref()) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(_result0.node.key);\n }\n\n return;\n }\n\n // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child\n // since that would be a focus trap\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n e.relatedTarget &&\n nodeContains(ref(), elementOrNull(e.relatedTarget))\n ) {\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n listData.keyboardNavigationBehavior === \"arrow\" ||\n isTruthy(_result0.allowsArrowNavigation)\n ) {\n handleCaptureKeyDown(event);\n }\n },\n { capture: true }\n );\n\n const onKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (listData.keyboardNavigationBehavior === \"tab\") {\n // Stop propagation for all events that originate from the children of the gridlist item since we don't want to trigger\n // grid level interactions (row navigation/typeselect/etc)\n // exception made for Tab since that needs to propagate to useSelectableCollection to tab out of the gridlist, might be others?\n if (getEventTarget(e) !== refElement && e.key !== \"Tab\") {\n e.stopPropagation();\n\n return;\n }\n\n if (\n handleTreeExpansionKeys(\n e,\n state,\n _result0.node,\n hasChildRows(),\n _result1.direction,\n activeElement,\n refElement,\n _result0.allowsArrowNavigation\n )\n ) {\n return;\n }\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (listData.keyboardNavigationBehavior === \"tab\") {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n const walker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n walker.currentNode = activeElement;\n const next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n const syntheticLinkProps = createSyntheticLinkProps(\n getCollectionNodeProps(_result0.node)\n );\n\n const linkProps = createMemo(() =>\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n omit(_result2, \"itemProps\")\n // oxlint-enable solid/reactivity\n .hasAction\n ? syntheticLinkProps\n : {}\n );\n // Follow-up: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n const rowProps = createMemo(() => {\n const result = mergeProps(_result2.itemProps, linkProps(), {\n \"aria-disabled\": ariaValue(\n state.selectionManager.isDisabled(_result0.node.key) || undefined\n ),\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n \"aria-label\": ariaValue(\n getTruthyValue(\n getTruthyValue(_result0.node[\"aria-label\"]) ?? _result0.node.textValue\n ) ?? undefined\n ),\n \"aria-labelledby\": ariaValue(\n isTruthy(descriptionId()) &&\n (isTruthy(_result0.node[\"aria-label\"]) || _result0.node.textValue)\n ? `${getRowId(state, _result0.node.key)} ${descriptionId()}`\n : undefined\n ),\n \"aria-selected\": ariaValue(\n state.selectionManager.canSelectItem(_result0.node.key)\n ? state.selectionManager.isSelected(_result0.node.key)\n : undefined\n ),\n id: getRowId(state, _result0.node.key),\n onFocus,\n role: \"row\",\n });\n\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n isTruthy(_result0.allowsArrowNavigation) &&\n listData.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n // we need to guard against space/enter triggering selection/row link via usePress (from itemProps) so check if propagation\n // is stopped. this also fixes space not working in a textfield in a tree parent row\n const baseOnKeyDown = result.onKeyDown;\n result.onKeyDown = (e: DOMKeyboardEvent<FocusableElement>) => {\n untrack(() => {\n onKeyDown(e);\n\n if (!isPropagationStopped(e)) {\n baseOnKeyDown?.(e);\n }\n });\n };\n\n if (isTruthy(_result0.isVirtualized)) {\n const { collection } = state;\n const nodes = [...collection];\n // Follow-up: refactor ListCollection to store an absolute index of a node's position?\n result[\"aria-rowindex\"] = nodes.some((node) => node.type === \"section\")\n ? [...collection.getKeys()]\n .filter((key) => collection.getItem(key)?.type !== \"section\")\n .indexOf(_result0.node.key) + 1\n : _result0.node.index + 1;\n }\n\n return result;\n });\n\n const gridCellProps: DOMAttributes = {\n \"aria-colindex\": ariaValue(1),\n role: \"gridcell\",\n };\n // Follow-up: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n\n return merge(\n {\n get descriptionProps() {\n return {\n get id() {\n return descriptionId();\n },\n };\n },\n get gridCellProps() {\n return gridCellProps;\n },\n get rowProps() {\n return merge(mergeProps(rowProps(), treeGridRowProps()));\n },\n },\n omit(_result2, \"itemProps\")\n );\n}\n\nfunction handleTreeExpansionKeys<T>(\n e: DOMKeyboardEvent,\n state: ListState<T> | TreeState<T>,\n node: RSNode<unknown>,\n hasChildRows: boolean | undefined,\n direction: string,\n activeElement: Element | null,\n rowRef: FocusableElement | null,\n allowsArrowNavigation: boolean | undefined\n): boolean {\n if (\n !(\"expandedKeys\" in state) ||\n (!isTruthy(allowsArrowNavigation) && activeElement !== rowRef)\n ) {\n return false;\n }\n\n if (\n e.key === EXPANSION_KEYS.expand[direction] &&\n state.selectionManager.focusedKey === node.key &&\n isTruthy(hasChildRows) &&\n !state.expandedKeys.has(node.key)\n ) {\n state.toggleKey(node.key);\n e.stopPropagation();\n\n return true;\n } else if (\n e.key === EXPANSION_KEYS.collapse[direction] &&\n state.selectionManager.focusedKey === node.key\n ) {\n // If item is collapsible, collapse it; else move to parent\n if (isTruthy(hasChildRows) && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n\n return true;\n } else if (\n !state.expandedKeys.has(node.key) &&\n isTruthy(node.parentKey) &&\n state.collection.getItem(node.parentKey)?.type === \"item\"\n ) {\n // Item is a leaf or already collapsed, move focus to parent\n state.selectionManager.setFocusedKey(node.parentKey);\n e.stopPropagation();\n\n return true;\n }\n }\n\n return false;\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let lastValue: FocusableElement | null = null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (lastValue) {\n next = lastValue;\n }\n } while (lastValue);\n\n return next;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,MAAM,iBAAwE;CAC5E,UAAU;EACR,KAAK;EACL,KAAK;CACP;CACA,QAAQ;EACN,KAAK;EACL,KAAK;CACP;AACF;;;;;;;;AASA,SAAgB,mBACd,OACA,OACA,KACkB;CAElB,MAAM,WAAW;CAEjB,MAAM,WAAW,aAAa;CAE9B,MAAM,WAAW,aACf,QAAQ,IAAI,KAAK,GACjB,6BACF;CAEA,MAAM,gBAAgB,aAAa;CAGnC,IAAI,iBAA6B;CAEjC,MAAM,cAAc;EAClB,MAAM,aAAa,IAAI;EAEvB,IAAI,eAAe,MACjB;EAGF,KAAK,SAAS,aAAa,WAAW,SAAS;GAE7C,IACE,cAAc,UAAU,KACxB,eAAe,iBAAiB,iBAAiB,UAAU,CAAC,GAE5D;GAGF,MAAM,aAAa,uBAAuB,YAAY,EACpD,UAAU,KACZ,CAAC;GAED,MAAM,YAAY,uBAAuB,WAAW,WAAW,CAAC;GAEhE,IAAI,SAAS,SAAS,GAAG;IACvB,YAAY,SAAS;IACrB,mBAAmB,WAAW,EAC5B,mBAAmB,gBAAgB,SAAS,EAC9C,CAAC;IAED;GACF;EACF;EAIA,IACG,UAAU,cAAc,KAAK,SAAS,KAAK,QAAQ,kBACpD,CAAC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AAU,WAAW,CAC5B;AACF;AAEA,SAAS,wBACP,GACA,OACA,MACA,cACA,WACA,eACA,QACA,uBACS;CACT,IACE,EAAE,kBAAkB,UACnB,CAAC,SAAS,qBAAqB,KAAK,kBAAkB,QAEvD,OAAO;CAGT,IACE,EAAE,QAAQ,eAAe,OAAO,cAChC,MAAM,iBAAiB,eAAe,KAAK,OAC3C,SAAS,YAAY,KACrB,CAAC,MAAM,aAAa,IAAI,KAAK,GAAG,GAChC;EACA,MAAM,UAAU,KAAK,GAAG;EACxB,EAAE,gBAAgB;EAElB,OAAO;CACT,OAAO,IACL,EAAE,QAAQ,eAAe,SAAS,cAClC,MAAM,iBAAiB,eAAe,KAAK,KAC3C;EAEA,IAAI,SAAS,YAAY,KAAK,MAAM,aAAa,IAAI,KAAK,GAAG,GAAG;GAC9D,MAAM,UAAU,KAAK,GAAG;GACxB,EAAE,gBAAgB;GAElB,OAAO;EACT,OAAO,IACL,CAAC,MAAM,aAAa,IAAI,KAAK,GAAG,KAChC,SAAS,KAAK,SAAS,KACvB,MAAM,WAAW,QAAQ,KAAK,SAAS,CAAC,EAAE,SAAS,QACnD;GAEA,MAAM,iBAAiB,cAAc,KAAK,SAAS;GACnD,EAAE,gBAAgB;GAElB,OAAO;EACT;CACF;CAEA,OAAO;AACT;AAEA,SAAS,KAAK,QAAoB;CAChC,IAAI,OAAgC;CACpC,IAAI,YAAqC;CAEzC,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"create-grid-list-item.js","names":[],"sources":["../../../src/gridlist/create-grid-list-item.ts"],"sourcesContent":["/*\n * Copyright 2022 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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/gridlist/useGridListItem.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { getChildNodes } from \"@solid2-aria/stately/collections/get-child-nodes\";\nimport type { ListState } from \"@solid2-aria/stately/list/create-list-state\";\nimport type { TreeState } from \"@solid2-aria/stately/tree/create-tree-state\";\nimport type {\n FocusableElement,\n Key,\n Node as RSNode,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { untrack, omit, merge, createMemo } from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { getFocusableTreeWalker } from \"../focus/focus-scope\";\nimport { createLocale } from \"../i18n/i18n-provider\";\nimport { isFocusVisible } from \"../interactions/create-focus-visible\";\nimport { focusSafely } from \"../interactions/focus-safely\";\nimport { createSelectableItem } from \"../selection/create-selectable-item\";\nimport type { SelectableItemStates } from \"../selection/create-selectable-item\";\nimport type { FocusEvent, KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { chain } from \"../utils/chain\";\nimport { createEvent } from \"../utils/create-event\";\nimport { createSlotId } from \"../utils/create-id\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { elementOrNull, focusableElementOrNull } from \"../utils/dom-value\";\nimport { getCollectionNodeProps } from \"../utils/get-collection-node-props\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { isPropagationStopped } from \"../utils/is-propagation-stopped\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { createSyntheticLinkProps } from \"../utils/open-link\";\nimport { requireValue } from \"../utils/require-value\";\nimport { scrollIntoViewport } from \"../utils/scroll-into-view\";\nimport {\n getActiveElement,\n getEventTarget,\n isFocusWithin,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { getRowId, listMap } from \"./utils\";\n\nexport interface AriaGridListItemOptions {\n /**\n * An object representing the list item. Contains all the relevant information that makes up the\n * list row.\n */\n node: RSNode<unknown>;\n /** Whether the list row is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: boolean;\n /**\n * Whether the row or its first focusable child element should be focused when the row is\n * focused.\n *\n * @default 'row'\n */\n focusMode?: \"child\" | \"row\";\n /**\n * Whether the row should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows with arrow keys while\n * focus is on an interactive child element within the row.\n */\n allowsArrowNavigation?: boolean;\n}\n\nexport interface GridListItemAria extends SelectableItemStates {\n /** Props for the list row element. */\n rowProps: DOMAttributes;\n /** Props for the grid cell element within the list row. */\n gridCellProps: DOMAttributes;\n /** Props for the list item description element, if any. */\n descriptionProps: DOMAttributes;\n}\n\nconst EXPANSION_KEYS: Record<\"expand\" | \"collapse\", Record<string, string>> = {\n collapse: {\n ltr: \"ArrowLeft\",\n rtl: \"ArrowRight\",\n },\n expand: {\n ltr: \"ArrowRight\",\n rtl: \"ArrowLeft\",\n },\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\n *\n * @param props - Props for the row.\n * @param state - State of the parent list, as returned by `useListState`.\n * @param ref - The ref attached to the row element.\n */\nexport function createGridListItem<T>(\n props: AriaGridListItemOptions,\n state: ListState<T> | TreeState<T>,\n ref: Accessor<FocusableElement | null>\n): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n const _result0 = props;\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n const _result1 = createLocale();\n\n const listData = requireValue(\n listMap.get(state),\n \"Expected listMap.get(state)\"\n );\n\n const descriptionId = createSlotId();\n // We need to track the key of the item at the time it was last focused so that we force\n // focus to go to the item when the DOM node is reused for a different item in a virtualizer.\n let keyWhenFocused: Key | null = null;\n\n const focus = () => {\n const refElement = ref();\n\n if (refElement === null) {\n return;\n }\n\n if ((_result0.focusMode ?? \"row\") === \"child\") {\n // If focus is already on a focusable child within the row, early return so we don't shift focus\n if (\n isFocusWithin(refElement) &&\n refElement !== getActiveElement(getOwnerDocument(refElement))\n ) {\n return;\n }\n\n const treeWalker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n const focusable = focusableElementOrNull(treeWalker.firstChild());\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(focusable),\n });\n\n return;\n }\n }\n\n // Don't shift focus to the row if the active element is a element within the row already\n // (e.g. clicking on a row button)\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n };\n\n const hasLink = createMemo(() =>\n state.selectionManager.isLink(props.node.key)\n );\n\n const hasChildRows = createMemo(\n () =>\n isTruthy(props.hasChildItems) ||\n [...getChildNodes(props.node, state.collection)].some(\n (child) => child.type === \"item\"\n )\n );\n\n const onAction = createMemo((): undefined | ((key: Key) => void) => {\n if (listData.onAction) {\n return listData.onAction;\n }\n\n if (\n \"expandedKeys\" in state &&\n !hasLink() &&\n state.selectionManager.selectionMode === \"none\" &&\n hasChildRows()\n ) {\n return () => {\n state.toggleKey(props.node.key);\n };\n }\n\n return undefined;\n });\n\n const treeGridRowProps = createMemo<DOMAttributes>(() => {\n const { node } = props;\n\n if (!isTruthy(node) || !(\"expandedKeys\" in state)) {\n return {};\n }\n\n const parent = isPresent(node.parentKey)\n ? state.collection.getItem(node.parentKey)\n : null;\n\n const siblings = (\n parent\n ? [...getChildNodes(parent, state.collection)]\n : [...state.collection]\n ).filter((row) => row.type === \"item\" && row.parentKey === node.parentKey);\n\n const position = siblings.findIndex((row) => row.key === node.key);\n\n return {\n \"aria-expanded\": ariaValue(\n hasChildRows() ? state.expandedKeys.has(node.key) : undefined\n ),\n \"aria-level\": node.level + 1,\n \"aria-posinset\": position === -1 ? undefined : position + 1,\n \"aria-setsize\": siblings.length,\n };\n });\n\n const _result2 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get linkBehavior() {\n return listData.linkBehavior;\n },\n get onAction() {\n return onAction() ||\n isTruthy(getCollectionNodeProps(_result0.node)?.onAction)\n ? chain(\n getCollectionNodeProps(_result0.node)?.onAction,\n onAction() ? () => onAction()?.(_result0.node.key) : undefined\n )\n : undefined;\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return (\n getTruthyValue(props.shouldSelectOnPressUp) ??\n listData.shouldSelectOnPressUp\n );\n },\n });\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n if (\n handleTreeExpansionKeys(\n e,\n state,\n _result0.node,\n hasChildRows(),\n _result1.direction,\n activeElement,\n refElement,\n _result0.allowsArrowNavigation\n )\n ) {\n return;\n }\n\n switch (e.key) {\n case \"ArrowLeft\": {\n if (listData.keyboardNavigationBehavior === \"arrow\") {\n // Find the next focusable element within the row.\n const focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(refElement),\n });\n } else if (_result1.direction === \"rtl\") {\n focusSafely(refElement);\n scrollIntoViewport(refElement, {\n containingElement: getScrollParent(refElement),\n });\n } else {\n walker.currentNode = refElement;\n const lastElement = last(walker);\n\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {\n containingElement: getScrollParent(refElement),\n });\n }\n }\n }\n\n break;\n }\n\n case \"ArrowRight\": {\n if (listData.keyboardNavigationBehavior === \"arrow\") {\n const focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n e.preventDefault();\n e.stopPropagation();\n\n if (isTruthy(focusable)) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(refElement),\n });\n } else if (_result1.direction === \"ltr\") {\n focusSafely(refElement);\n scrollIntoViewport(refElement, {\n containingElement: getScrollParent(refElement),\n });\n } else {\n walker.currentNode = refElement;\n const lastElement = last(walker);\n\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {\n containingElement: getScrollParent(refElement),\n });\n }\n }\n }\n\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate\n // to the row above/below instead. We need to re-dispatch the event from a higher parent so it still\n // bubbles and gets handled by useSelectableCollection.\n if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {\n e.stopPropagation();\n e.preventDefault();\n getParentElement(refElement)?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n const onFocus = (e: FocusEvent<FocusableElement>) => {\n keyWhenFocused = _result0.node.key;\n\n if (getEventTarget(e) !== ref()) {\n // useSelectableItem only handles setting the focused key when\n // the focused element is the row itself. We also want to\n // set the focused key when a child element receives focus.\n // If focus is currently visible (e.g. the user is navigating with the keyboard),\n // then skip this. We want to restore focus to the previously focused row\n // in that case since the list should act like a single tab stop.\n if (!isFocusVisible()) {\n state.selectionManager.setFocusedKey(_result0.node.key);\n }\n\n return;\n }\n\n // if focus goes back to cell from child, make sure we don't refocus the cell if we are in focusMode=child\n // since that would be a focus trap\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n e.relatedTarget &&\n nodeContains(ref(), elementOrNull(e.relatedTarget))\n ) {\n return;\n }\n\n // If the cell itself is focused, wait a frame so that focus finishes propagating\n // up to the tree, and move focus to a focusable child if possible.\n requestAnimationFrame(() => {\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n listData.keyboardNavigationBehavior === \"arrow\" ||\n isTruthy(_result0.allowsArrowNavigation)\n ) {\n handleCaptureKeyDown(event);\n }\n },\n { capture: true }\n );\n\n const onKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (listData.keyboardNavigationBehavior === \"tab\") {\n // Stop propagation for all events that originate from the children of the gridlist item since we don't want to trigger\n // grid level interactions (row navigation/typeselect/etc)\n // exception made for Tab since that needs to propagate to useSelectableCollection to tab out of the gridlist, might be others?\n if (getEventTarget(e) !== refElement && e.key !== \"Tab\") {\n e.stopPropagation();\n\n return;\n }\n\n if (\n handleTreeExpansionKeys(\n e,\n state,\n _result0.node,\n hasChildRows(),\n _result1.direction,\n activeElement,\n refElement,\n _result0.allowsArrowNavigation\n )\n ) {\n return;\n }\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (listData.keyboardNavigationBehavior === \"tab\") {\n // If there is another focusable element within this item, stop propagation so the tab key\n // is handled by the browser and not by useSelectableCollection (which would take us out of the list).\n const walker = getFocusableTreeWalker(refElement, {\n tabbable: true,\n });\n\n walker.currentNode = activeElement;\n const next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n\n if (next) {\n e.stopPropagation();\n }\n }\n\n break;\n }\n\n default: {\n break;\n }\n }\n };\n\n const syntheticLinkProps = createSyntheticLinkProps(\n getCollectionNodeProps(_result0.node)\n );\n\n const linkProps = createMemo(() =>\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n omit(_result2, \"itemProps\")\n // oxlint-enable solid/reactivity\n .hasAction\n ? syntheticLinkProps\n : {}\n );\n // Follow-up: re-add when we get translations and fix this for iOS VO\n // let rowAnnouncement;\n // if (onAction) {\n // rowAnnouncement = stringFormatter.format('hasActionAnnouncement');\n // } else if (hasLink) {\n // rowAnnouncement = stringFormatter.format('hasLinkAnnouncement', {\n // link: node.props.href\n // });\n // }\n\n const rowProps = createMemo(() => {\n const result = mergeProps(_result2.itemProps, linkProps(), {\n \"aria-disabled\": ariaValue(\n state.selectionManager.isDisabled(_result0.node.key) || undefined\n ),\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n \"aria-label\": ariaValue(\n getTruthyValue(\n getTruthyValue(_result0.node[\"aria-label\"]) ?? _result0.node.textValue\n ) ?? undefined\n ),\n \"aria-labelledby\": ariaValue(\n isTruthy(descriptionId()) &&\n (isTruthy(_result0.node[\"aria-label\"]) || _result0.node.textValue)\n ? `${getRowId(state, _result0.node.key)} ${descriptionId()}`\n : undefined\n ),\n \"aria-selected\": ariaValue(\n state.selectionManager.canSelectItem(_result0.node.key)\n ? state.selectionManager.isSelected(_result0.node.key)\n : undefined\n ),\n id: getRowId(state, _result0.node.key),\n onFocusIn: onFocus,\n role: \"row\",\n });\n\n if (\n (_result0.focusMode ?? \"row\") === \"child\" &&\n isTruthy(_result0.allowsArrowNavigation) &&\n listData.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n // we need to guard against space/enter triggering selection/row link via usePress (from itemProps) so check if propagation\n // is stopped. this also fixes space not working in a textfield in a tree parent row\n const baseOnKeyDown = result.onKeyDown;\n result.onKeyDown = (e: DOMKeyboardEvent<FocusableElement>) => {\n untrack(() => {\n onKeyDown(e);\n\n if (!isPropagationStopped(e)) {\n baseOnKeyDown?.(e);\n }\n });\n };\n\n if (isTruthy(_result0.isVirtualized)) {\n const { collection } = state;\n const nodes = [...collection];\n // Follow-up: refactor ListCollection to store an absolute index of a node's position?\n result[\"aria-rowindex\"] = nodes.some((node) => node.type === \"section\")\n ? [...collection.getKeys()]\n .filter((key) => collection.getItem(key)?.type !== \"section\")\n .indexOf(_result0.node.key) + 1\n : _result0.node.index + 1;\n }\n\n return result;\n });\n\n const gridCellProps: DOMAttributes = {\n \"aria-colindex\": ariaValue(1),\n role: \"gridcell\",\n };\n // Follow-up: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n\n return merge(\n {\n get descriptionProps() {\n return {\n get id() {\n return descriptionId();\n },\n };\n },\n get gridCellProps() {\n return gridCellProps;\n },\n get rowProps() {\n return merge(mergeProps(rowProps(), treeGridRowProps()));\n },\n },\n omit(_result2, \"itemProps\")\n );\n}\n\nfunction handleTreeExpansionKeys<T>(\n e: DOMKeyboardEvent,\n state: ListState<T> | TreeState<T>,\n node: RSNode<unknown>,\n hasChildRows: boolean | undefined,\n direction: string,\n activeElement: Element | null,\n rowRef: FocusableElement | null,\n allowsArrowNavigation: boolean | undefined\n): boolean {\n if (\n !(\"expandedKeys\" in state) ||\n (!isTruthy(allowsArrowNavigation) && activeElement !== rowRef)\n ) {\n return false;\n }\n\n if (\n e.key === EXPANSION_KEYS.expand[direction] &&\n state.selectionManager.focusedKey === node.key &&\n isTruthy(hasChildRows) &&\n !state.expandedKeys.has(node.key)\n ) {\n state.toggleKey(node.key);\n e.stopPropagation();\n\n return true;\n } else if (\n e.key === EXPANSION_KEYS.collapse[direction] &&\n state.selectionManager.focusedKey === node.key\n ) {\n // If item is collapsible, collapse it; else move to parent\n if (isTruthy(hasChildRows) && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n\n return true;\n } else if (\n !state.expandedKeys.has(node.key) &&\n isTruthy(node.parentKey) &&\n state.collection.getItem(node.parentKey)?.type === \"item\"\n ) {\n // Item is a leaf or already collapsed, move focus to parent\n state.selectionManager.setFocusedKey(node.parentKey);\n e.stopPropagation();\n\n return true;\n }\n }\n\n return false;\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement | null = null;\n let lastValue: FocusableElement | null = null;\n\n do {\n lastValue = focusableElementOrNull(walker.lastChild());\n\n if (lastValue) {\n next = lastValue;\n }\n } while (lastValue);\n\n return next;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,MAAM,iBAAwE;CAC5E,UAAU;EACR,KAAK;EACL,KAAK;CACP;CACA,QAAQ;EACN,KAAK;EACL,KAAK;CACP;AACF;;;;;;;;AASA,SAAgB,mBACd,OACA,OACA,KACkB;CAElB,MAAM,WAAW;CAEjB,MAAM,WAAW,aAAa;CAE9B,MAAM,WAAW,aACf,QAAQ,IAAI,KAAK,GACjB,6BACF;CAEA,MAAM,gBAAgB,aAAa;CAGnC,IAAI,iBAA6B;CAEjC,MAAM,cAAc;EAClB,MAAM,aAAa,IAAI;EAEvB,IAAI,eAAe,MACjB;EAGF,KAAK,SAAS,aAAa,WAAW,SAAS;GAE7C,IACE,cAAc,UAAU,KACxB,eAAe,iBAAiB,iBAAiB,UAAU,CAAC,GAE5D;GAGF,MAAM,aAAa,uBAAuB,YAAY,EACpD,UAAU,KACZ,CAAC;GAED,MAAM,YAAY,uBAAuB,WAAW,WAAW,CAAC;GAEhE,IAAI,SAAS,SAAS,GAAG;IACvB,YAAY,SAAS;IACrB,mBAAmB,WAAW,EAC5B,mBAAmB,gBAAgB,SAAS,EAC9C,CAAC;IAED;GACF;EACF;EAIA,IACG,UAAU,cAAc,KAAK,SAAS,KAAK,QAAQ,kBACpD,CAAC,cAAc,UAAU,G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KAAK,UAAU,WAAW,CAC5B;AACF;AAEA,SAAS,wBACP,GACA,OACA,MACA,cACA,WACA,eACA,QACA,uBACS;CACT,IACE,EAAE,kBAAkB,UACnB,CAAC,SAAS,qBAAqB,KAAK,kBAAkB,QAEvD,OAAO;CAGT,IACE,EAAE,QAAQ,eAAe,OAAO,cAChC,MAAM,iBAAiB,eAAe,KAAK,OAC3C,SAAS,YAAY,KACrB,CAAC,MAAM,aAAa,IAAI,KAAK,GAAG,GAChC;EACA,MAAM,UAAU,KAAK,GAAG;EACxB,EAAE,gBAAgB;EAElB,OAAO;CACT,OAAO,IACL,EAAE,QAAQ,eAAe,SAAS,cAClC,MAAM,iBAAiB,eAAe,KAAK,KAC3C;EAEA,IAAI,SAAS,YAAY,KAAK,MAAM,aAAa,IAAI,KAAK,GAAG,GAAG;GAC9D,MAAM,UAAU,KAAK,GAAG;GACxB,EAAE,gBAAgB;GAElB,OAAO;EACT,OAAO,IACL,CAAC,MAAM,aAAa,IAAI,KAAK,GAAG,KAChC,SAAS,KAAK,SAAS,KACvB,MAAM,WAAW,QAAQ,KAAK,SAAS,CAAC,EAAE,SAAS,QACnD;GAEA,MAAM,iBAAiB,cAAc,KAAK,SAAS;GACnD,EAAE,gBAAgB;GAElB,OAAO;EACT;CACF;CAEA,OAAO;AACT;AAEA,SAAS,KAAK,QAAoB;CAChC,IAAI,OAAgC;CACpC,IAAI,YAAqC;CAEzC,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
|
|
@@ -22,11 +22,14 @@ import { createGlobalListeners } from "../utils/create-global-listeners.js";
|
|
|
22
22
|
import { createEffect, createSignal, onSettled, untrack } from "solid-js";
|
|
23
23
|
// src/interactions/create-hover.ts
|
|
24
24
|
let globalIgnoreEmulatedMouseEvents = false;
|
|
25
|
+
let globalIgnoreEmulatedMouseEventsTimeout = null;
|
|
25
26
|
let hoverCount = 0;
|
|
26
27
|
function setGlobalIgnoreEmulatedMouseEvents() {
|
|
27
28
|
globalIgnoreEmulatedMouseEvents = true;
|
|
28
|
-
|
|
29
|
+
if (globalIgnoreEmulatedMouseEventsTimeout !== null) clearTimeout(globalIgnoreEmulatedMouseEventsTimeout);
|
|
30
|
+
globalIgnoreEmulatedMouseEventsTimeout = setTimeout(() => {
|
|
29
31
|
globalIgnoreEmulatedMouseEvents = false;
|
|
32
|
+
globalIgnoreEmulatedMouseEventsTimeout = null;
|
|
30
33
|
}, 500);
|
|
31
34
|
}
|
|
32
35
|
function handleGlobalPointerEvent(e) {
|
|
@@ -63,9 +66,9 @@ function createHover(props) {
|
|
|
63
66
|
const _result1 = createGlobalListeners();
|
|
64
67
|
function triggerHoverEnd(event, pointerType) {
|
|
65
68
|
const { target } = state;
|
|
69
|
+
if (pointerType !== "mouse" && pointerType !== "pen" || !state.isHovered || !target) return;
|
|
66
70
|
state.pointerType = "";
|
|
67
71
|
state.target = null;
|
|
68
|
-
if (pointerType !== "mouse" && pointerType !== "pen" || !state.isHovered || !target) return;
|
|
69
72
|
state.isHovered = false;
|
|
70
73
|
_result1.removeAllGlobalListeners();
|
|
71
74
|
if (props.onHoverEnd) props.onHoverEnd({
|
|
@@ -77,8 +80,8 @@ function createHover(props) {
|
|
|
77
80
|
setHovered(false);
|
|
78
81
|
}
|
|
79
82
|
const triggerHoverStart = (event, pointerType) => {
|
|
80
|
-
state.pointerType = pointerType;
|
|
81
83
|
if (isTruthy(props.isDisabled) || pointerType !== "mouse" && pointerType !== "pen" || state.isHovered || !(event.currentTarget instanceof Element) || !nodeContains(event.currentTarget, requireElement(getEventTarget(event)))) return;
|
|
84
|
+
state.pointerType = pointerType;
|
|
82
85
|
state.isHovered = true;
|
|
83
86
|
const target = event.currentTarget;
|
|
84
87
|
if (!(target instanceof HTMLElement)) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-hover.js","names":[],"sources":["../../../src/interactions/create-hover.ts"],"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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/useHover.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { HoverEvents } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createEffect, createSignal, onSettled, untrack } from \"solid-js\";\n\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { requireElement } from \"../utils/dom-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { isTruthy } from \"../utils/truthy\";\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean;\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes;\n isHovered: boolean;\n}\n\ninterface HoverState {\n ignoreEmulatedMouseEvents: boolean;\n isHovered: boolean;\n pointerType: string;\n target: HTMLElement | null;\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n }, 500);\n}\n\nfunction handleGlobalPointerEvent(e: PointerEvent) {\n if (e.pointerType === \"touch\") {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents(): undefined | (() => void) {\n const ownerDocument = getOwnerDocument(null);\n\n if (ownerDocument === undefined) {\n return undefined;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== \"undefined\") {\n ownerDocument.addEventListener(\"pointerup\", handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === \"test\") {\n ownerDocument.addEventListener(\n \"touchend\",\n setGlobalIgnoreEmulatedMouseEvents\n );\n }\n }\n\n hoverCount += 1;\n\n return () => {\n hoverCount -= 1;\n\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n ownerDocument.removeEventListener(\"pointerup\", handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === \"test\") {\n ownerDocument.removeEventListener(\n \"touchend\",\n setGlobalIgnoreEmulatedMouseEvents\n );\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function createHover(props: HoverProps): HoverResult {\n const [isHovered, setHovered] = createSignal(false, { ownedWrite: true });\n\n const state: HoverState = {\n ignoreEmulatedMouseEvents: false,\n isHovered: false,\n pointerType: \"\",\n target: null,\n };\n\n onSettled(setupGlobalTouchEvents);\n const _result1 = createGlobalListeners();\n\n function triggerHoverEnd(\n event: {\n currentTarget: EventTarget | null;\n },\n pointerType: string\n ) {\n const { target } = state;\n state.pointerType = \"\";\n state.target = null;\n\n if (\n (pointerType !== \"mouse\" && pointerType !== \"pen\") ||\n !state.isHovered ||\n !target\n ) {\n return;\n }\n\n state.isHovered = false;\n _result1.removeAllGlobalListeners();\n\n if (props.onHoverEnd) {\n props.onHoverEnd({\n pointerType,\n target,\n type: \"hoverend\",\n });\n }\n\n if (props.onHoverChange) {\n props.onHoverChange(false);\n }\n\n setHovered(false);\n }\n\n const triggerHoverStart = (\n event: MouseEvent | PointerEvent,\n pointerType: string\n ) => {\n state.pointerType = pointerType;\n\n if (\n isTruthy(props.isDisabled) ||\n (pointerType !== \"mouse\" && pointerType !== \"pen\") ||\n state.isHovered ||\n !(event.currentTarget instanceof Element) ||\n !nodeContains(event.currentTarget, requireElement(getEventTarget(event)))\n ) {\n return;\n }\n\n state.isHovered = true;\n const target = event.currentTarget;\n\n if (!(target instanceof HTMLElement)) {\n return;\n }\n\n state.target = target;\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n _result1.addGlobalListener(\n getOwnerDocument(requireElement(getEventTarget(event))),\n \"pointerover\",\n (e) => {\n if (\n state.isHovered &&\n state.target &&\n !nodeContains(state.target, requireElement(getEventTarget(e)))\n ) {\n triggerHoverEnd(e, e.pointerType);\n }\n },\n { capture: true }\n );\n\n if (props.onHoverStart) {\n props.onHoverStart({\n pointerType,\n target,\n type: \"hoverstart\",\n });\n }\n\n if (props.onHoverChange) {\n props.onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n const hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== \"undefined\") {\n hoverProps.onPointerEnter = (e) => {\n untrack(() => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === \"mouse\") {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n });\n };\n\n hoverProps.onPointerLeave = (e) => {\n untrack(() => {\n if (\n !isTruthy(props.isDisabled) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n triggerHoverEnd(e, e.pointerType);\n }\n });\n };\n } else if (process.env.NODE_ENV === \"test\") {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n untrack(() => {\n if (\n !state.ignoreEmulatedMouseEvents &&\n !globalIgnoreEmulatedMouseEvents\n ) {\n triggerHoverStart(e, \"mouse\");\n }\n\n state.ignoreEmulatedMouseEvents = false;\n });\n };\n\n hoverProps.onMouseLeave = (e) => {\n untrack(() => {\n if (\n !isTruthy(props.isDisabled) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n triggerHoverEnd(e, \"mouse\");\n }\n });\n };\n }\n\n createEffect(\n () => props.isDisabled,\n (disabled) => {\n if (disabled === true) {\n untrack(() => {\n triggerHoverEnd({ currentTarget: state.target }, state.pointerType);\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get hoverProps() {\n return hoverProps;\n },\n get isHovered() {\n return isHovered();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAI,kCAAkC;AACtC,IAAI,aAAa;AAEjB,SAAS,qCAAqC;CAC5C,kCAAkC;CAKlC,iBAAiB;EACf,kCAAkC;CACpC,GAAG,GAAG;AACR;AAEA,SAAS,yBAAyB,GAAiB;CACjD,IAAI,EAAE,gBAAgB,SACpB,mCAAmC;AAEvC;AAEA,SAAS,yBAAmD;CAC1D,MAAM,gBAAgB,iBAAiB,IAAI;CAE3C,IAAI,kBAAkB,KAAA,GACpB;CAGF,IAAI,eAAe,GAAG;EACpB,IAAI,OAAO,iBAAiB,aAC1B,cAAc,iBAAiB,aAAa,wBAAwB;OAC/D,IAAI,QAAQ,IAAI,aAAa,QAClC,cAAc,iBACZ,YACA,kCACF;CAEJ;CAEA,cAAc;CAEd,aAAa;EACX,cAAc;EAEd,IAAI,aAAa,GACf;EAGF,IAAI,OAAO,iBAAiB,aAC1B,cAAc,oBAAoB,aAAa,wBAAwB;OAClE,IAAI,QAAQ,IAAI,aAA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AI;EAG1B,WAAW,IAAI;CACjB;CAEA,MAAM,aAA4B,CAAC;CAEnC,IAAI,OAAO,iBAAiB,aAAa;EACvC,WAAW,kBAAkB,MAAM;GACjC,cAAc;IACZ,IAAI,mCAAmC,EAAE,gBAAgB,SACvD;IAGF,kBAAkB,GAAG,EAAE,WAAW;GACpC,CAAC;EACH;EAEA,WAAW,kBAAkB,MAAM;GACjC,cAAc;IACZ,IACE,CAAC,SAAS,MAAM,UAAU,KAC1B,aAAa,EAAE,eAAe,eAAe,CAAC,CAAC,GAE/C,gBAAgB,GAAG,EAAE,WAAW;GAEpC,CAAC;EACH;CACF,OAAO,IAAI,QAAQ,IAAI,aAAa,QAAQ;EAC1C,WAAW,qBAAqB;GAC9B,MAAM,4BAA4B;EACpC;EAEA,WAAW,gBAAgB,MAAM;GAC/B,cAAc;IACZ,IACE,CAAC,MAAM,6BACP,CAAC,iCAED,kBAAkB,GAAG,OAAO;IAG9B,MAAM,4BAA4B;GACpC,CAAC;EACH;EAEA,WAAW,gBAAgB,MAAM;GAC/B,cAAc;IACZ,IACE,CAAC,SAAS,MAAM,UAAU,KAC1B,aAAa,EAAE,eAAe,eAAe,CAAC,CAAC,GAE/C,gBAAgB,GAAG,OAAO;GAE9B,CAAC;EACH;CACF;CAEA,mBACQ,MAAM,aACX,aAAa;EACZ,IAAI,aAAa,MACf,cAAc;GACZ,gBAAgB,EAAE,eAAe,MAAM,OAAO,GAAG,MAAM,WAAW;EACpE,CAAC;CAEL,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO;EACL,IAAI,aAAa;GACf,OAAO;EACT;EACA,IAAI,YAAY;GACd,OAAO,UAAU;EACnB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-hover.js","names":[],"sources":["../../../src/interactions/create-hover.ts"],"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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/useHover.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { HoverEvents } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { createEffect, createSignal, onSettled, untrack } from \"solid-js\";\n\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { requireElement } from \"../utils/dom-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { isTruthy } from \"../utils/truthy\";\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean;\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes;\n isHovered: boolean;\n}\n\ninterface HoverState {\n ignoreEmulatedMouseEvents: boolean;\n isHovered: boolean;\n pointerType: string;\n target: HTMLElement | null;\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\n\nlet globalIgnoreEmulatedMouseEventsTimeout: ReturnType<\n typeof setTimeout\n> | null = null;\n\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n if (globalIgnoreEmulatedMouseEventsTimeout !== null) {\n clearTimeout(globalIgnoreEmulatedMouseEventsTimeout);\n }\n\n globalIgnoreEmulatedMouseEventsTimeout = setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n globalIgnoreEmulatedMouseEventsTimeout = null;\n }, 500);\n}\n\nfunction handleGlobalPointerEvent(e: PointerEvent) {\n if (e.pointerType === \"touch\") {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents(): undefined | (() => void) {\n const ownerDocument = getOwnerDocument(null);\n\n if (ownerDocument === undefined) {\n return undefined;\n }\n\n if (hoverCount === 0) {\n if (typeof PointerEvent !== \"undefined\") {\n ownerDocument.addEventListener(\"pointerup\", handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === \"test\") {\n ownerDocument.addEventListener(\n \"touchend\",\n setGlobalIgnoreEmulatedMouseEvents\n );\n }\n }\n\n hoverCount += 1;\n\n return () => {\n hoverCount -= 1;\n\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n ownerDocument.removeEventListener(\"pointerup\", handleGlobalPointerEvent);\n } else if (process.env.NODE_ENV === \"test\") {\n ownerDocument.removeEventListener(\n \"touchend\",\n setGlobalIgnoreEmulatedMouseEvents\n );\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function createHover(props: HoverProps): HoverResult {\n const [isHovered, setHovered] = createSignal(false, { ownedWrite: true });\n\n const state: HoverState = {\n ignoreEmulatedMouseEvents: false,\n isHovered: false,\n pointerType: \"\",\n target: null,\n };\n\n onSettled(setupGlobalTouchEvents);\n const _result1 = createGlobalListeners();\n\n function triggerHoverEnd(\n event: {\n currentTarget: EventTarget | null;\n },\n pointerType: string\n ) {\n const { target } = state;\n\n if (\n (pointerType !== \"mouse\" && pointerType !== \"pen\") ||\n !state.isHovered ||\n !target\n ) {\n return;\n }\n\n state.pointerType = \"\";\n state.target = null;\n state.isHovered = false;\n _result1.removeAllGlobalListeners();\n\n if (props.onHoverEnd) {\n props.onHoverEnd({\n pointerType,\n target,\n type: \"hoverend\",\n });\n }\n\n if (props.onHoverChange) {\n props.onHoverChange(false);\n }\n\n setHovered(false);\n }\n\n const triggerHoverStart = (\n event: MouseEvent | PointerEvent,\n pointerType: string\n ) => {\n if (\n isTruthy(props.isDisabled) ||\n (pointerType !== \"mouse\" && pointerType !== \"pen\") ||\n state.isHovered ||\n !(event.currentTarget instanceof Element) ||\n !nodeContains(event.currentTarget, requireElement(getEventTarget(event)))\n ) {\n return;\n }\n\n state.pointerType = pointerType;\n state.isHovered = true;\n const target = event.currentTarget;\n\n if (!(target instanceof HTMLElement)) {\n return;\n }\n\n state.target = target;\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n _result1.addGlobalListener(\n getOwnerDocument(requireElement(getEventTarget(event))),\n \"pointerover\",\n (e) => {\n if (\n state.isHovered &&\n state.target &&\n !nodeContains(state.target, requireElement(getEventTarget(e)))\n ) {\n triggerHoverEnd(e, e.pointerType);\n }\n },\n { capture: true }\n );\n\n if (props.onHoverStart) {\n props.onHoverStart({\n pointerType,\n target,\n type: \"hoverstart\",\n });\n }\n\n if (props.onHoverChange) {\n props.onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n const hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== \"undefined\") {\n hoverProps.onPointerEnter = (e) => {\n untrack(() => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === \"mouse\") {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n });\n };\n\n hoverProps.onPointerLeave = (e) => {\n untrack(() => {\n if (\n !isTruthy(props.isDisabled) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n triggerHoverEnd(e, e.pointerType);\n }\n });\n };\n } else if (process.env.NODE_ENV === \"test\") {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n untrack(() => {\n if (\n !state.ignoreEmulatedMouseEvents &&\n !globalIgnoreEmulatedMouseEvents\n ) {\n triggerHoverStart(e, \"mouse\");\n }\n\n state.ignoreEmulatedMouseEvents = false;\n });\n };\n\n hoverProps.onMouseLeave = (e) => {\n untrack(() => {\n if (\n !isTruthy(props.isDisabled) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n triggerHoverEnd(e, \"mouse\");\n }\n });\n };\n }\n\n createEffect(\n () => props.isDisabled,\n (disabled) => {\n if (disabled === true) {\n untrack(() => {\n triggerHoverEnd({ currentTarget: state.target }, state.pointerType);\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get hoverProps() {\n return hoverProps;\n },\n get isHovered() {\n return isHovered();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAI,kCAAkC;AAEtC,IAAI,yCAEO;AAEX,IAAI,aAAa;AAEjB,SAAS,qCAAqC;CAC5C,kCAAkC;CAMlC,IAAI,2CAA2C,MAC7C,aAAa,sCAAsC;CAGrD,yCAAyC,iBAAiB;EACxD,kCAAkC;EAClC,yCAAyC;CAC3C,GAAG,GAAG;AACR;AAEA,SAAS,yBAAyB,GAAiB;CACjD,IAAI,EAAE,gBAAgB,SACpB,mCAAmC;AAEvC;AAEA,SAAS,yBAAmD;CAC1D,MAAM,gBAAgB,iBAAiB,IAAI;CAE3C,IAAI,kBAAkB,KAAA,GACpB;CAGF,IAAI,eAAe,GAAG;EACpB,IAAI,OAAO,iBAAiB,aAC1B,cAAc,iBAAiB,aAAa,wBAAwB;OAC/D,IAAI,QAAQ,IAAI,aAAa,Q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
@@ -291,7 +291,7 @@ function createPress(props) {
|
|
|
291
291
|
},
|
|
292
292
|
onKeyDown(e) {
|
|
293
293
|
if (isValidKeyboardEvent(e, e.currentTarget) && nodeContains(e.currentTarget, getEventTarget(e))) {
|
|
294
|
-
if (shouldPreventDefaultKeyboard(getEventTarget(e), e
|
|
294
|
+
if (shouldPreventDefaultKeyboard(getEventTarget(e), e)) e.preventDefault();
|
|
295
295
|
let shouldStopPropagation = true;
|
|
296
296
|
if (!state.isPressed && !e.repeat) {
|
|
297
297
|
state.target = e.currentTarget;
|
|
@@ -311,7 +311,7 @@ function createPress(props) {
|
|
|
311
311
|
};
|
|
312
312
|
function onKeyUp(e) {
|
|
313
313
|
if (state.isPressed && state.target && isValidKeyboardEvent(e, state.target)) {
|
|
314
|
-
if (shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e
|
|
314
|
+
if (shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e)) e.preventDefault();
|
|
315
315
|
const target = getEventTarget(e);
|
|
316
316
|
const wasPressed = nodeContains(state.target, requireElement(target));
|
|
317
317
|
triggerPressEndEvent(createEvent(state.target, e), "keyboard", wasPressed);
|
|
@@ -606,8 +606,9 @@ function shouldPreventDefaultUp(target) {
|
|
|
606
606
|
if (isHTMLAnchorLink(target)) return false;
|
|
607
607
|
return true;
|
|
608
608
|
}
|
|
609
|
-
function shouldPreventDefaultKeyboard(target,
|
|
610
|
-
|
|
609
|
+
function shouldPreventDefaultKeyboard(target, event) {
|
|
610
|
+
const { key } = event;
|
|
611
|
+
if (isMac() && key === "Enter" && event.ctrlKey) return false;
|
|
611
612
|
if (target instanceof HTMLInputElement) {
|
|
612
613
|
if (key === "Enter" && (target.type === "checkbox" || target.type === "radio")) return false;
|
|
613
614
|
return !isValidInputKey(target, key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-press.js","names":[],"sources":["../../../src/interactions/create-press.ts"],"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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/usePress.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; register the initial press responder in an explicit untracked lifecycle scope.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n FocusableElement,\n PressEvent as IPressEvent,\n PointerType,\n PressEvents,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n omit,\n untrack,\n useContext,\n createEffect,\n createSignal,\n flush,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type {\n MouseEvent as TargetedMouseEvent,\n TouchEvent as TargetedTouchEvent,\n} from \"../types\";\nimport { chain } from \"../utils/chain\";\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n requireElement,\n requireFocusableElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n isVirtualClick,\n isVirtualPointerEvent,\n} from \"../utils/is-virtual-event\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink } from \"../utils/open-link\";\nimport { isMac } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { PressResponderContext } from \"./context\";\nimport { disableTextSelection, restoreTextSelection } from \"./text-selection\";\nimport { preventFocus, setEventTarget } from \"./utils\";\n\nexport interface PressProps extends PressEvents {\n /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */\n isPressed?: boolean;\n /** Whether the press events should be disabled. */\n isDisabled?: boolean;\n /** Whether the target should not receive focus on press. */\n preventFocusOnPress?: boolean;\n /**\n * Whether press events should be canceled when the pointer leaves the target while pressed.\n * By default, this is `false`, which means if the pointer returns back over the target while\n * still pressed, onPressStart will be fired again. If set to `true`, the press is canceled\n * when the pointer leaves the target and onPressStart will not be fired if the pointer returns.\n */\n shouldCancelOnPointerExit?: boolean;\n /** Whether text selection should be enabled on the pressable element. */\n allowTextSelectionOnPress?: boolean;\n}\n\nexport interface PressHookProps extends PressProps {\n /** A ref to the target element. */\n ref?: Accessor<Element | null>;\n}\n\ninterface PressState {\n isPressed: boolean;\n ignoreEmulatedMouseEvents: boolean;\n didFirePressStart: boolean;\n isTriggeringEvent: boolean;\n activePointerId: number | null;\n target: FocusableElement | null;\n isOverTarget: boolean;\n pointerType: PointerType | null;\n userSelect?: string;\n metaKeyEvents?: Map<string, globalThis.KeyboardEvent>;\n disposables: (() => void)[];\n}\n\ninterface EventBase {\n currentTarget: EventTarget | null;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n clientX?: number;\n clientY?: number;\n targetTouches?: {\n clientX?: number;\n clientY?: number;\n }[];\n key?: string;\n}\n\nexport interface PressResult {\n /** Whether the target is currently pressed. */\n isPressed: boolean;\n /** Props to spread on the target element. */\n pressProps: DOMAttributes;\n}\n\nfunction createPressResponderContext(props: PressHookProps): PressHookProps {\n const context = useContext(PressResponderContext);\n const currentProps = mergeProps(omit(context, \"register\", \"ref\"), props);\n untrack(() => {\n context.register();\n });\n\n createEffect(\n () => ({ element: currentProps.ref?.(), setRef: context.ref }),\n ({ element, setRef }) => {\n if (element instanceof HTMLElement || element instanceof SVGElement) {\n setRef?.(element);\n }\n },\n { ssrSource: \"client\" }\n );\n\n return currentProps;\n}\n\nclass PressEvent implements IPressEvent {\n type: IPressEvent[\"type\"];\n pointerType: PointerType;\n target: Element;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n x: number;\n y: number;\n key: string | undefined;\n #shouldStopPropagation = true;\n constructor(\n type: IPressEvent[\"type\"],\n pointerType: PointerType,\n originalEvent: EventBase,\n state?: PressState\n ) {\n const currentTarget = state?.target ?? originalEvent.currentTarget;\n\n const rect: DOMRect | undefined =\n requireElement(currentTarget)?.getBoundingClientRect();\n\n let x = 0;\n let y = 0;\n\n let clientX;\n let clientY: number | null = null;\n\n if (\n isPresent(originalEvent.clientX) &&\n originalEvent.clientY !== null &&\n originalEvent.clientY !== undefined\n ) {\n ({ clientX } = originalEvent);\n ({ clientY } = originalEvent);\n }\n\n if (isTruthy(rect)) {\n if (isPresent(clientX) && clientY !== null && clientY !== undefined) {\n x = clientX - rect.left;\n y = clientY - rect.top;\n } else {\n x = rect.width / 2;\n y = rect.height / 2;\n }\n }\n\n this.type = type;\n this.pointerType = pointerType;\n this.target = requireElement(originalEvent.currentTarget);\n this.shiftKey = originalEvent.shiftKey;\n this.metaKey = originalEvent.metaKey;\n this.ctrlKey = originalEvent.ctrlKey;\n this.altKey = originalEvent.altKey;\n this.x = x;\n this.y = y;\n this.key = originalEvent.key;\n }\n continuePropagation() {\n this.#shouldStopPropagation = false;\n }\n get shouldStopPropagation() {\n return this.#shouldStopPropagation;\n }\n}\n\nconst linkedEvents = new WeakSet<Event>();\n\nfunction parsePointerType(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Validate optional native event extensions before storing their pointer type.\n value: unknown\n): PointerType {\n return value === \"touch\" ||\n value === \"pen\" ||\n value === \"keyboard\" ||\n value === \"virtual\"\n ? value\n : \"mouse\";\n}\n\nconst STYLE_ID = \"react-aria-pressable-style\";\nconst PRESSABLE_ATTRIBUTE = \"data-react-aria-pressable\";\n\n/**\n * Handles press interactions across mouse, touch, keyboard, and screen readers.\n * It normalizes behavior across browsers and platforms, and handles many nuances\n * of dealing with pointer and keyboard events.\n */\nexport function createPress(props: PressHookProps): PressResult {\n const _result0 = createPressResponderContext(props);\n const [isPressed, setPressed] = createSignal(false, { ownedWrite: true });\n\n const ref: PressState = {\n activePointerId: null,\n didFirePressStart: false,\n disposables: [],\n ignoreEmulatedMouseEvents: false,\n isOverTarget: false,\n isPressed: false,\n isTriggeringEvent: false,\n pointerType: null,\n target: null,\n };\n\n const _result1 = createGlobalListeners();\n\n const triggerPressStart = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled) || state.didFirePressStart) {\n return false;\n }\n\n let shouldStopPropagation = true;\n state.isTriggeringEvent = true;\n\n if (_result0.onPressStart) {\n const event = new PressEvent(\"pressstart\", pointerType, originalEvent);\n _result0.onPressStart(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(true);\n }\n\n state.isTriggeringEvent = false;\n state.didFirePressStart = true;\n setPressed(true);\n\n return shouldStopPropagation;\n };\n\n const triggerPressEnd = (\n originalEvent: EventBase,\n pointerType: PointerType,\n wasPressed = true\n ) => {\n const state = ref;\n\n if (!state.didFirePressStart) {\n return false;\n }\n\n state.didFirePressStart = false;\n state.isTriggeringEvent = true;\n let shouldStopPropagation = true;\n\n if (_result0.onPressEnd) {\n const event = new PressEvent(\"pressend\", pointerType, originalEvent);\n _result0.onPressEnd(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(false);\n }\n\n setPressed(false);\n\n if (_result0.onPress && wasPressed && !isTruthy(_result0.isDisabled)) {\n const event = new PressEvent(\"press\", pointerType, originalEvent);\n _result0.onPress(event);\n shouldStopPropagation &&= event.shouldStopPropagation;\n }\n\n state.isTriggeringEvent = false;\n\n return shouldStopPropagation;\n };\n\n const triggerPressEndEvent = triggerPressEnd;\n\n const triggerPressUp = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled)) {\n return false;\n }\n\n if (_result0.onPressUp) {\n state.isTriggeringEvent = true;\n const event = new PressEvent(\"pressup\", pointerType, originalEvent);\n _result0.onPressUp(event);\n state.isTriggeringEvent = false;\n\n return event.shouldStopPropagation;\n }\n\n return true;\n };\n\n const triggerPressUpEvent = triggerPressUp;\n\n const cancel = (e: EventBase) => {\n const state = ref;\n\n if (state.isPressed && state.target) {\n if (\n state.didFirePressStart &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressEnd(createEvent(state.target, e), state.pointerType, false);\n }\n\n state.isPressed = false;\n state.isOverTarget = false;\n state.activePointerId = null;\n state.pointerType = null;\n _result1.removeAllGlobalListeners();\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n }\n };\n\n const cancelEvent = cancel;\n createEffect(\n () => _result0.isDisabled,\n (disabled) => {\n if (disabled === true && ref.isPressed) {\n untrack(() => {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: ref.target,\n metaKey: false,\n shiftKey: false,\n });\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n const cancelOnPointerExit = (e: EventBase) => {\n if (isTruthy(_result0.shouldCancelOnPointerExit)) {\n cancel(e);\n }\n };\n\n const triggerClick = (e: TargetedMouseEvent<FocusableElement>) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n _result0.onClick?.(e);\n };\n\n const triggerActivationClick = (\n e: KeyboardEvent | TouchEvent,\n target: FocusableElement\n ) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n // Some third-party libraries pass in onClick instead of onPress.\n // Create a fake mouse event and trigger onClick as well.\n // This matches the browser's native activation behavior for certain elements (e.g. button).\n // https://html.spec.whatwg.org/#activation\n // https://html.spec.whatwg.org/#fire-a-synthetic-pointer-event\n if (_result0.onClick) {\n const event = new MouseEvent(\"click\", e);\n setEventTarget(event, target);\n _result0.onClick(event);\n }\n };\n\n function onScroll(e: Event) {\n const state = ref;\n\n if (\n state.isPressed &&\n nodeContains(requireElement(getEventTarget(e)), state.target)\n ) {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: state.target,\n metaKey: false,\n shiftKey: false,\n });\n }\n }\n\n function onMouseUp(e: MouseEvent) {\n const state = ref;\n\n // Only handle left clicks\n if (e.button !== 0) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n\n return;\n }\n\n if (\n state.target &&\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onMouseUp and onClick, and is more compatible with third party libraries.\n } else {\n cancelEvent(e);\n }\n\n state.isOverTarget = false;\n }\n\n function onPointerCancel(e: PointerEvent) {\n cancelEvent(e);\n }\n\n function onPointerUp(e: PointerEvent) {\n const state = ref;\n\n if (\n e.pointerId === state.activePointerId &&\n state.isPressed &&\n e.button === 0 &&\n state.target\n ) {\n if (\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onPointerUp and onClick, and is more compatible with third party libraries.\n // https://github.com/adobe/react-spectrum/issues/1513\n // https://issues.chromium.org/issues/40732224\n // However, iOS and Android do not focus or fire onClick after a long press.\n // We work around this by triggering a click ourselves after a timeout.\n // This timeout is canceled during the click event in case the real one fires first.\n // The timeout must be at least 32ms, because Safari on iOS delays the click event on\n // non-form elements without certain ARIA roles (for hover emulation).\n // https://github.com/WebKit/WebKit/blob/dccfae42bb29bd4bdef052e469f604a9387241c0/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm#L875-L892\n let clicked = false;\n\n const timeout = setTimeout(() => {\n if (state.isPressed && state.target instanceof HTMLElement) {\n if (clicked) {\n cancelEvent(e);\n } else {\n focusWithoutScrolling(state.target);\n state.target.click();\n }\n }\n }, 80);\n\n // Use a capturing listener to track if a click occurred.\n // If stopPropagation is called it may never reach our handler.\n _result1.addGlobalListener(\n requireValue(e.currentTarget, \"Expected the click listener target\"),\n \"click\",\n () => {\n clicked = true;\n },\n true\n );\n state.disposables.push(() => {\n clearTimeout(timeout);\n });\n } else {\n cancelEvent(e);\n }\n\n // Ignore subsequent onPointerLeave event before onClick on touch devices.\n state.isOverTarget = false;\n }\n }\n\n const state = ref;\n\n const pressPropsValue: DOMAttributes = {\n onClick(e) {\n if (!isTruthy(e)) {\n return;\n }\n\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n e.button === 0 &&\n !state.isTriggeringEvent &&\n !isTruthy(openLink.isOpening)\n ) {\n let shouldStopPropagation = true;\n\n if (isTruthy(_result0.isDisabled)) {\n e.preventDefault();\n }\n\n // If triggered from a screen reader or by using element.click(),\n // trigger as if it were a keyboard click.\n if (\n !state.ignoreEmulatedMouseEvents &&\n !state.isPressed &&\n (state.pointerType === \"virtual\" || isVirtualClick(e))\n ) {\n const stopPressStart = triggerPressStart(e, \"virtual\");\n const stopPressUp = triggerPressUpEvent(e, \"virtual\");\n const stopPressEnd = triggerPressEndEvent(e, \"virtual\");\n triggerClick(e);\n shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;\n } else if (state.isPressed && state.pointerType !== \"keyboard\") {\n const pointerType =\n getTruthyValue(\n state.pointerType ??\n (\"pointerType\" in e\n ? parsePointerType(e.pointerType)\n : undefined)\n ) ?? \"virtual\";\n\n const stopPressUp = triggerPressUpEvent(\n createEvent(e.currentTarget, e),\n pointerType\n );\n\n const stopPressEnd = triggerPressEndEvent(\n createEvent(e.currentTarget, e),\n pointerType,\n true\n );\n\n shouldStopPropagation = stopPressUp && stopPressEnd;\n state.isOverTarget = false;\n triggerClick(e);\n\n cancelEvent(e);\n }\n\n state.ignoreEmulatedMouseEvents = false;\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n }\n },\n onKeyDown(e) {\n if (\n isValidKeyboardEvent(e, e.currentTarget) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n if (shouldPreventDefaultKeyboard(getEventTarget(e), e.key)) {\n e.preventDefault();\n }\n\n // If the event is repeating, it may have started on a different element\n // after which focus moved to the current element. Ignore these events and\n // only handle the first key down event.\n let shouldStopPropagation = true;\n\n if (!state.isPressed && !e.repeat) {\n state.target = e.currentTarget;\n state.isPressed = true;\n state.pointerType = \"keyboard\";\n shouldStopPropagation = triggerPressStart(e, \"keyboard\");\n }\n\n // Focus may move before the key up event, so register the event on the document\n // instead of the same element where the key down event occurred. Make it capturing so that it will trigger\n // before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.\n const originalTarget = e.currentTarget;\n\n const pressUp = (eValue: globalThis.KeyboardEvent) => {\n if (\n isValidKeyboardEvent(eValue, originalTarget) &&\n !eValue.repeat &&\n nodeContains(\n originalTarget,\n requireElement(getEventTarget(eValue))\n ) &&\n state.target\n ) {\n triggerPressUpEvent(createEvent(state.target, eValue), \"keyboard\");\n }\n };\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"keyup\",\n chain(pressUp, onKeyUp),\n true\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n // Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.\n // macOS has a bug where keyup events are not fired while the Meta key is down.\n // When the Meta key itself is released we will get an event for that, and we'll act as if\n // all of these other keys were released as well.\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1393524\n // https://bugs.webkit.org/show_bug.cgi?id=55291\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1299553\n if (e.metaKey && isMac()) {\n state.metaKeyEvents?.set(e.key, e);\n }\n } else if (e.key === \"Meta\") {\n state.metaKeyEvents = new Map();\n }\n },\n };\n\n function onKeyUp(e: KeyboardEvent) {\n if (\n state.isPressed &&\n state.target &&\n isValidKeyboardEvent(e, state.target)\n ) {\n if (\n shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e.key)\n ) {\n e.preventDefault();\n }\n\n const target = getEventTarget(e);\n const wasPressed = nodeContains(state.target, requireElement(target));\n triggerPressEndEvent(\n createEvent(state.target, e),\n \"keyboard\",\n wasPressed\n );\n\n if (wasPressed) {\n triggerActivationClick(e, state.target);\n }\n\n _result1.removeAllGlobalListeners();\n\n // If a link was triggered with a key other than Enter, open the URL ourselves.\n // This means the link has a role override, and the default browser behavior\n // only applies when using the Enter key.\n if (\n e.key !== \"Enter\" &&\n isHTMLAnchorLink(state.target) &&\n nodeContains(state.target, requireElement(target)) &&\n !linkedEvents.has(e)\n ) {\n // Store a hidden property on the event so we only trigger link click once,\n // even if there are multiple usePress instances attached to the element.\n linkedEvents.add(e);\n openLink(state.target, e, false);\n }\n\n state.isPressed = false;\n state.metaKeyEvents?.delete(e.key);\n } else if (e.key === \"Meta\" && isTruthy(state.metaKeyEvents?.size)) {\n // If we recorded keydown events that occurred while the Meta key was pressed,\n // and those haven't received keyup events already, fire keyup events ourselves.\n // See comment above for more info about the macOS bug causing this.\n const events = state.metaKeyEvents;\n state.metaKeyEvents = undefined;\n\n for (const event of events.values()) {\n state.target?.dispatchEvent(new KeyboardEvent(\"keyup\", event));\n }\n }\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n pressPropsValue.onPointerDown = (e) => {\n // Only handle left clicks, and ignore events that bubbled through portals.\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.\n // Ignore and let the onClick handler take care of it instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n if (isVirtualPointerEvent(e)) {\n state.pointerType = \"virtual\";\n\n return;\n }\n\n state.pointerType = parsePointerType(e.pointerType);\n let shouldStopPropagation = true;\n\n if (!state.isPressed) {\n state.isPressed = true;\n state.isOverTarget = true;\n state.activePointerId = e.pointerId;\n state.target = e.currentTarget;\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n // Release pointer capture so that touch interactions can leave the original target.\n // This enables onPointerLeave and onPointerEnter to fire.\n const target = getEventTarget(e);\n\n if (\"releasePointerCapture\" in target) {\n if (\"hasPointerCapture\" in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n requireElement(target).releasePointerCapture(e.pointerId);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointerup\",\n onPointerUp,\n false\n );\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointercancel\",\n onPointerCancel,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseDown = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (e.button === 0) {\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onPointerUp = (e) => {\n // iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.pointerType === \"virtual\"\n ) {\n return;\n }\n\n // Only handle left clicks. If isPressed is true, delay until onClick.\n if (e.button === 0 && !state.isPressed) {\n triggerPressUpEvent(\n e,\n getTruthyValue(state.pointerType) ?? parsePointerType(e.pointerType)\n );\n }\n };\n\n pressPropsValue.onPointerEnter = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n triggerPressStart(createEvent(state.target, e), state.pointerType);\n }\n };\n\n pressPropsValue.onPointerLeave = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n triggerPressEndEvent(\n createEvent(state.target, e),\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.\n cancelEvent(e);\n };\n } else if (process.env.NODE_ENV === \"test\") {\n // NOTE: this fallback branch is entirely used by unit tests.\n // All browsers now support pointer events, but JSDOM still does not.\n pressPropsValue.onMouseDown = (e) => {\n // Only handle left clicks\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n e.stopPropagation();\n\n return;\n }\n\n state.isPressed = true;\n state.isOverTarget = true;\n state.target = e.currentTarget;\n state.pointerType = isVirtualClick(e) ? \"virtual\" : \"mouse\";\n\n // Flush sync so that focus moved during react re-renders occurs before we yield back to the browser.\n const shouldStopPropagation = (() => {\n const result = (() =>\n triggerPressStart(\n e,\n requireValue(state.pointerType, \"Expected state.pointerType\")\n ))();\n\n flush();\n\n return result;\n })();\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"mouseup\",\n onMouseUp,\n false\n );\n };\n\n pressPropsValue.onMouseEnter = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseLeave = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n e,\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseUp = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n !state.ignoreEmulatedMouseEvents &&\n e.button === 0 &&\n !state.isPressed\n ) {\n triggerPressUpEvent(e, getTruthyValue(state.pointerType) ?? \"mouse\");\n }\n };\n\n pressPropsValue.onTouchStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n const touch = getTouchFromEvent(e);\n\n if (!touch) {\n return;\n }\n\n state.activePointerId = touch.identifier;\n state.ignoreEmulatedMouseEvents = true;\n state.isOverTarget = true;\n state.isPressed = true;\n state.target = e.currentTarget;\n state.pointerType = \"touch\";\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n const shouldStopPropagation = triggerPressStart(\n createTouchEvent(state.target, e),\n state.pointerType\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n _result1.addGlobalListener(\n getOwnerWindow(e.currentTarget),\n \"scroll\",\n onScroll,\n true\n );\n };\n\n pressPropsValue.onTouchMove = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (touch && isOverTarget(touch, e.currentTarget)) {\n if (\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n }\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n cancelOnPointerExit(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onTouchEnd = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (\n touch &&\n isOverTarget(touch, e.currentTarget) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressUpEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n triggerActivationClick(\n e,\n requireValue(state.target, \"Expected state.target\")\n );\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n state.isPressed = false;\n state.activePointerId = null;\n state.isOverTarget = false;\n state.ignoreEmulatedMouseEvents = true;\n\n if (state.target && !isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n _result1.removeAllGlobalListeners();\n };\n\n pressPropsValue.onTouchCancel = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n e.stopPropagation();\n\n if (state.isPressed) {\n cancelEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n cancelEvent(e);\n };\n }\n\n // Avoid onClick delay for double tap to zoom by default.\n createEffect(\n () => _result0.ref?.(),\n (element) => {\n if (!element || process.env.NODE_ENV === \"test\") {\n return;\n }\n\n const ownerDocument = getOwnerDocument(element);\n\n if (\n !isTruthy(ownerDocument) ||\n !isTruthy(ownerDocument.head) ||\n ownerDocument.querySelector(`#${STYLE_ID}`)\n ) {\n return;\n }\n\n const style = ownerDocument.createElement(\"style\");\n style.id = STYLE_ID;\n const nonce = getNonce(ownerDocument);\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n // touchAction: 'manipulation' is supposed to be equivalent, but in\n // Safari it causes onPointerCancel not to fire on scroll.\n // https://bugs.webkit.org/show_bug.cgi?id=240917\n style.textContent = `\n@layer {\n [${PRESSABLE_ATTRIBUTE}] {\n touch-action: pan-x pan-y pinch-zoom;\n }\n}\n `.trim();\n ownerDocument.head.prepend(style);\n },\n { ssrSource: \"client\" }\n );\n // Remove user-select: none in case component unmounts immediately after pressStart\n createEffect(\n () => _result0.allowTextSelectionOnPress,\n (allowTextSelection) => () => {\n if (allowTextSelection !== true) {\n restoreTextSelection(state.target ?? undefined);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get isPressed() {\n return getTruthyValue(_result0.isPressed) ?? isPressed();\n },\n get pressProps() {\n return mergeProps(\n omit(\n _result0,\n \"onPress\",\n \"onPressChange\",\n \"onPressStart\",\n \"onPressEnd\",\n \"onPressUp\",\n \"onClick\",\n \"isDisabled\",\n \"isPressed\",\n \"preventFocusOnPress\",\n \"shouldCancelOnPointerExit\",\n \"allowTextSelectionOnPress\",\n \"ref\"\n ),\n pressPropsValue,\n { [PRESSABLE_ATTRIBUTE]: true }\n );\n },\n };\n}\n\nfunction isHTMLAnchorLink(target: Element): target is HTMLAnchorElement {\n return target.tagName === \"A\" && target.hasAttribute(\"href\");\n}\n\nfunction isValidKeyboardEvent(\n event: KeyboardEvent,\n currentTarget: Element\n): boolean {\n const { key, code } = event;\n const element = requireHTMLElement(currentTarget);\n const role = element.getAttribute(\"role\");\n\n // Accessibility for keyboards. Space and Enter only.\n // \"Spacebar\" is for IE 11\n return (\n (key === \"Enter\" ||\n key === \" \" ||\n key === \"Spacebar\" ||\n code === \"Space\") &&\n (!(element instanceof getOwnerWindow(element).HTMLInputElement) ||\n isValidInputKey(element, key)) &&\n !(element instanceof getOwnerWindow(element).HTMLTextAreaElement) &&\n !element.isContentEditable &&\n // Links should only trigger with Enter key\n ((role !== \"link\" && (isTruthy(role) || !isHTMLAnchorLink(element))) ||\n key === \"Enter\")\n );\n}\n\nfunction getTouchFromEvent(event: TouchEvent): Touch | null {\n const { targetTouches } = event;\n\n if (targetTouches.length > 0) {\n return targetTouches[0] ?? null;\n }\n\n return null;\n}\n\nfunction getTouchById(\n event: TouchEvent,\n pointerId: null | number\n): null | Touch {\n const { changedTouches } = event;\n\n for (const touch of changedTouches) {\n if (touch.identifier === pointerId) {\n return touch;\n }\n }\n\n return null;\n}\n\nfunction createTouchEvent(\n target: FocusableElement,\n e: TargetedTouchEvent<FocusableElement>\n): EventBase {\n let clientX = 0;\n let clientY = 0;\n\n if (isTruthy(e.targetTouches) && e.targetTouches.length === 1) {\n ({ clientX } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n ({ clientY } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n }\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\nfunction createEvent(target: FocusableElement, e: EventBase): EventBase {\n const { clientX } = e;\n const { clientY } = e;\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n key: e.key,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\ninterface Rect {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\ninterface EventPoint {\n clientX: number;\n clientY: number;\n width?: number;\n height?: number;\n radiusX?: number;\n radiusY?: number;\n}\n\nfunction getPointClientRect(point: EventPoint): Rect {\n let offsetX = 0;\n let offsetY = 0;\n\n if (point.width !== undefined) {\n offsetX = point.width / 2;\n } else if (point.radiusX !== undefined) {\n offsetX = point.radiusX;\n }\n\n if (point.height !== undefined) {\n offsetY = point.height / 2;\n } else if (point.radiusY !== undefined) {\n offsetY = point.radiusY;\n }\n\n return {\n bottom: point.clientY + offsetY,\n left: point.clientX - offsetX,\n right: point.clientX + offsetX,\n top: point.clientY - offsetY,\n };\n}\n\nfunction areRectanglesOverlapping(a: Rect, b: Rect) {\n // check if they cannot overlap on x axis\n if (a.left > b.right || b.left > a.right) {\n return false;\n }\n\n // check if they cannot overlap on y axis\n if (a.top > b.bottom || b.top > a.bottom) {\n return false;\n }\n\n return true;\n}\n\nfunction isOverTarget(point: EventPoint, target: Element) {\n const rect = target.getBoundingClientRect();\n const pointRect = getPointClientRect(point);\n\n return areRectanglesOverlapping(rect, pointRect);\n}\n\nfunction shouldPreventDefaultUp(target: Element) {\n if (target instanceof HTMLInputElement) {\n return false;\n }\n\n if (target instanceof HTMLButtonElement) {\n return target.type !== \"submit\" && target.type !== \"reset\";\n }\n\n if (isHTMLAnchorLink(target)) {\n return false;\n }\n\n return true;\n}\n\nfunction shouldPreventDefaultKeyboard(target: Element, key: string) {\n // Don't prevent the contextmenu shortcut on mac.\n if (isMac() && key === \"Enter\") {\n return false;\n }\n\n if (target instanceof HTMLInputElement) {\n if (\n key === \"Enter\" &&\n (target.type === \"checkbox\" || target.type === \"radio\")\n ) {\n // Enter on a checkbox or radio should do an implicit form submission, but not toggle the input.\n return false;\n }\n\n return !isValidInputKey(target, key);\n }\n\n return shouldPreventDefaultUp(target);\n}\n\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\nfunction isValidInputKey(target: HTMLInputElement, key: string) {\n // Only space should toggle checkboxes and radios, not enter.\n return target.type === \"checkbox\" || target.type === \"radio\"\n ? key === \" \"\n : nonTextInputTypes.has(target.type);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAS,4BAA4B,OAAuC;CAC1E,MAAM,UAAU,WAAW,qBAAqB;CAChD,MAAM,eAAe,WAAW,KAAK,SAAS,YAAY,KAAK,GAAG,KAAK;CACvE,cAAc;EACZ,QAAQ,SAAS;CACnB,CAAC;CAED,oBACS;EAAE,SAAS,aAAa,MAAM;EAAG,QAAQ,QAAQ;CAAI,KAC3D,EAAE,SAAS,aAAa;EACvB,IAAI,mBAAmB,eAAe,mBAAmB,YACvD,SAAS,OAAO;CAEpB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO;AACT;AAEA,IAAM,aAAN,MAAwC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,yBAAyB;CACzB,YACE,MACA,aACA,eACA,OACA;EACA,MAAM,gBAAgB,OAAO,UAAU,cAAc;EAErD,MAAM,OACJ,eAAe,aAAa,CAAC,EAAE,sBAAsB;EAEvD,IAAI,IAAI;EACR,IAAI,IAAI;EAER,IAAI;EACJ,IAAI,UAAyB;EAE7B,IACE,UAAU,cAA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OAAO;CAGT,IAAI,kBAAkB,mBACpB,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;CAGrD,IAAI,iBAAiB,MAAM,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,6BAA6B,QAAiB,KAAa;CAElE,IAAI,MAAM,KAAK,QAAQ,SACrB,OAAO;CAGT,IAAI,kBAAkB,kBAAkB;EACtC,IACE,QAAQ,YACP,OAAO,SAAS,cAAc,OAAO,SAAS,UAG/C,OAAO;EAGT,OAAO,CAAC,gBAAgB,QAAQ,GAAG;CACrC;CAEA,OAAO,uBAAuB,MAAM;AACtC;AAEA,MAAM,oCAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,QAA0B,KAAa;CAE9D,OAAO,OAAO,SAAS,cAAc,OAAO,SAAS,UACjD,QAAQ,MACR,kBAAkB,IAAI,OAAO,IAAI;AACvC"}
|
|
1
|
+
{"version":3,"file":"create-press.js","names":[],"sources":["../../../src/interactions/create-press.ts"],"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/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/usePress.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; register the initial press responder in an explicit untracked lifecycle scope.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n FocusableElement,\n PressEvent as IPressEvent,\n PointerType,\n PressEvents,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n omit,\n untrack,\n useContext,\n createEffect,\n createSignal,\n flush,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type {\n MouseEvent as TargetedMouseEvent,\n TouchEvent as TargetedTouchEvent,\n} from \"../types\";\nimport { chain } from \"../utils/chain\";\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n requireElement,\n requireFocusableElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n isVirtualClick,\n isVirtualPointerEvent,\n} from \"../utils/is-virtual-event\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink } from \"../utils/open-link\";\nimport { isMac } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { PressResponderContext } from \"./context\";\nimport { disableTextSelection, restoreTextSelection } from \"./text-selection\";\nimport { preventFocus, setEventTarget } from \"./utils\";\n\nexport interface PressProps extends PressEvents {\n /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */\n isPressed?: boolean;\n /** Whether the press events should be disabled. */\n isDisabled?: boolean;\n /** Whether the target should not receive focus on press. */\n preventFocusOnPress?: boolean;\n /**\n * Whether press events should be canceled when the pointer leaves the target while pressed.\n * By default, this is `false`, which means if the pointer returns back over the target while\n * still pressed, onPressStart will be fired again. If set to `true`, the press is canceled\n * when the pointer leaves the target and onPressStart will not be fired if the pointer returns.\n */\n shouldCancelOnPointerExit?: boolean;\n /** Whether text selection should be enabled on the pressable element. */\n allowTextSelectionOnPress?: boolean;\n}\n\nexport interface PressHookProps extends PressProps {\n /** A ref to the target element. */\n ref?: Accessor<Element | null>;\n}\n\ninterface PressState {\n isPressed: boolean;\n ignoreEmulatedMouseEvents: boolean;\n didFirePressStart: boolean;\n isTriggeringEvent: boolean;\n activePointerId: number | null;\n target: FocusableElement | null;\n isOverTarget: boolean;\n pointerType: PointerType | null;\n userSelect?: string;\n metaKeyEvents?: Map<string, globalThis.KeyboardEvent>;\n disposables: (() => void)[];\n}\n\ninterface EventBase {\n currentTarget: EventTarget | null;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n clientX?: number;\n clientY?: number;\n targetTouches?: {\n clientX?: number;\n clientY?: number;\n }[];\n key?: string;\n}\n\nexport interface PressResult {\n /** Whether the target is currently pressed. */\n isPressed: boolean;\n /** Props to spread on the target element. */\n pressProps: DOMAttributes;\n}\n\nfunction createPressResponderContext(props: PressHookProps): PressHookProps {\n const context = useContext(PressResponderContext);\n const currentProps = mergeProps(omit(context, \"register\", \"ref\"), props);\n untrack(() => {\n context.register();\n });\n\n createEffect(\n () => ({ element: currentProps.ref?.(), setRef: context.ref }),\n ({ element, setRef }) => {\n if (element instanceof HTMLElement || element instanceof SVGElement) {\n setRef?.(element);\n }\n },\n { ssrSource: \"client\" }\n );\n\n return currentProps;\n}\n\nclass PressEvent implements IPressEvent {\n type: IPressEvent[\"type\"];\n pointerType: PointerType;\n target: Element;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n x: number;\n y: number;\n key: string | undefined;\n #shouldStopPropagation = true;\n constructor(\n type: IPressEvent[\"type\"],\n pointerType: PointerType,\n originalEvent: EventBase,\n state?: PressState\n ) {\n const currentTarget = state?.target ?? originalEvent.currentTarget;\n\n const rect: DOMRect | undefined =\n requireElement(currentTarget)?.getBoundingClientRect();\n\n let x = 0;\n let y = 0;\n\n let clientX;\n let clientY: number | null = null;\n\n if (\n isPresent(originalEvent.clientX) &&\n originalEvent.clientY !== null &&\n originalEvent.clientY !== undefined\n ) {\n ({ clientX } = originalEvent);\n ({ clientY } = originalEvent);\n }\n\n if (isTruthy(rect)) {\n if (isPresent(clientX) && clientY !== null && clientY !== undefined) {\n x = clientX - rect.left;\n y = clientY - rect.top;\n } else {\n x = rect.width / 2;\n y = rect.height / 2;\n }\n }\n\n this.type = type;\n this.pointerType = pointerType;\n this.target = requireElement(originalEvent.currentTarget);\n this.shiftKey = originalEvent.shiftKey;\n this.metaKey = originalEvent.metaKey;\n this.ctrlKey = originalEvent.ctrlKey;\n this.altKey = originalEvent.altKey;\n this.x = x;\n this.y = y;\n this.key = originalEvent.key;\n }\n continuePropagation() {\n this.#shouldStopPropagation = false;\n }\n get shouldStopPropagation() {\n return this.#shouldStopPropagation;\n }\n}\n\nconst linkedEvents = new WeakSet<Event>();\n\nfunction parsePointerType(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Validate optional native event extensions before storing their pointer type.\n value: unknown\n): PointerType {\n return value === \"touch\" ||\n value === \"pen\" ||\n value === \"keyboard\" ||\n value === \"virtual\"\n ? value\n : \"mouse\";\n}\n\nconst STYLE_ID = \"react-aria-pressable-style\";\nconst PRESSABLE_ATTRIBUTE = \"data-react-aria-pressable\";\n\n/**\n * Handles press interactions across mouse, touch, keyboard, and screen readers.\n * It normalizes behavior across browsers and platforms, and handles many nuances\n * of dealing with pointer and keyboard events.\n */\nexport function createPress(props: PressHookProps): PressResult {\n const _result0 = createPressResponderContext(props);\n const [isPressed, setPressed] = createSignal(false, { ownedWrite: true });\n\n const ref: PressState = {\n activePointerId: null,\n didFirePressStart: false,\n disposables: [],\n ignoreEmulatedMouseEvents: false,\n isOverTarget: false,\n isPressed: false,\n isTriggeringEvent: false,\n pointerType: null,\n target: null,\n };\n\n const _result1 = createGlobalListeners();\n\n const triggerPressStart = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled) || state.didFirePressStart) {\n return false;\n }\n\n let shouldStopPropagation = true;\n state.isTriggeringEvent = true;\n\n if (_result0.onPressStart) {\n const event = new PressEvent(\"pressstart\", pointerType, originalEvent);\n _result0.onPressStart(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(true);\n }\n\n state.isTriggeringEvent = false;\n state.didFirePressStart = true;\n setPressed(true);\n\n return shouldStopPropagation;\n };\n\n const triggerPressEnd = (\n originalEvent: EventBase,\n pointerType: PointerType,\n wasPressed = true\n ) => {\n const state = ref;\n\n if (!state.didFirePressStart) {\n return false;\n }\n\n state.didFirePressStart = false;\n state.isTriggeringEvent = true;\n let shouldStopPropagation = true;\n\n if (_result0.onPressEnd) {\n const event = new PressEvent(\"pressend\", pointerType, originalEvent);\n _result0.onPressEnd(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(false);\n }\n\n setPressed(false);\n\n if (_result0.onPress && wasPressed && !isTruthy(_result0.isDisabled)) {\n const event = new PressEvent(\"press\", pointerType, originalEvent);\n _result0.onPress(event);\n shouldStopPropagation &&= event.shouldStopPropagation;\n }\n\n state.isTriggeringEvent = false;\n\n return shouldStopPropagation;\n };\n\n const triggerPressEndEvent = triggerPressEnd;\n\n const triggerPressUp = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled)) {\n return false;\n }\n\n if (_result0.onPressUp) {\n state.isTriggeringEvent = true;\n const event = new PressEvent(\"pressup\", pointerType, originalEvent);\n _result0.onPressUp(event);\n state.isTriggeringEvent = false;\n\n return event.shouldStopPropagation;\n }\n\n return true;\n };\n\n const triggerPressUpEvent = triggerPressUp;\n\n const cancel = (e: EventBase) => {\n const state = ref;\n\n if (state.isPressed && state.target) {\n if (\n state.didFirePressStart &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressEnd(createEvent(state.target, e), state.pointerType, false);\n }\n\n state.isPressed = false;\n state.isOverTarget = false;\n state.activePointerId = null;\n state.pointerType = null;\n _result1.removeAllGlobalListeners();\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n }\n };\n\n const cancelEvent = cancel;\n createEffect(\n () => _result0.isDisabled,\n (disabled) => {\n if (disabled === true && ref.isPressed) {\n untrack(() => {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: ref.target,\n metaKey: false,\n shiftKey: false,\n });\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n const cancelOnPointerExit = (e: EventBase) => {\n if (isTruthy(_result0.shouldCancelOnPointerExit)) {\n cancel(e);\n }\n };\n\n const triggerClick = (e: TargetedMouseEvent<FocusableElement>) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n _result0.onClick?.(e);\n };\n\n const triggerActivationClick = (\n e: KeyboardEvent | TouchEvent,\n target: FocusableElement\n ) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n // Some third-party libraries pass in onClick instead of onPress.\n // Create a fake mouse event and trigger onClick as well.\n // This matches the browser's native activation behavior for certain elements (e.g. button).\n // https://html.spec.whatwg.org/#activation\n // https://html.spec.whatwg.org/#fire-a-synthetic-pointer-event\n if (_result0.onClick) {\n const event = new MouseEvent(\"click\", e);\n setEventTarget(event, target);\n _result0.onClick(event);\n }\n };\n\n function onScroll(e: Event) {\n const state = ref;\n\n if (\n state.isPressed &&\n nodeContains(requireElement(getEventTarget(e)), state.target)\n ) {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: state.target,\n metaKey: false,\n shiftKey: false,\n });\n }\n }\n\n function onMouseUp(e: MouseEvent) {\n const state = ref;\n\n // Only handle left clicks\n if (e.button !== 0) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n\n return;\n }\n\n if (\n state.target &&\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onMouseUp and onClick, and is more compatible with third party libraries.\n } else {\n cancelEvent(e);\n }\n\n state.isOverTarget = false;\n }\n\n function onPointerCancel(e: PointerEvent) {\n cancelEvent(e);\n }\n\n function onPointerUp(e: PointerEvent) {\n const state = ref;\n\n if (\n e.pointerId === state.activePointerId &&\n state.isPressed &&\n e.button === 0 &&\n state.target\n ) {\n if (\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onPointerUp and onClick, and is more compatible with third party libraries.\n // https://github.com/adobe/react-spectrum/issues/1513\n // https://issues.chromium.org/issues/40732224\n // However, iOS and Android do not focus or fire onClick after a long press.\n // We work around this by triggering a click ourselves after a timeout.\n // This timeout is canceled during the click event in case the real one fires first.\n // The timeout must be at least 32ms, because Safari on iOS delays the click event on\n // non-form elements without certain ARIA roles (for hover emulation).\n // https://github.com/WebKit/WebKit/blob/dccfae42bb29bd4bdef052e469f604a9387241c0/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm#L875-L892\n let clicked = false;\n\n const timeout = setTimeout(() => {\n if (state.isPressed && state.target instanceof HTMLElement) {\n if (clicked) {\n cancelEvent(e);\n } else {\n focusWithoutScrolling(state.target);\n state.target.click();\n }\n }\n }, 80);\n\n // Use a capturing listener to track if a click occurred.\n // If stopPropagation is called it may never reach our handler.\n _result1.addGlobalListener(\n requireValue(e.currentTarget, \"Expected the click listener target\"),\n \"click\",\n () => {\n clicked = true;\n },\n true\n );\n state.disposables.push(() => {\n clearTimeout(timeout);\n });\n } else {\n cancelEvent(e);\n }\n\n // Ignore subsequent onPointerLeave event before onClick on touch devices.\n state.isOverTarget = false;\n }\n }\n\n const state = ref;\n\n const pressPropsValue: DOMAttributes = {\n onClick(e) {\n if (!isTruthy(e)) {\n return;\n }\n\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n e.button === 0 &&\n !state.isTriggeringEvent &&\n !isTruthy(openLink.isOpening)\n ) {\n let shouldStopPropagation = true;\n\n if (isTruthy(_result0.isDisabled)) {\n e.preventDefault();\n }\n\n // If triggered from a screen reader or by using element.click(),\n // trigger as if it were a keyboard click.\n if (\n !state.ignoreEmulatedMouseEvents &&\n !state.isPressed &&\n (state.pointerType === \"virtual\" || isVirtualClick(e))\n ) {\n const stopPressStart = triggerPressStart(e, \"virtual\");\n const stopPressUp = triggerPressUpEvent(e, \"virtual\");\n const stopPressEnd = triggerPressEndEvent(e, \"virtual\");\n triggerClick(e);\n shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;\n } else if (state.isPressed && state.pointerType !== \"keyboard\") {\n const pointerType =\n getTruthyValue(\n state.pointerType ??\n (\"pointerType\" in e\n ? parsePointerType(e.pointerType)\n : undefined)\n ) ?? \"virtual\";\n\n const stopPressUp = triggerPressUpEvent(\n createEvent(e.currentTarget, e),\n pointerType\n );\n\n const stopPressEnd = triggerPressEndEvent(\n createEvent(e.currentTarget, e),\n pointerType,\n true\n );\n\n shouldStopPropagation = stopPressUp && stopPressEnd;\n state.isOverTarget = false;\n triggerClick(e);\n\n cancelEvent(e);\n }\n\n state.ignoreEmulatedMouseEvents = false;\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n }\n },\n onKeyDown(e) {\n if (\n isValidKeyboardEvent(e, e.currentTarget) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n if (shouldPreventDefaultKeyboard(getEventTarget(e), e)) {\n e.preventDefault();\n }\n\n // If the event is repeating, it may have started on a different element\n // after which focus moved to the current element. Ignore these events and\n // only handle the first key down event.\n let shouldStopPropagation = true;\n\n if (!state.isPressed && !e.repeat) {\n state.target = e.currentTarget;\n state.isPressed = true;\n state.pointerType = \"keyboard\";\n shouldStopPropagation = triggerPressStart(e, \"keyboard\");\n }\n\n // Focus may move before the key up event, so register the event on the document\n // instead of the same element where the key down event occurred. Make it capturing so that it will trigger\n // before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.\n const originalTarget = e.currentTarget;\n\n const pressUp = (eValue: globalThis.KeyboardEvent) => {\n if (\n isValidKeyboardEvent(eValue, originalTarget) &&\n !eValue.repeat &&\n nodeContains(\n originalTarget,\n requireElement(getEventTarget(eValue))\n ) &&\n state.target\n ) {\n triggerPressUpEvent(createEvent(state.target, eValue), \"keyboard\");\n }\n };\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"keyup\",\n chain(pressUp, onKeyUp),\n true\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n // Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.\n // macOS has a bug where keyup events are not fired while the Meta key is down.\n // When the Meta key itself is released we will get an event for that, and we'll act as if\n // all of these other keys were released as well.\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1393524\n // https://bugs.webkit.org/show_bug.cgi?id=55291\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1299553\n if (e.metaKey && isMac()) {\n state.metaKeyEvents?.set(e.key, e);\n }\n } else if (e.key === \"Meta\") {\n state.metaKeyEvents = new Map();\n }\n },\n };\n\n function onKeyUp(e: KeyboardEvent) {\n if (\n state.isPressed &&\n state.target &&\n isValidKeyboardEvent(e, state.target)\n ) {\n if (shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e)) {\n e.preventDefault();\n }\n\n const target = getEventTarget(e);\n const wasPressed = nodeContains(state.target, requireElement(target));\n triggerPressEndEvent(\n createEvent(state.target, e),\n \"keyboard\",\n wasPressed\n );\n\n if (wasPressed) {\n triggerActivationClick(e, state.target);\n }\n\n _result1.removeAllGlobalListeners();\n\n // If a link was triggered with a key other than Enter, open the URL ourselves.\n // This means the link has a role override, and the default browser behavior\n // only applies when using the Enter key.\n if (\n e.key !== \"Enter\" &&\n isHTMLAnchorLink(state.target) &&\n nodeContains(state.target, requireElement(target)) &&\n !linkedEvents.has(e)\n ) {\n // Store a hidden property on the event so we only trigger link click once,\n // even if there are multiple usePress instances attached to the element.\n linkedEvents.add(e);\n openLink(state.target, e, false);\n }\n\n state.isPressed = false;\n state.metaKeyEvents?.delete(e.key);\n } else if (e.key === \"Meta\" && isTruthy(state.metaKeyEvents?.size)) {\n // If we recorded keydown events that occurred while the Meta key was pressed,\n // and those haven't received keyup events already, fire keyup events ourselves.\n // See comment above for more info about the macOS bug causing this.\n const events = state.metaKeyEvents;\n state.metaKeyEvents = undefined;\n\n for (const event of events.values()) {\n state.target?.dispatchEvent(new KeyboardEvent(\"keyup\", event));\n }\n }\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n pressPropsValue.onPointerDown = (e) => {\n // Only handle left clicks, and ignore events that bubbled through portals.\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.\n // Ignore and let the onClick handler take care of it instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n if (isVirtualPointerEvent(e)) {\n state.pointerType = \"virtual\";\n\n return;\n }\n\n state.pointerType = parsePointerType(e.pointerType);\n let shouldStopPropagation = true;\n\n if (!state.isPressed) {\n state.isPressed = true;\n state.isOverTarget = true;\n state.activePointerId = e.pointerId;\n state.target = e.currentTarget;\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n // Release pointer capture so that touch interactions can leave the original target.\n // This enables onPointerLeave and onPointerEnter to fire.\n const target = getEventTarget(e);\n\n if (\"releasePointerCapture\" in target) {\n if (\"hasPointerCapture\" in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n requireElement(target).releasePointerCapture(e.pointerId);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointerup\",\n onPointerUp,\n false\n );\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointercancel\",\n onPointerCancel,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseDown = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (e.button === 0) {\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onPointerUp = (e) => {\n // iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.pointerType === \"virtual\"\n ) {\n return;\n }\n\n // Only handle left clicks. If isPressed is true, delay until onClick.\n if (e.button === 0 && !state.isPressed) {\n triggerPressUpEvent(\n e,\n getTruthyValue(state.pointerType) ?? parsePointerType(e.pointerType)\n );\n }\n };\n\n pressPropsValue.onPointerEnter = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n triggerPressStart(createEvent(state.target, e), state.pointerType);\n }\n };\n\n pressPropsValue.onPointerLeave = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n triggerPressEndEvent(\n createEvent(state.target, e),\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.\n cancelEvent(e);\n };\n } else if (process.env.NODE_ENV === \"test\") {\n // NOTE: this fallback branch is entirely used by unit tests.\n // All browsers now support pointer events, but JSDOM still does not.\n pressPropsValue.onMouseDown = (e) => {\n // Only handle left clicks\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n e.stopPropagation();\n\n return;\n }\n\n state.isPressed = true;\n state.isOverTarget = true;\n state.target = e.currentTarget;\n state.pointerType = isVirtualClick(e) ? \"virtual\" : \"mouse\";\n\n // Flush sync so that focus moved during react re-renders occurs before we yield back to the browser.\n const shouldStopPropagation = (() => {\n const result = (() =>\n triggerPressStart(\n e,\n requireValue(state.pointerType, \"Expected state.pointerType\")\n ))();\n\n flush();\n\n return result;\n })();\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"mouseup\",\n onMouseUp,\n false\n );\n };\n\n pressPropsValue.onMouseEnter = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseLeave = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n e,\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseUp = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n !state.ignoreEmulatedMouseEvents &&\n e.button === 0 &&\n !state.isPressed\n ) {\n triggerPressUpEvent(e, getTruthyValue(state.pointerType) ?? \"mouse\");\n }\n };\n\n pressPropsValue.onTouchStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n const touch = getTouchFromEvent(e);\n\n if (!touch) {\n return;\n }\n\n state.activePointerId = touch.identifier;\n state.ignoreEmulatedMouseEvents = true;\n state.isOverTarget = true;\n state.isPressed = true;\n state.target = e.currentTarget;\n state.pointerType = \"touch\";\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n const shouldStopPropagation = triggerPressStart(\n createTouchEvent(state.target, e),\n state.pointerType\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n _result1.addGlobalListener(\n getOwnerWindow(e.currentTarget),\n \"scroll\",\n onScroll,\n true\n );\n };\n\n pressPropsValue.onTouchMove = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (touch && isOverTarget(touch, e.currentTarget)) {\n if (\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n }\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n cancelOnPointerExit(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onTouchEnd = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (\n touch &&\n isOverTarget(touch, e.currentTarget) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressUpEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n triggerActivationClick(\n e,\n requireValue(state.target, \"Expected state.target\")\n );\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n state.isPressed = false;\n state.activePointerId = null;\n state.isOverTarget = false;\n state.ignoreEmulatedMouseEvents = true;\n\n if (state.target && !isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n _result1.removeAllGlobalListeners();\n };\n\n pressPropsValue.onTouchCancel = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n e.stopPropagation();\n\n if (state.isPressed) {\n cancelEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n cancelEvent(e);\n };\n }\n\n // Avoid onClick delay for double tap to zoom by default.\n createEffect(\n () => _result0.ref?.(),\n (element) => {\n if (!element || process.env.NODE_ENV === \"test\") {\n return;\n }\n\n const ownerDocument = getOwnerDocument(element);\n\n if (\n !isTruthy(ownerDocument) ||\n !isTruthy(ownerDocument.head) ||\n ownerDocument.querySelector(`#${STYLE_ID}`)\n ) {\n return;\n }\n\n const style = ownerDocument.createElement(\"style\");\n style.id = STYLE_ID;\n const nonce = getNonce(ownerDocument);\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n // touchAction: 'manipulation' is supposed to be equivalent, but in\n // Safari it causes onPointerCancel not to fire on scroll.\n // https://bugs.webkit.org/show_bug.cgi?id=240917\n style.textContent = `\n@layer {\n [${PRESSABLE_ATTRIBUTE}] {\n touch-action: pan-x pan-y pinch-zoom;\n }\n}\n `.trim();\n ownerDocument.head.prepend(style);\n },\n { ssrSource: \"client\" }\n );\n // Remove user-select: none in case component unmounts immediately after pressStart\n createEffect(\n () => _result0.allowTextSelectionOnPress,\n (allowTextSelection) => () => {\n if (allowTextSelection !== true) {\n restoreTextSelection(state.target ?? undefined);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get isPressed() {\n return getTruthyValue(_result0.isPressed) ?? isPressed();\n },\n get pressProps() {\n return mergeProps(\n omit(\n _result0,\n \"onPress\",\n \"onPressChange\",\n \"onPressStart\",\n \"onPressEnd\",\n \"onPressUp\",\n \"onClick\",\n \"isDisabled\",\n \"isPressed\",\n \"preventFocusOnPress\",\n \"shouldCancelOnPointerExit\",\n \"allowTextSelectionOnPress\",\n \"ref\"\n ),\n pressPropsValue,\n { [PRESSABLE_ATTRIBUTE]: true }\n );\n },\n };\n}\n\nfunction isHTMLAnchorLink(target: Element): target is HTMLAnchorElement {\n return target.tagName === \"A\" && target.hasAttribute(\"href\");\n}\n\nfunction isValidKeyboardEvent(\n event: KeyboardEvent,\n currentTarget: Element\n): boolean {\n const { key, code } = event;\n const element = requireHTMLElement(currentTarget);\n const role = element.getAttribute(\"role\");\n\n // Accessibility for keyboards. Space and Enter only.\n // \"Spacebar\" is for IE 11\n return (\n (key === \"Enter\" ||\n key === \" \" ||\n key === \"Spacebar\" ||\n code === \"Space\") &&\n (!(element instanceof getOwnerWindow(element).HTMLInputElement) ||\n isValidInputKey(element, key)) &&\n !(element instanceof getOwnerWindow(element).HTMLTextAreaElement) &&\n !element.isContentEditable &&\n // Links should only trigger with Enter key\n ((role !== \"link\" && (isTruthy(role) || !isHTMLAnchorLink(element))) ||\n key === \"Enter\")\n );\n}\n\nfunction getTouchFromEvent(event: TouchEvent): Touch | null {\n const { targetTouches } = event;\n\n if (targetTouches.length > 0) {\n return targetTouches[0] ?? null;\n }\n\n return null;\n}\n\nfunction getTouchById(\n event: TouchEvent,\n pointerId: null | number\n): null | Touch {\n const { changedTouches } = event;\n\n for (const touch of changedTouches) {\n if (touch.identifier === pointerId) {\n return touch;\n }\n }\n\n return null;\n}\n\nfunction createTouchEvent(\n target: FocusableElement,\n e: TargetedTouchEvent<FocusableElement>\n): EventBase {\n let clientX = 0;\n let clientY = 0;\n\n if (isTruthy(e.targetTouches) && e.targetTouches.length === 1) {\n ({ clientX } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n ({ clientY } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n }\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\nfunction createEvent(target: FocusableElement, e: EventBase): EventBase {\n const { clientX } = e;\n const { clientY } = e;\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n key: e.key,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\ninterface Rect {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\ninterface EventPoint {\n clientX: number;\n clientY: number;\n width?: number;\n height?: number;\n radiusX?: number;\n radiusY?: number;\n}\n\nfunction getPointClientRect(point: EventPoint): Rect {\n let offsetX = 0;\n let offsetY = 0;\n\n if (point.width !== undefined) {\n offsetX = point.width / 2;\n } else if (point.radiusX !== undefined) {\n offsetX = point.radiusX;\n }\n\n if (point.height !== undefined) {\n offsetY = point.height / 2;\n } else if (point.radiusY !== undefined) {\n offsetY = point.radiusY;\n }\n\n return {\n bottom: point.clientY + offsetY,\n left: point.clientX - offsetX,\n right: point.clientX + offsetX,\n top: point.clientY - offsetY,\n };\n}\n\nfunction areRectanglesOverlapping(a: Rect, b: Rect) {\n // check if they cannot overlap on x axis\n if (a.left > b.right || b.left > a.right) {\n return false;\n }\n\n // check if they cannot overlap on y axis\n if (a.top > b.bottom || b.top > a.bottom) {\n return false;\n }\n\n return true;\n}\n\nfunction isOverTarget(point: EventPoint, target: Element) {\n const rect = target.getBoundingClientRect();\n const pointRect = getPointClientRect(point);\n\n return areRectanglesOverlapping(rect, pointRect);\n}\n\nfunction shouldPreventDefaultUp(target: Element) {\n if (target instanceof HTMLInputElement) {\n return false;\n }\n\n if (target instanceof HTMLButtonElement) {\n return target.type !== \"submit\" && target.type !== \"reset\";\n }\n\n if (isHTMLAnchorLink(target)) {\n return false;\n }\n\n return true;\n}\n\nfunction shouldPreventDefaultKeyboard(\n target: Element,\n event: Pick<KeyboardEvent, \"key\" | \"ctrlKey\">\n) {\n const { key } = event;\n\n // Don't prevent the contextmenu shortcut (Control + Enter) on mac.\n if (isMac() && key === \"Enter\" && event.ctrlKey) {\n return false;\n }\n\n if (target instanceof HTMLInputElement) {\n if (\n key === \"Enter\" &&\n (target.type === \"checkbox\" || target.type === \"radio\")\n ) {\n // Enter on a checkbox or radio should do an implicit form submission, but not toggle the input.\n return false;\n }\n\n return !isValidInputKey(target, key);\n }\n\n return shouldPreventDefaultUp(target);\n}\n\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\nfunction isValidInputKey(target: HTMLInputElement, key: string) {\n // Only space should toggle checkboxes and radios, not enter.\n return target.type === \"checkbox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;AACF,CAAC;AAED,SAAS,gBAAgB,QAA0B,KAAa;CAE9D,OAAO,OAAO,SAAS,cAAc,OAAO,SAAS,UACjD,QAAQ,MACR,kBAAkB,IAAI,OAAO,IAAI;AACvC"}
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
16
|
*/
|
|
17
17
|
import { isPresent } from "../utils/is-present.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { isNode, isShadowRoot } from "../utils/type-helpers.js";
|
|
19
|
+
import { getOwnerWindow } from "../utils/dom-helpers.js";
|
|
20
|
+
import { getActiveElement, getEventTarget, getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
20
21
|
import { focusableElementOrNull, requireElement } from "../utils/dom-value.js";
|
|
21
22
|
import { focusWithoutScrolling } from "../utils/focus-without-scrolling.js";
|
|
22
23
|
import { isFocusable } from "../utils/is-focusable.js";
|
|
@@ -69,7 +70,7 @@ let ignoreFocusEvent = false;
|
|
|
69
70
|
*/
|
|
70
71
|
function preventFocus(target) {
|
|
71
72
|
let currentTarget = target;
|
|
72
|
-
while (currentTarget && !isFocusable(currentTarget, { skipVisibilityCheck: true })) currentTarget = currentTarget
|
|
73
|
+
while (currentTarget && !isFocusable(currentTarget, { skipVisibilityCheck: true })) currentTarget = focusableElementOrNull(getParentElement(currentTarget));
|
|
73
74
|
const ownerWindow = getOwnerWindow(currentTarget);
|
|
74
75
|
const activeElement = focusableElementOrNull(getActiveElement(ownerWindow.document));
|
|
75
76
|
if (!activeElement || activeElement === currentTarget) return;
|