@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
|
@@ -7,6 +7,7 @@ import { getTruthyValue, isTruthy } from "../utils/truthy.js";
|
|
|
7
7
|
import { getOwnerDocument } from "../utils/dom-helpers.js";
|
|
8
8
|
import { getActiveElement } from "../utils/shadowdom/dom-functions.js";
|
|
9
9
|
import { untrack } from "solid-js";
|
|
10
|
+
import { shadowDOM } from "@solid2-aria/stately/flags/flags";
|
|
10
11
|
// src/focus/virtual-focus.ts
|
|
11
12
|
function moveVirtualFocus(to) {
|
|
12
13
|
const from = getVirtuallyFocusedElement(getOwnerDocument(to));
|
|
@@ -17,8 +18,8 @@ function moveVirtualFocus(to) {
|
|
|
17
18
|
}
|
|
18
19
|
function dispatchVirtualBlur(from, to) {
|
|
19
20
|
untrack(() => {
|
|
20
|
-
from.dispatchEvent(
|
|
21
|
-
from.dispatchEvent(
|
|
21
|
+
from.dispatchEvent(createFocusEvent("blur", { relatedTarget: to }));
|
|
22
|
+
from.dispatchEvent(createFocusEvent("focusout", {
|
|
22
23
|
bubbles: true,
|
|
23
24
|
relatedTarget: to
|
|
24
25
|
}));
|
|
@@ -26,8 +27,8 @@ function dispatchVirtualBlur(from, to) {
|
|
|
26
27
|
}
|
|
27
28
|
function dispatchVirtualFocus(to, from) {
|
|
28
29
|
untrack(() => {
|
|
29
|
-
to.dispatchEvent(
|
|
30
|
-
to.dispatchEvent(
|
|
30
|
+
to.dispatchEvent(createFocusEvent("focus", { relatedTarget: from }));
|
|
31
|
+
to.dispatchEvent(createFocusEvent("focusin", {
|
|
31
32
|
bubbles: true,
|
|
32
33
|
relatedTarget: from
|
|
33
34
|
}));
|
|
@@ -39,6 +40,20 @@ function getVirtuallyFocusedElement(document) {
|
|
|
39
40
|
if (isTruthy(activeDescendant)) return getTruthyValue(document.querySelector(`#${activeDescendant}`)) ?? activeElement;
|
|
40
41
|
return activeElement;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
let originalRelatedTargetMap = null;
|
|
44
|
+
function createFocusEvent(type, eventInitDict) {
|
|
45
|
+
const event = new FocusEvent(type, eventInitDict);
|
|
46
|
+
if (shadowDOM()) {
|
|
47
|
+
originalRelatedTargetMap ??= /* @__PURE__ */ new WeakMap();
|
|
48
|
+
const { relatedTarget } = event;
|
|
49
|
+
if (relatedTarget !== null) originalRelatedTargetMap.set(event, relatedTarget);
|
|
50
|
+
}
|
|
51
|
+
return event;
|
|
52
|
+
}
|
|
53
|
+
function getOriginalRelatedTarget(event) {
|
|
54
|
+
if (!shadowDOM()) return event.relatedTarget;
|
|
55
|
+
return originalRelatedTargetMap?.get(event) ?? event.relatedTarget;
|
|
56
|
+
}
|
|
57
|
+
export { dispatchVirtualBlur, dispatchVirtualFocus, getOriginalRelatedTarget, getVirtuallyFocusedElement, moveVirtualFocus };
|
|
43
58
|
|
|
44
59
|
//# sourceMappingURL=virtual-focus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-focus.js","names":[],"sources":["../../../src/focus/virtual-focus.ts"],"sourcesContent":["/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/virtualFocus.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; dispatch virtual focus events outside reactive tracking so handlers observe event-time state.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { untrack } from \"solid-js\";\n\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { getActiveElement } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport function moveVirtualFocus(to: Element | null): void {\n const from = getVirtuallyFocusedElement(getOwnerDocument(to));\n\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n untrack(() => {\n from.dispatchEvent(
|
|
1
|
+
{"version":3,"file":"virtual-focus.js","names":[],"sources":["../../../src/focus/virtual-focus.ts"],"sourcesContent":["/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/focus/virtualFocus.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; dispatch virtual focus events outside reactive tracking so handlers observe event-time state.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { shadowDOM } from \"@solid2-aria/stately/flags/flags\";\nimport { untrack } from \"solid-js\";\n\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport { getActiveElement } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport function moveVirtualFocus(to: Element | null): void {\n const from = getVirtuallyFocusedElement(getOwnerDocument(to));\n\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n untrack(() => {\n from.dispatchEvent(createFocusEvent(\"blur\", { relatedTarget: to }));\n from.dispatchEvent(\n createFocusEvent(\"focusout\", { bubbles: true, relatedTarget: to })\n );\n });\n}\n\nexport function dispatchVirtualFocus(to: Element, from: Element | null): void {\n untrack(() => {\n to.dispatchEvent(createFocusEvent(\"focus\", { relatedTarget: from }));\n to.dispatchEvent(\n createFocusEvent(\"focusin\", { bubbles: true, relatedTarget: from })\n );\n });\n}\n\nexport function getVirtuallyFocusedElement(document: Document): Element | null {\n const activeElement = getActiveElement(document);\n const activeDescendant = activeElement?.getAttribute(\"aria-activedescendant\");\n\n if (isTruthy(activeDescendant)) {\n return (\n getTruthyValue(document.querySelector(`#${activeDescendant}`)) ??\n activeElement\n );\n }\n\n return activeElement;\n}\n\nlet originalRelatedTargetMap: WeakMap<FocusEvent, EventTarget> | null = null;\n\nfunction createFocusEvent(type: string, eventInitDict?: FocusEventInit) {\n const event = new FocusEvent(type, eventInitDict);\n\n if (shadowDOM()) {\n originalRelatedTargetMap ??= new WeakMap();\n const { relatedTarget } = event;\n\n if (relatedTarget !== null) {\n originalRelatedTargetMap.set(event, relatedTarget);\n }\n }\n\n return event;\n}\n\nexport function getOriginalRelatedTarget(\n event: FocusEvent\n): EventTarget | null {\n if (!shadowDOM()) {\n return event.relatedTarget;\n }\n\n return originalRelatedTargetMap?.get(event) ?? event.relatedTarget;\n}\n"],"mappings":";;;;;;;;;;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18
|
import { isPresent } from "../utils/is-present.js";
|
|
19
19
|
import { mergeProps } from "../utils/merge-props.js";
|
|
20
20
|
import { getOwnerDocument } from "../utils/dom-helpers.js";
|
|
21
|
-
import { getActiveElement, getEventTarget, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
21
|
+
import { getActiveElement, getEventTarget, getParentElement, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
22
22
|
import { elementOrNull, focusableElementOrNull, requireFocusableElement } from "../utils/dom-value.js";
|
|
23
23
|
import { requireValue } from "../utils/require-value.js";
|
|
24
24
|
import { isFocusVisible } from "../interactions/create-focus-visible.js";
|
|
@@ -107,7 +107,7 @@ function createGridCell(props, state, ref) {
|
|
|
107
107
|
scrollIntoViewport(focusable, { containingElement: getScrollParent(cell) });
|
|
108
108
|
} else {
|
|
109
109
|
if (_result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key) !== _result0.node.key) {
|
|
110
|
-
cell
|
|
110
|
+
getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
if (focusMode() === "cell" && _result1.direction === "rtl") {
|
|
@@ -133,7 +133,7 @@ function createGridCell(props, state, ref) {
|
|
|
133
133
|
scrollIntoViewport(focusable, { containingElement: getScrollParent(cell) });
|
|
134
134
|
} else {
|
|
135
135
|
if (_result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key) !== _result0.node.key) {
|
|
136
|
-
cell
|
|
136
|
+
getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
if (focusMode() === "cell" && _result1.direction === "ltr") {
|
|
@@ -166,7 +166,7 @@ function createGridCell(props, state, ref) {
|
|
|
166
166
|
case "ArrowDown": if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {
|
|
167
167
|
e.stopPropagation();
|
|
168
168
|
e.preventDefault();
|
|
169
|
-
refElement
|
|
169
|
+
getParentElement(refElement)?.dispatchEvent(new KeyboardEvent(e.type, e));
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-grid-cell.js","names":[],"sources":["../../../src/grid/create-grid-cell.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/grid/useGridCell.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 { GridState } from \"@solid2-aria/stately/grid/create-grid-state\";\nimport type {\n IGridCollection as GridCollection,\n GridNode,\n} from \"@solid2-aria/stately/grid/grid-collection\";\nimport type { FocusableElement, Key } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { 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 { KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { createEvent } from \"../utils/create-event\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport {\n elementOrNull,\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\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 { isTruthy } from \"../utils/truthy\";\nimport { gridMap } from \"./utils\";\n\nexport interface GridCellProps {\n /**\n * An object representing the grid cell. Contains all the relevant information that makes up the\n * grid cell.\n */\n node: GridNode<unknown>;\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /**\n * Whether the cell or its first focusable child element should be focused when the grid cell is\n * focused. Defaults to 'child' in arrow keyboard navigation mode and 'cell' in\n * tab keyboard navigation mode.\n */\n focusMode?: \"child\" | \"cell\";\n /**\n * Whether the cell should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows and cells with arrow keys while\n * focus is on an interactive child element within the cell.\n */\n allowsArrowNavigation?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Indicates how many columns the data cell spans. */\n colSpan?: number;\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n *\n * @deprecated\n */\n onAction?: () => void;\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes;\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n *\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function createGridCell<T, C extends GridCollection<T>>(\n props: GridCellProps,\n state: GridState<T, C>,\n ref: Accessor<FocusableElement | null>\n): GridCellAria {\n const _result0 = props;\n const _result1 = createLocale();\n\n const _result2 = requireValue(\n gridMap.get(state),\n \"Expected gridMap.get(state)\"\n );\n\n const focusMode = createMemo(\n () =>\n _result0.focusMode ??\n (_result2.keyboardNavigationBehavior === \"tab\" ? \"cell\" : \"child\")\n );\n\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 // Tracks the specific focusable child that was last focused within this cell.\n let lastFocusedChild: FocusableElement | null = null;\n\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n const focus = () => {\n const refElement = ref();\n\n if (refElement) {\n const treeWalker = getFocusableTreeWalker(refElement);\n\n if (focusMode() === \"child\") {\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (isFocusWithin(refElement) && refElement !== activeElement) {\n return;\n }\n\n const ownerDocument = getOwnerDocument(refElement);\n\n const shouldRestoreToLastFocused =\n !activeElement ||\n activeElement === ownerDocument.body ||\n activeElement === refElement;\n\n if (shouldRestoreToLastFocused) {\n const lastChild = lastFocusedChild;\n\n if (\n lastChild &&\n keyWhenFocused === _result0.node.key &&\n nodeContains(refElement, lastChild)\n ) {\n focusSafely(lastChild);\n\n return;\n }\n }\n\n const focusable =\n state.selectionManager.childFocusStrategy === \"last\"\n ? last(treeWalker)\n : focusableElementOrNull(treeWalker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n\n return;\n }\n }\n\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n }\n };\n\n const _result3 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isDisabled() {\n return state.collection.size === 0;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get onAction() {\n return _result2.actions.onCellAction\n ? () => _result2.actions.onCellAction?.(_result0.node.key)\n : getLegacyOption(_result0, \"onAction\");\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return _result0.shouldSelectOnPressUp;\n },\n });\n\n function focusLeftInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n const prev = _result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key);\n\n if (prev !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"rtl\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.firstChild())\n : last(walker);\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n function focusRightInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n const next = _result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key);\n\n if (next !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n cell.parentElement?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"ltr\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? last(walker)\n : focusableElementOrNull(walker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n switch (e.key) {\n case \"ArrowLeft\": {\n focusLeftInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowRight\": {\n focusRightInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n _result2.keyboardNavigationBehavior !== \"tab\" ||\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 state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (\n _result2.keyboardNavigationBehavior === \"tab\" &&\n getEventTarget(e) !== refElement &&\n e.key !== \"Tab\"\n ) {\n e.stopPropagation();\n\n return;\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (_result2.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 // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\n const onFocus = (e: FocusEvent) => {\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n const target = requireFocusableElement(getEventTarget(e));\n\n if (ref() && nodeContains(ref(), target)) {\n lastFocusedChild = target;\n }\n\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 focusMode() === \"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 focusMode() === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n const gridCellProps = createMemo(() => {\n const result = mergeProps(_result3.itemProps, {\n \"aria-colindex\": ariaValue(\n isPresent(_result0.node.colIndex)\n ? _result0.node.colIndex + 1\n : undefined\n // aria-colindex is 1-based\n ),\n \"aria-colspan\": ariaValue(_result0.node.colSpan),\n colspan: isTruthy(_result0.isVirtualized)\n ? undefined\n : _result0.node.colSpan,\n onFocus,\n onKeyDown:\n _result2.keyboardNavigationBehavior === \"tab\" ? onKeyDown : undefined,\n role: \"gridcell\",\n\n // make sure shift tabbing from a child of a cell doesnt move focus back to cell if focusMode=\"child\" and in tab nav\n // consistent with arrow nav and focusMode=\"child\" since you can't go back to the cell there either\n });\n\n if (\n focusMode() === \"child\" &&\n _result2.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n if (isTruthy(_result0.isVirtualized)) {\n result[\"aria-colindex\"] =\n // aria-colindex is 1-based\n (_result0.node.colIndex ?? _result0.node.index) + 1;\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (\n isTruthy(_result0.shouldSelectOnPressUp) &&\n result.tabindex !== null &&\n result.tabindex !== undefined &&\n !isPresent(result.onPointerDown)\n ) {\n result.onPointerDown = (e) => {\n const el = e.currentTarget;\n const tabindex = el.getAttribute(\"tabindex\");\n el.removeAttribute(\"tabindex\");\n requestAnimationFrame(() => {\n if (isPresent(tabindex)) {\n el.setAttribute(\"tabindex\", tabindex);\n }\n });\n };\n }\n\n return result;\n });\n\n return {\n get gridCellProps() {\n return gridCellProps();\n },\n get isPressed() {\n return _result3.isPressed;\n },\n };\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAgB,eACd,OACA,OACA,KACc;CACd,MAAM,WAAW;CACjB,MAAM,WAAW,aAAa;CAE9B,MAAM,WAAW,aACf,QAAQ,IAAI,KAAK,GACjB,6BACF;CAEA,MAAM,YAAY,iBAEd,SAAS,cACR,SAAS,+BAA+B,QAAQ,SAAS,QAC9D;CAIA,IAAI,iBAA6B;CAEjC,IAAI,mBAA4C;CAIhD,MAAM,cAAc;EAClB,MAAM,aAAa,IAAI;EAEvB,IAAI,YAAY;GACd,MAAM,aAAa,uBAAuB,UAAU;GAEpD,IAAI,UAAU,MAAM,SAAS;IAC3B,MAAM,gBAAgB,iBAAiB,iBAAiB,UAAU,CAAC;IAGnE,IAAI,cAAc,UAAU,KAAK,eAAe,eAC9C;IAGF,MAAM,gBAAgB,iBAAiB,UAAU;IAOjD,IAJE,CAAC,iBACD,kBAAkB,cAAc,QAChC,kBAAkB,YAEY;KAC9B,MAAM,YAAY;KAElB,IACE,aACA,mBAAmB,SAAS,KAAK,OACjC,aAAa,YAAY,SAAS,GAClC;MACA,YAAY,SAAS;MAErB;KACF;IACF;IAEA,MAAM,YACJ,MAAM,iBAAiB,uBAAuB,SAC1C,KAAK,UAAU,IACf,uBAAuB,WAAW,WAAW,CAAC;IAEpD,IAAI,WAAW;KACb,YAAY,SAAS;KAErB;IACF;GAC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EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"create-grid-cell.js","names":[],"sources":["../../../src/grid/create-grid-cell.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/grid/useGridCell.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 { GridState } from \"@solid2-aria/stately/grid/create-grid-state\";\nimport type {\n IGridCollection as GridCollection,\n GridNode,\n} from \"@solid2-aria/stately/grid/grid-collection\";\nimport type { FocusableElement, Key } from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { 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 { KeyboardEvent as DOMKeyboardEvent } from \"../types\";\nimport { ariaValue } from \"../utils/aria-value\";\nimport { createEvent } from \"../utils/create-event\";\nimport { getOwnerDocument } from \"../utils/dom-helpers\";\nimport {\n elementOrNull,\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isPresent } from \"../utils/is-present\";\nimport { getLegacyOption } from \"../utils/legacy-option\";\nimport { mergeProps } from \"../utils/merge-props\";\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 { isTruthy } from \"../utils/truthy\";\nimport { gridMap } from \"./utils\";\n\nexport interface GridCellProps {\n /**\n * An object representing the grid cell. Contains all the relevant information that makes up the\n * grid cell.\n */\n node: GridNode<unknown>;\n /** Whether the grid cell is contained in a virtual scroller. */\n isVirtualized?: boolean;\n /**\n * Whether the cell or its first focusable child element should be focused when the grid cell is\n * focused. Defaults to 'child' in arrow keyboard navigation mode and 'cell' in\n * tab keyboard navigation mode.\n */\n focusMode?: \"child\" | \"cell\";\n /**\n * Whether the cell should support arrow key navigation even when the containing collection uses\n * tab keyboard navigation. Allows users to navigate between rows and cells with arrow keys while\n * focus is on an interactive child element within the cell.\n */\n allowsArrowNavigation?: boolean;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n /** Indicates how many columns the data cell spans. */\n colSpan?: number;\n /**\n * Handler that is called when a user performs an action on the cell.\n * Please use onCellAction at the collection level instead.\n *\n * @deprecated\n */\n onAction?: () => void;\n}\n\nexport interface GridCellAria {\n /** Props for the grid cell element. */\n gridCellProps: DOMAttributes;\n /** Whether the cell is currently in a pressed state. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a cell in a grid.\n *\n * @param props - Props for the cell.\n * @param state - State of the parent grid, as returned by `useGridState`.\n */\nexport function createGridCell<T, C extends GridCollection<T>>(\n props: GridCellProps,\n state: GridState<T, C>,\n ref: Accessor<FocusableElement | null>\n): GridCellAria {\n const _result0 = props;\n const _result1 = createLocale();\n\n const _result2 = requireValue(\n gridMap.get(state),\n \"Expected gridMap.get(state)\"\n );\n\n const focusMode = createMemo(\n () =>\n _result0.focusMode ??\n (_result2.keyboardNavigationBehavior === \"tab\" ? \"cell\" : \"child\")\n );\n\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 // Tracks the specific focusable child that was last focused within this cell.\n let lastFocusedChild: FocusableElement | null = null;\n\n // Handles focusing the cell. If there is a focusable child,\n // it is focused, otherwise the cell itself is focused.\n const focus = () => {\n const refElement = ref();\n\n if (refElement) {\n const treeWalker = getFocusableTreeWalker(refElement);\n\n if (focusMode() === \"child\") {\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n // If focus is already on a focusable child within the cell, early return so we don't shift focus\n if (isFocusWithin(refElement) && refElement !== activeElement) {\n return;\n }\n\n const ownerDocument = getOwnerDocument(refElement);\n\n const shouldRestoreToLastFocused =\n !activeElement ||\n activeElement === ownerDocument.body ||\n activeElement === refElement;\n\n if (shouldRestoreToLastFocused) {\n const lastChild = lastFocusedChild;\n\n if (\n lastChild &&\n keyWhenFocused === _result0.node.key &&\n nodeContains(refElement, lastChild)\n ) {\n focusSafely(lastChild);\n\n return;\n }\n }\n\n const focusable =\n state.selectionManager.childFocusStrategy === \"last\"\n ? last(treeWalker)\n : focusableElementOrNull(treeWalker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n\n return;\n }\n }\n\n if (\n (isPresent(keyWhenFocused) && _result0.node.key !== keyWhenFocused) ||\n !isFocusWithin(refElement)\n ) {\n focusSafely(refElement);\n }\n }\n };\n\n const _result3 = createSelectableItem({\n get focus() {\n return focus;\n },\n get isDisabled() {\n return state.collection.size === 0;\n },\n get isVirtualized() {\n return _result0.isVirtualized;\n },\n get key() {\n return _result0.node.key;\n },\n get onAction() {\n return _result2.actions.onCellAction\n ? () => _result2.actions.onCellAction?.(_result0.node.key)\n : getLegacyOption(_result0, \"onAction\");\n },\n get ref() {\n return ref;\n },\n get selectionManager() {\n return state.selectionManager;\n },\n get shouldSelectOnPressUp() {\n return _result0.shouldSelectOnPressUp;\n },\n });\n\n function focusLeftInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n // Find the next focusable element within the cell.\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.nextNode())\n : focusableElementOrNull(walker.previousNode());\n\n // Don't focus the cell itself if focusMode is \"child\"\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n // If there is no next focusable child, then move to the next cell to the left of this one.\n // This will be handled by useSelectableCollection. However, if there is no cell to the left\n // of this one, only one column, and the grid doesn't focus rows, then the next key will be the\n // same as this one. In that case we need to handle focusing either the cell or the first/last\n // child, depending on the focus mode.\n const prev = _result2.keyboardDelegate.getKeyLeftOf?.(_result0.node.key);\n\n if (prev !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"rtl\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.firstChild())\n : last(walker);\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n function focusRightInCell(\n e: DOMKeyboardEvent,\n walker: TreeWalker,\n cell: FocusableElement\n ): void {\n let focusable: FocusableElement | null =\n _result1.direction === \"rtl\"\n ? focusableElementOrNull(walker.previousNode())\n : focusableElementOrNull(walker.nextNode());\n\n if (focusMode() === \"child\" && focusable === cell) {\n focusable = null;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n } else {\n const next = _result2.keyboardDelegate.getKeyRightOf?.(_result0.node.key);\n\n if (next !== _result0.node.key) {\n // We prevent the capturing event from reaching children of the cell, e.g. pickers.\n // We want arrow keys to navigate to the next cell instead. We need to re-dispatch\n // the event from a higher parent so it still bubbles and gets handled by useSelectableCollection.\n getParentElement(cell)?.dispatchEvent(new KeyboardEvent(e.type, e));\n\n return;\n }\n\n if (focusMode() === \"cell\" && _result1.direction === \"ltr\") {\n focusSafely(cell);\n scrollIntoViewport(cell, {\n containingElement: getScrollParent(cell),\n });\n } else {\n walker.currentNode = cell;\n focusable =\n _result1.direction === \"rtl\"\n ? last(walker)\n : focusableElementOrNull(walker.firstChild());\n\n if (focusable) {\n focusSafely(focusable);\n scrollIntoViewport(focusable, {\n containingElement: getScrollParent(cell),\n });\n }\n }\n }\n }\n\n const handleCaptureKeyDown = (e: DOMKeyboardEvent) => {\n const refElement = ref();\n const activeElement = getActiveElement(getOwnerDocument(refElement));\n\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n const walker = getFocusableTreeWalker(refElement);\n walker.currentNode = activeElement;\n\n switch (e.key) {\n case \"ArrowLeft\": {\n focusLeftInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowRight\": {\n focusRightInCell(e, walker, refElement);\n break;\n }\n\n case \"ArrowUp\":\n case \"ArrowDown\": {\n // Prevent this event from reaching cell children, e.g. menu buttons. We want arrow keys to navigate\n // to the cell 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 createEvent(\n ref,\n \"keydown\",\n (event) => {\n if (\n _result2.keyboardNavigationBehavior !== \"tab\" ||\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 state.isKeyboardNavigationDisabled ||\n !refElement ||\n !activeElement\n ) {\n return;\n }\n\n if (\n _result2.keyboardNavigationBehavior === \"tab\" &&\n getEventTarget(e) !== refElement &&\n e.key !== \"Tab\"\n ) {\n e.stopPropagation();\n\n return;\n }\n\n switch (e.key) {\n case \"Tab\": {\n if (_result2.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 // Grid cells can have focusable elements inside them. In this case, focus should\n // be marshalled to that element rather than focusing the cell itself.\n const onFocus = (e: FocusEvent) => {\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 gridcell 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/cell\n // in that case since the table should act like a single tab stop.\n const target = requireFocusableElement(getEventTarget(e));\n\n if (ref() && nodeContains(ref(), target)) {\n lastFocusedChild = target;\n }\n\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 focusMode() === \"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 focusMode() === \"child\" &&\n getActiveElement(getOwnerDocument(ref())) === ref()\n ) {\n focus();\n }\n });\n };\n\n const gridCellProps = createMemo(() => {\n const result = mergeProps(_result3.itemProps, {\n \"aria-colindex\": ariaValue(\n isPresent(_result0.node.colIndex)\n ? _result0.node.colIndex + 1\n : undefined\n // aria-colindex is 1-based\n ),\n \"aria-colspan\": ariaValue(_result0.node.colSpan),\n colspan: isTruthy(_result0.isVirtualized)\n ? undefined\n : _result0.node.colSpan,\n onFocus,\n onKeyDown:\n _result2.keyboardNavigationBehavior === \"tab\" ? onKeyDown : undefined,\n role: \"gridcell\",\n\n // make sure shift tabbing from a child of a cell doesnt move focus back to cell if focusMode=\"child\" and in tab nav\n // consistent with arrow nav and focusMode=\"child\" since you can't go back to the cell there either\n });\n\n if (\n focusMode() === \"child\" &&\n _result2.keyboardNavigationBehavior === \"tab\"\n ) {\n result.tabindex = -1;\n }\n\n if (isTruthy(_result0.isVirtualized)) {\n result[\"aria-colindex\"] =\n // aria-colindex is 1-based\n (_result0.node.colIndex ?? _result0.node.index) + 1;\n }\n\n // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the\n // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault\n // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.\n // To avoid this, remove the tabIndex from the cell briefly on pointer down.\n if (\n isTruthy(_result0.shouldSelectOnPressUp) &&\n result.tabindex !== null &&\n result.tabindex !== undefined &&\n !isPresent(result.onPointerDown)\n ) {\n result.onPointerDown = (e) => {\n const el = e.currentTarget;\n const tabindex = el.getAttribute(\"tabindex\");\n el.removeAttribute(\"tabindex\");\n requestAnimationFrame(() => {\n if (isPresent(tabindex)) {\n el.setAttribute(\"tabindex\", tabindex);\n }\n });\n };\n }\n\n return result;\n });\n\n return {\n get gridCellProps() {\n return gridCellProps();\n },\n get isPressed() {\n return _result3.isPressed;\n },\n };\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,eACd,OACA,OACA,KACc;CACd,MAAM,WAAW;CACjB,MAAM,WAAW,aAAa;CAE9B,MAAM,WAAW,aACf,QAAQ,IAAI,KAAK,GACjB,6BACF;CAEA,MAAM,YAAY,iBAEd,SAAS,cACR,SAAS,+BAA+B,QAAQ,SAAS,QAC9D;CAIA,IAAI,iBAA6B;CAEjC,IAAI,mBAA4C;CAIhD,MAAM,cAAc;EAClB,MAAM,aAAa,IAAI;EAEvB,IAAI,YAAY;GACd,MAAM,aAAa,uBAAuB,UAAU;GAEpD,IAAI,UAAU,MAAM,SAAS;IAC3B,MAAM,gBAAgB,iBAAiB,iBAAiB,UAAU,CAAC;IAGnE,IAAI,cAAc,UAAU,KAAK,eAAe,eAC9C;IAGF,MAAM,gBAAgB,iBAAiB,UAAU;IAOjD,IAJE,CAAC,iBACD,kBAAkB,cAAc,QAChC,kBAAkB,YAEY;KAC9B,MAAM,YAAY;KAElB,IACE,aACA,mBAAmB,SAAS,KAAK,OACjC,aAAa,YAAY,SAAS,GAClC;MACA,YAAY,SAAS;MAErB;KACF;IACF;IAEA,MAAM,YACJ,MAAM,iBAAiB,uBAAuB,SAC1C,KAAK,UAAU,IACf,uBAAuB,WAAW,WAAW,CAAC;IAEpD,IAAI,WAAW;KACb,YAAY,SAAS;KAErB;IACF;GACF;GAEA,I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CACpC,IAAI,YAAqC;CAEzC,GAAG;EACD,YAAY,uBAAuB,OAAO,UAAU,CAAC;EAErD,IAAI,WACF,OAAO;CAEX,SAAS;CAET,OAAO;AACT"}
|
|
@@ -20,7 +20,7 @@ import { createSlotId } from "../utils/create-id.js";
|
|
|
20
20
|
import { isPresent } from "../utils/is-present.js";
|
|
21
21
|
import { mergeProps } from "../utils/merge-props.js";
|
|
22
22
|
import { getOwnerDocument } from "../utils/dom-helpers.js";
|
|
23
|
-
import { getActiveElement, getEventTarget, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
23
|
+
import { getActiveElement, getEventTarget, getParentElement, isFocusWithin, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
24
24
|
import { elementOrNull, focusableElementOrNull } from "../utils/dom-value.js";
|
|
25
25
|
import { requireValue } from "../utils/require-value.js";
|
|
26
26
|
import { isPropagationStopped } from "../utils/is-propagation-stopped.js";
|
|
@@ -178,7 +178,7 @@ function createGridListItem(props, state, ref) {
|
|
|
178
178
|
case "ArrowDown": if (!e.altKey && nodeContains(refElement, getEventTarget(e))) {
|
|
179
179
|
e.stopPropagation();
|
|
180
180
|
e.preventDefault();
|
|
181
|
-
refElement
|
|
181
|
+
getParentElement(refElement)?.dispatchEvent(new KeyboardEvent(e.type, e));
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
};
|
|
@@ -224,7 +224,7 @@ function createGridListItem(props, state, ref) {
|
|
|
224
224
|
"aria-labelledby": ariaValue(isTruthy(descriptionId()) && (isTruthy(_result0.node["aria-label"]) || _result0.node.textValue) ? `${getRowId(state, _result0.node.key)} ${descriptionId()}` : void 0),
|
|
225
225
|
"aria-selected": ariaValue(state.selectionManager.canSelectItem(_result0.node.key) ? state.selectionManager.isSelected(_result0.node.key) : void 0),
|
|
226
226
|
id: getRowId(state, _result0.node.key),
|
|
227
|
-
onFocus,
|
|
227
|
+
onFocusIn: onFocus,
|
|
228
228
|
role: "row"
|
|
229
229
|
});
|
|
230
230
|
if ((_result0.focusMode ?? "row") === "child" && isTruthy(_result0.allowsArrowNavigation) && listData.keyboardNavigationBehavior === "tab") result.tabindex = -1;
|
|
@@ -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,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AAY,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,KAC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;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,iBAAi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AAG,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,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AAa,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"}
|
|
@@ -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);
|