@react-aria/gridlist 3.8.2-nightly.4659 → 3.8.2-nightly.4664
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/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useGridList.main.js +3 -2
- package/dist/useGridList.main.js.map +1 -1
- package/dist/useGridList.mjs +3 -2
- package/dist/useGridList.module.js +3 -2
- package/dist/useGridList.module.js.map +1 -1
- package/dist/useGridListItem.main.js +16 -5
- package/dist/useGridListItem.main.js.map +1 -1
- package/dist/useGridListItem.mjs +16 -5
- package/dist/useGridListItem.module.js +16 -5
- package/dist/useGridListItem.module.js.map +1 -1
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.module.js.map +1 -1
- package/package.json +12 -12
- package/src/useGridList.ts +11 -3
- package/src/useGridListItem.ts +57 -41
- package/src/utils.ts +2 -1
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export interface GridListProps<T> extends CollectionBase<T>, MultipleSelection {
|
|
|
14
14
|
disabledBehavior?: DisabledBehavior;
|
|
15
15
|
}
|
|
16
16
|
export interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLabelingProps {
|
|
17
|
+
/**
|
|
18
|
+
* Whether keyboard navigation to focusable elements within grid list items is
|
|
19
|
+
* via the left/right arrow keys or the tab key.
|
|
20
|
+
* @default 'arrow'
|
|
21
|
+
*/
|
|
22
|
+
keyboardNavigationBehavior?: 'arrow' | 'tab';
|
|
17
23
|
}
|
|
18
24
|
export interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {
|
|
19
25
|
/** Whether the list uses virtual scrolling. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AC8BA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,iBAAiB;IAC5E;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,G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B,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,iCAAkC,SAAQ,oBAAoB;IAC5D,sCAAsC;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,2DAA2D;IAC3D,aAAa,EAAE,aAAa,CAAC;IAC7B,2DAA2D;IAC3D,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAaD;;;;;GAKG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,gBAAgB,CAkOzJ;AC7QD;;;;GAIG;AACH,6CAA6C,CAAC,EAAE,KAAK,EAAE,8BAA8B,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,yBAAyB,CAUrI;ACbD,YAAY,EAAC,8BAA8B,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC","sources":["packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/utils.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridList.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListItem.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/useGridListSelectionCheckbox.ts","packages/@react-aria/gridlist/src/packages/@react-aria/gridlist/src/index.ts","packages/@react-aria/gridlist/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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\nexport {useGridList} from './useGridList';\nexport {useGridListItem} from './useGridListItem';\nexport {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';\n\nexport type {AriaGridListOptions, AriaGridListProps, GridListAria, GridListProps} from './useGridList';\nexport type {AriaGridListItemOptions, GridListItemAria} from './useGridListItem';\nexport type {AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria} from '@react-aria/grid';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/useGridList.main.js
CHANGED
|
@@ -26,7 +26,7 @@ $parcel$export(module.exports, "useGridList", () => $acf209ae814f1c93$export$664
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
function $acf209ae814f1c93$export$664f9155035607eb(props, state, ref) {
|
|
29
|
-
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action' } = props;
|
|
29
|
+
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action', keyboardNavigationBehavior: keyboardNavigationBehavior = 'arrow' } = props;
|
|
30
30
|
if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
|
|
31
31
|
let { listProps: listProps } = (0, $i2dnl$reactariaselection.useSelectableList)({
|
|
32
32
|
selectionManager: state.selectionManager,
|
|
@@ -43,7 +43,8 @@ function $acf209ae814f1c93$export$664f9155035607eb(props, state, ref) {
|
|
|
43
43
|
(0, $7db02799adae605d$exports.listMap).set(state, {
|
|
44
44
|
id: id,
|
|
45
45
|
onAction: onAction,
|
|
46
|
-
linkBehavior: linkBehavior
|
|
46
|
+
linkBehavior: linkBehavior,
|
|
47
|
+
keyboardNavigationBehavior: keyboardNavigationBehavior
|
|
47
48
|
});
|
|
48
49
|
let descriptionProps = (0, $i2dnl$reactariagrid.useHighlightSelectionDescription)({
|
|
49
50
|
selectionManager: state.selectionManager,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;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S,CAAC,gBAAgB,GAAG,MAAM,UAAU,CAAC,IAAI;QAClD,SAAS,CAAC,gBAAgB,GAAG;IAC/B;IAEA,CAAA,GAAA,iDAA2B,EAAE,CAAC,GAAG;IAEjC,OAAO;mBACL;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridList.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\nimport {\n AriaLabelingProps,\n CollectionBase,\n DisabledBehavior,\n DOMAttributes,\n DOMProps,\n Key,\n KeyboardDelegate,\n MultipleSelection\n} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {listMap} from './utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject} from 'react';\nimport {useGridSelectionAnnouncement, useHighlightSelectionDescription} from '@react-aria/grid';\nimport {useHasTabbableChild} from '@react-aria/focus';\nimport {useSelectableList} from '@react-aria/selection';\n\nexport interface GridListProps<T> extends CollectionBase<T>, MultipleSelection {\n /**\n * Handler that is called when a user performs an action on an item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: (key: Key) => void,\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\n\nexport interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLabelingProps {\n /**\n * Whether keyboard navigation to focusable elements within grid list items is\n * via the left/right arrow keys or the tab key.\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab'\n}\n\nexport interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {\n /** Whether the list uses virtual scrolling. */\n isVirtualized?: boolean,\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface GridListAria {\n /** Props for the grid element. */\n gridProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a list component with interactive children.\n * A grid list displays data in a single column and enables a user to navigate its contents via directional navigation keys.\n * @param props - Props for the list.\n * @param state - State for the list, as returned by `useListState`.\n * @param ref - The ref attached to the list element.\n */\nexport function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement>): GridListAria {\n let {\n isVirtualized,\n keyboardDelegate,\n onAction,\n linkBehavior = 'action',\n keyboardNavigationBehavior = 'arrow'\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let {listProps} = useSelectableList({\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n ref,\n keyboardDelegate: keyboardDelegate,\n isVirtualized,\n selectOnFocus: state.selectionManager.selectionBehavior === 'replace',\n shouldFocusWrap: props.shouldFocusWrap,\n linkBehavior\n });\n\n let id = useId(props.id);\n listMap.set(state, {id, onAction, linkBehavior, keyboardNavigationBehavior});\n\n let descriptionProps = useHighlightSelectionDescription({\n selectionManager: state.selectionManager,\n hasItemActions: !!onAction\n });\n\n let hasTabbableChild = useHasTabbableChild(ref, {\n isDisabled: state.collection.size !== 0\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n let gridProps: DOMAttributes = mergeProps(\n domProps,\n {\n role: 'grid',\n id,\n 'aria-multiselectable': state.selectionManager.selectionMode === 'multiple' ? 'true' : undefined\n },\n // If collection is empty, make sure the grid is tabbable unless there is a child tabbable element.\n state.collection.size === 0 ? {tabIndex: hasTabbableChild ? -1 : 0} : listProps,\n descriptionProps\n );\n\n if (isVirtualized) {\n gridProps['aria-rowcount'] = state.collection.size;\n gridProps['aria-colcount'] = 1;\n }\n\n useGridSelectionAnnouncement({}, state);\n\n return {\n gridProps\n };\n}\n"],"names":[],"version":3,"file":"useGridList.main.js.map"}
|
package/dist/useGridList.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import {useSelectableList as $lnALe$useSelectableList} from "@react-aria/selecti
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
function $f47efb0c3a859cf2$export$664f9155035607eb(props, state, ref) {
|
|
23
|
-
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action' } = props;
|
|
23
|
+
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action', keyboardNavigationBehavior: keyboardNavigationBehavior = 'arrow' } = props;
|
|
24
24
|
if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
|
|
25
25
|
let { listProps: listProps } = (0, $lnALe$useSelectableList)({
|
|
26
26
|
selectionManager: state.selectionManager,
|
|
@@ -37,7 +37,8 @@ function $f47efb0c3a859cf2$export$664f9155035607eb(props, state, ref) {
|
|
|
37
37
|
(0, $ce9b18daab526bbd$export$5b9bb410392e3991).set(state, {
|
|
38
38
|
id: id,
|
|
39
39
|
onAction: onAction,
|
|
40
|
-
linkBehavior: linkBehavior
|
|
40
|
+
linkBehavior: linkBehavior,
|
|
41
|
+
keyboardNavigationBehavior: keyboardNavigationBehavior
|
|
41
42
|
});
|
|
42
43
|
let descriptionProps = (0, $lnALe$useHighlightSelectionDescription)({
|
|
43
44
|
selectionManager: state.selectionManager,
|
|
@@ -20,7 +20,7 @@ import {useSelectableList as $lnALe$useSelectableList} from "@react-aria/selecti
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
function $f47efb0c3a859cf2$export$664f9155035607eb(props, state, ref) {
|
|
23
|
-
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action' } = props;
|
|
23
|
+
let { isVirtualized: isVirtualized, keyboardDelegate: keyboardDelegate, onAction: onAction, linkBehavior: linkBehavior = 'action', keyboardNavigationBehavior: keyboardNavigationBehavior = 'arrow' } = props;
|
|
24
24
|
if (!props['aria-label'] && !props['aria-labelledby']) console.warn('An aria-label or aria-labelledby prop is required for accessibility.');
|
|
25
25
|
let { listProps: listProps } = (0, $lnALe$useSelectableList)({
|
|
26
26
|
selectionManager: state.selectionManager,
|
|
@@ -37,7 +37,8 @@ function $f47efb0c3a859cf2$export$664f9155035607eb(props, state, ref) {
|
|
|
37
37
|
(0, $ce9b18daab526bbd$export$5b9bb410392e3991).set(state, {
|
|
38
38
|
id: id,
|
|
39
39
|
onAction: onAction,
|
|
40
|
-
linkBehavior: linkBehavior
|
|
40
|
+
linkBehavior: linkBehavior,
|
|
41
|
+
keyboardNavigationBehavior: keyboardNavigationBehavior
|
|
41
42
|
});
|
|
42
43
|
let descriptionProps = (0, $lnALe$useHighlightSelectionDescription)({
|
|
43
44
|
selectionManager: state.selectionManager,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA0EM,SAAS,0CAAe,KAA6B,EAAE,KAAmB,EAAE,GAA2B;IAC5G,IAAI,iBACF,aAAa,oBACb,gBAAgB,YAChB,QAAQ,gBACR,eAAe,sCACf,6BAA6B,SAC9B,GAAG;IAEJ,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,kBAAkB,EACnD,QAAQ,IAAI,CAAC;IAGf,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,wBAAgB,EAAE;QAClC,kBAAkB,MAAM,gBAAgB;QACxC,YAAY,MAAM,UAAU;QAC5B,cAAc,MAAM,YAAY;aAChC;QACA,kBAAkB;uBAClB;QACA,eAAe,MAAM,gBAAgB,CAAC,iBAAiB,KAAK;QAC5D,iBAAiB,MAAM,eAAe;sBACtC;IACF;IAEA,IAAI,KAAK,CAAA,GAAA,YAAI,EAAE,MAAM,EAAE;IACvB,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC,OAAO;YAAC;kBAAI;sBAAU;oCAAc;IAA0B;IAE1E,IAAI,mBAAmB,CAAA,GAAA,uCAA+B,EAAE;QACtD,kBAAkB,MAAM,gBAAgB;QACxC,gBAAgB,CAAC,CAAC;IACpB;IAEA,IAAI,mBAAmB,CAAA,GAAA,0BAAkB,EAAE,KAAK;QAC9C,YAAY,MAAM,UAAU,CAAC,IAAI,KAAK;IACxC;IAEA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,YAA2B,CAAA,GAAA,iBAAS,EACtC,UACA;QACE,MAAM;YACN;QACA,wBAAwB,MAAM,gBAAgB,CAAC,aAAa,KAAK,aAAa,SAAS;IACzF,GACA,mGAAmG;IACnG,MAAM,UAAU,CAAC,IAAI,KAAK,IAAI;QAAC,UAAU,mBAAmB,KAAK;IAAC,IAAI,WACtE;IAGF,IAAI,eAAe;QACjB,SAAS,CAAC,gBAAgB,GAAG,MAAM,UAAU,CAAC,IAAI;QAClD,SAAS,CAAC,gBAAgB,GAAG;IAC/B;IAEA,CAAA,GAAA,mCAA2B,EAAE,CAAC,GAAG;IAEjC,OAAO;mBACL;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridList.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\nimport {\n AriaLabelingProps,\n CollectionBase,\n DisabledBehavior,\n DOMAttributes,\n DOMProps,\n Key,\n KeyboardDelegate,\n MultipleSelection\n} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {listMap} from './utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject} from 'react';\nimport {useGridSelectionAnnouncement, useHighlightSelectionDescription} from '@react-aria/grid';\nimport {useHasTabbableChild} from '@react-aria/focus';\nimport {useSelectableList} from '@react-aria/selection';\n\nexport interface GridListProps<T> extends CollectionBase<T>, MultipleSelection {\n /**\n * Handler that is called when a user performs an action on an item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: (key: Key) => void,\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\n\nexport interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLabelingProps {\n /**\n * Whether keyboard navigation to focusable elements within grid list items is\n * via the left/right arrow keys or the tab key.\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab'\n}\n\nexport interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {\n /** Whether the list uses virtual scrolling. */\n isVirtualized?: boolean,\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface GridListAria {\n /** Props for the grid element. */\n gridProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a list component with interactive children.\n * A grid list displays data in a single column and enables a user to navigate its contents via directional navigation keys.\n * @param props - Props for the list.\n * @param state - State for the list, as returned by `useListState`.\n * @param ref - The ref attached to the list element.\n */\nexport function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement>): GridListAria {\n let {\n isVirtualized,\n keyboardDelegate,\n onAction,\n linkBehavior = 'action',\n keyboardNavigationBehavior = 'arrow'\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let {listProps} = useSelectableList({\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n ref,\n keyboardDelegate: keyboardDelegate,\n isVirtualized,\n selectOnFocus: state.selectionManager.selectionBehavior === 'replace',\n shouldFocusWrap: props.shouldFocusWrap,\n linkBehavior\n });\n\n let id = useId(props.id);\n listMap.set(state, {id, onAction, linkBehavior, keyboardNavigationBehavior});\n\n let descriptionProps = useHighlightSelectionDescription({\n selectionManager: state.selectionManager,\n hasItemActions: !!onAction\n });\n\n let hasTabbableChild = useHasTabbableChild(ref, {\n isDisabled: state.collection.size !== 0\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n let gridProps: DOMAttributes = mergeProps(\n domProps,\n {\n role: 'grid',\n id,\n 'aria-multiselectable': state.selectionManager.selectionMode === 'multiple' ? 'true' : undefined\n },\n // If collection is empty, make sure the grid is tabbable unless there is a child tabbable element.\n state.collection.size === 0 ? {tabIndex: hasTabbableChild ? -1 : 0} : listProps,\n descriptionProps\n );\n\n if (isVirtualized) {\n gridProps['aria-rowcount'] = state.collection.size;\n gridProps['aria-colcount'] = 1;\n }\n\n useGridSelectionAnnouncement({}, state);\n\n return {\n gridProps\n };\n}\n"],"names":[],"version":3,"file":"useGridList.module.js.map"}
|
|
@@ -47,7 +47,7 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
47
47
|
let { node: node, isVirtualized: isVirtualized, shouldSelectOnPressUp: shouldSelectOnPressUp } = props;
|
|
48
48
|
// let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');
|
|
49
49
|
let { direction: direction } = (0, $911qM$reactariai18n.useLocale)();
|
|
50
|
-
let { onAction: onAction, linkBehavior: linkBehavior } = (0, $7db02799adae605d$exports.listMap).get(state);
|
|
50
|
+
let { onAction: onAction, linkBehavior: linkBehavior, keyboardNavigationBehavior: keyboardNavigationBehavior } = (0, $7db02799adae605d$exports.listMap).get(state);
|
|
51
51
|
let descriptionId = (0, $911qM$reactariautils.useSlotId)();
|
|
52
52
|
// We need to track the key of the item at the time it was last focused so that we force
|
|
53
53
|
// focus to go to the item when the DOM node is reused for a different item in a virtualizer.
|
|
@@ -105,7 +105,7 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
105
105
|
}
|
|
106
106
|
switch(e.key){
|
|
107
107
|
case 'ArrowLeft':
|
|
108
|
-
{
|
|
108
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
109
109
|
// Find the next focusable element within the row.
|
|
110
110
|
let focusable = direction === 'rtl' ? walker.nextNode() : walker.previousNode();
|
|
111
111
|
if (focusable) {
|
|
@@ -135,10 +135,10 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
break;
|
|
139
138
|
}
|
|
139
|
+
break;
|
|
140
140
|
case 'ArrowRight':
|
|
141
|
-
{
|
|
141
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
142
142
|
let focusable = direction === 'rtl' ? walker.previousNode() : walker.nextNode();
|
|
143
143
|
if (focusable) {
|
|
144
144
|
e.preventDefault();
|
|
@@ -166,8 +166,8 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
break;
|
|
170
169
|
}
|
|
170
|
+
break;
|
|
171
171
|
case 'ArrowUp':
|
|
172
172
|
case 'ArrowDown':
|
|
173
173
|
// Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate
|
|
@@ -179,6 +179,17 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
179
179
|
ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
|
|
180
180
|
}
|
|
181
181
|
break;
|
|
182
|
+
case 'Tab':
|
|
183
|
+
if (keyboardNavigationBehavior === 'tab') {
|
|
184
|
+
// If there is another focusable element within this item, stop propagation so the tab key
|
|
185
|
+
// is handled by the browser and not by useSelectableCollection (which would take us out of the list).
|
|
186
|
+
let walker = (0, $911qM$reactariafocus.getFocusableTreeWalker)(ref.current, {
|
|
187
|
+
tabbable: true
|
|
188
|
+
});
|
|
189
|
+
walker.currentNode = document.activeElement;
|
|
190
|
+
let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
191
|
+
if (next) e.stopPropagation();
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
};
|
|
184
195
|
let onFocus = (e)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAgC;QAuD7G,aAA6B;IAtDrD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA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6FAA6F;QAC7F,cAAc,KAAK,SAAS,IAAI;QAChC,iBAAiB,MAAM,gBAAgB,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI;QAChH,iBAAiB,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK;QAChE,mBAAmB,iBAAiB,KAAK,SAAS,GAAG,CAAC,EAAE,CAAA,GAAA,kCAAO,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,cAAc,CAAC,GAAG;QACvG,IAAI,CAAA,GAAA,kCAAO,EAAE,OAAO,KAAK,GAAG;IAC9B;IAEA,IAAI,eACF,QAAQ,CAAC,gBAAgB,GAAG,KAAK,KAAK,GAAG;IAG3C,IAAI,gBAAgB;QAClB,MAAM;QACN,iBAAiB;IACnB;IAEA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,gCAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.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\nimport {chain, getScrollParent, getSyntheticLinkProps, mergeProps, scrollIntoViewport, useSlotId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, RefObject, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\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}\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 = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\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 useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\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 = useRef(null);\n let focus = () => {\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 (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\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 && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\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(node.key);\n }\n return;\n }\n };\n\n let linkProps = itemStates.hasAction ? getSyntheticLinkProps(node.props) : {};\n // TODO: 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 let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file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AAK,GAAG;IAG3C,IAAI,gBAAgB;QAClB,MAAM;QACN,iBAAiB;IACnB;IAEA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,gCAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.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\nimport {chain, getScrollParent, getSyntheticLinkProps, mergeProps, scrollIntoViewport, useSlotId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, RefObject, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\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}\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 = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\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 useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\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 = useRef(null);\n let focus = () => {\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 (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\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 && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (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 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\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(node.key);\n }\n return;\n }\n };\n\n let linkProps = itemStates.hasAction ? getSyntheticLinkProps(node.props) : {};\n // TODO: 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 let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.main.js.map"}
|
package/dist/useGridListItem.mjs
CHANGED
|
@@ -41,7 +41,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
41
41
|
let { node: node, isVirtualized: isVirtualized, shouldSelectOnPressUp: shouldSelectOnPressUp } = props;
|
|
42
42
|
// let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');
|
|
43
43
|
let { direction: direction } = (0, $lxFUG$useLocale)();
|
|
44
|
-
let { onAction: onAction, linkBehavior: linkBehavior } = (0, $ce9b18daab526bbd$export$5b9bb410392e3991).get(state);
|
|
44
|
+
let { onAction: onAction, linkBehavior: linkBehavior, keyboardNavigationBehavior: keyboardNavigationBehavior } = (0, $ce9b18daab526bbd$export$5b9bb410392e3991).get(state);
|
|
45
45
|
let descriptionId = (0, $lxFUG$useSlotId)();
|
|
46
46
|
// We need to track the key of the item at the time it was last focused so that we force
|
|
47
47
|
// focus to go to the item when the DOM node is reused for a different item in a virtualizer.
|
|
@@ -99,7 +99,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
99
99
|
}
|
|
100
100
|
switch(e.key){
|
|
101
101
|
case 'ArrowLeft':
|
|
102
|
-
{
|
|
102
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
103
103
|
// Find the next focusable element within the row.
|
|
104
104
|
let focusable = direction === 'rtl' ? walker.nextNode() : walker.previousNode();
|
|
105
105
|
if (focusable) {
|
|
@@ -129,10 +129,10 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
break;
|
|
133
132
|
}
|
|
133
|
+
break;
|
|
134
134
|
case 'ArrowRight':
|
|
135
|
-
{
|
|
135
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
136
136
|
let focusable = direction === 'rtl' ? walker.previousNode() : walker.nextNode();
|
|
137
137
|
if (focusable) {
|
|
138
138
|
e.preventDefault();
|
|
@@ -160,8 +160,8 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
break;
|
|
164
163
|
}
|
|
164
|
+
break;
|
|
165
165
|
case 'ArrowUp':
|
|
166
166
|
case 'ArrowDown':
|
|
167
167
|
// Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate
|
|
@@ -173,6 +173,17 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
173
173
|
ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
|
|
174
174
|
}
|
|
175
175
|
break;
|
|
176
|
+
case 'Tab':
|
|
177
|
+
if (keyboardNavigationBehavior === 'tab') {
|
|
178
|
+
// If there is another focusable element within this item, stop propagation so the tab key
|
|
179
|
+
// is handled by the browser and not by useSelectableCollection (which would take us out of the list).
|
|
180
|
+
let walker = (0, $lxFUG$getFocusableTreeWalker)(ref.current, {
|
|
181
|
+
tabbable: true
|
|
182
|
+
});
|
|
183
|
+
walker.currentNode = document.activeElement;
|
|
184
|
+
let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
185
|
+
if (next) e.stopPropagation();
|
|
186
|
+
}
|
|
176
187
|
}
|
|
177
188
|
};
|
|
178
189
|
let onFocus = (e)=>{
|
|
@@ -41,7 +41,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
41
41
|
let { node: node, isVirtualized: isVirtualized, shouldSelectOnPressUp: shouldSelectOnPressUp } = props;
|
|
42
42
|
// let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');
|
|
43
43
|
let { direction: direction } = (0, $lxFUG$useLocale)();
|
|
44
|
-
let { onAction: onAction, linkBehavior: linkBehavior } = (0, $ce9b18daab526bbd$export$5b9bb410392e3991).get(state);
|
|
44
|
+
let { onAction: onAction, linkBehavior: linkBehavior, keyboardNavigationBehavior: keyboardNavigationBehavior } = (0, $ce9b18daab526bbd$export$5b9bb410392e3991).get(state);
|
|
45
45
|
let descriptionId = (0, $lxFUG$useSlotId)();
|
|
46
46
|
// We need to track the key of the item at the time it was last focused so that we force
|
|
47
47
|
// focus to go to the item when the DOM node is reused for a different item in a virtualizer.
|
|
@@ -99,7 +99,7 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
99
99
|
}
|
|
100
100
|
switch(e.key){
|
|
101
101
|
case 'ArrowLeft':
|
|
102
|
-
{
|
|
102
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
103
103
|
// Find the next focusable element within the row.
|
|
104
104
|
let focusable = direction === 'rtl' ? walker.nextNode() : walker.previousNode();
|
|
105
105
|
if (focusable) {
|
|
@@ -129,10 +129,10 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
break;
|
|
133
132
|
}
|
|
133
|
+
break;
|
|
134
134
|
case 'ArrowRight':
|
|
135
|
-
{
|
|
135
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
136
136
|
let focusable = direction === 'rtl' ? walker.previousNode() : walker.nextNode();
|
|
137
137
|
if (focusable) {
|
|
138
138
|
e.preventDefault();
|
|
@@ -160,8 +160,8 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
break;
|
|
164
163
|
}
|
|
164
|
+
break;
|
|
165
165
|
case 'ArrowUp':
|
|
166
166
|
case 'ArrowDown':
|
|
167
167
|
// Prevent this event from reaching row children, e.g. menu buttons. We want arrow keys to navigate
|
|
@@ -173,6 +173,17 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
173
173
|
ref.current.parentElement.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent));
|
|
174
174
|
}
|
|
175
175
|
break;
|
|
176
|
+
case 'Tab':
|
|
177
|
+
if (keyboardNavigationBehavior === 'tab') {
|
|
178
|
+
// If there is another focusable element within this item, stop propagation so the tab key
|
|
179
|
+
// is handled by the browser and not by useSelectableCollection (which would take us out of the list).
|
|
180
|
+
let walker = (0, $lxFUG$getFocusableTreeWalker)(ref.current, {
|
|
181
|
+
tabbable: true
|
|
182
|
+
});
|
|
183
|
+
walker.currentNode = document.activeElement;
|
|
184
|
+
let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
185
|
+
if (next) e.stopPropagation();
|
|
186
|
+
}
|
|
176
187
|
}
|
|
177
188
|
};
|
|
178
189
|
let onFocus = (e)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAgC;QAuD7G,aAA6B;IAtDrD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IAC3C,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC5B,IAAI,QAAQ;YAKP;QAJH,yFAAyF;QACzF,kCAAkC;QAClC,IACE,AAAC,eAAe,OAAO,IAAI,QAAQ,KAAK,GAAG,KAAK,eAAe,OAAO,IACtE,GAAC,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,QAAQ,CAAC,SAAS,aAAa,IAE7C,CAAA,GAAA,kBAAU,EAAE,IAAI,OAAO;IAE3B;IAEA,IAAI,mBAAgD,CAAC;IACrD,IAAI;IACJ,IAAI,UAAU,MAA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EA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,iBAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.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\nimport {chain, getScrollParent, getSyntheticLinkProps, mergeProps, scrollIntoViewport, useSlotId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, RefObject, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\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}\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 = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\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 useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\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 = useRef(null);\n let focus = () => {\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 (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n break;\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 && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\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(node.key);\n }\n return;\n }\n };\n\n let linkProps = itemStates.hasAction ? getSyntheticLinkProps(node.props) : {};\n // TODO: 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 let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAgC;QAuD7G,aAA6B;IAtDrD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,yBACb,qBAAqB,EACtB,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IACvE,IAAI,gBAAgB,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AC5E,gEAAgE;IAChE,uBAAuB;IACvB,kBAAkB;IAClB,uEAAuE;IACvE,wBAAwB;IACxB,sEAAsE;IACtE,4BAA4B;IAC5B,QAAQ;IACR,IAAI;IAEJ,IAAI,WAA0B,CAAA,GAAA,iBAAS,EAAE,WAAW,WAAW;QAC7D,MAAM;QACN,kBAAkB;iBAClB;QACA,6FAA6F;QAC7F,cAAc,KAAK,SAAS,IAAI;QAChC,iBAAiB,MAAM,gBAAgB,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI;QAChH,iBAAiB,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK;QAChE,mBAAmB,iBAAiB,KAAK,SAAS,GAAG,CAAC,EAAE,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,cAAc,CAAC,GAAG;QACvG,IAAI,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,GAAG;IAC9B;IAEA,IAAI,eACF,QAAQ,CAAC,gBAAgB,GAAG,KAAK,KAAK,GAAG;IAG3C,IAAI,gBAAgB;QAClB,MAAM;QACN,iBAAiB;IACnB;IAEA,2FAA2F;IAC3F,OAAO;QACL,UAAU;YAAC,GAAG,CAAA,GAAA,iBAAS,EAAE,UAAU,iBAAiB;QAAA;uBACpD;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI;IACJ,IAAI;IACJ,GAAG;QACD,OAAO,OAAO,SAAS;QACvB,IAAI,MACF,OAAO;IAEX,QAAS,MAAM;IACf,OAAO;AACT","sources":["packages/@react-aria/gridlist/src/useGridListItem.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\nimport {chain, getScrollParent, getSyntheticLinkProps, mergeProps, scrollIntoViewport, useSlotId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getLastItem} from '@react-stately/collections';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, RefObject, useRef} from 'react';\nimport {isFocusVisible} from '@react-aria/interactions';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates, useSelectableItem} from '@react-aria/selection';\nimport type {TreeState} from '@react-stately/tree';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaGridListItemOptions {\n /** An object representing the list item. Contains all the relevant information that makes up the list row. */\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}\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 = {\n 'expand': {\n ltr: 'ArrowRight',\n rtl: 'ArrowLeft'\n },\n 'collapse': {\n ltr: 'ArrowLeft',\n rtl: 'ArrowRight'\n }\n};\n\n/**\n * Provides the behavior and accessibility implementation for a row in a grid list.\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 useGridListItem<T>(props: AriaGridListItemOptions, state: ListState<T> | TreeState<T>, ref: RefObject<FocusableElement>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized,\n shouldSelectOnPressUp\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);\n let descriptionId = useSlotId();\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 = useRef(null);\n let focus = () => {\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 (keyWhenFocused.current != null && node.key !== keyWhenFocused.current) ||\n !ref.current?.contains(document.activeElement)\n ) {\n focusSafely(ref.current);\n }\n };\n\n let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n let hasChildRows;\n let hasLink = state.selectionManager.isLink(node.key);\n if (node != null && 'expandedKeys' in state) {\n // TODO: ideally node.hasChildNodes would be a way to tell if a row has child nodes, but the row's contents make it so that value is always\n // true...\n hasChildRows = [...state.collection.getChildren(node.key)].length > 1;\n if (onAction == null && !hasLink && state.selectionManager.selectionMode === 'none' && hasChildRows) {\n onAction = () => state.toggleKey(node.key);\n }\n\n let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined;\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': node.level > 0 ?\n (getLastItem(state.collection.getChildren(node?.parentKey))).index + 1 :\n [...state.collection].filter(row => row.level === 0).at(-1).index + 1\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp,\n onAction: onAction || node.props?.onAction ? chain(node.props?.onAction, onAction ? () => onAction(node.key) : undefined) : undefined,\n focus,\n linkBehavior\n });\n\n let onKeyDown = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element)) {\n return;\n }\n\n let walker = getFocusableTreeWalker(ref.current);\n walker.currentNode = document.activeElement;\n\n if ('expandedKeys' in state && document.activeElement === ref.current) {\n if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && !state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === node.key && hasChildRows && state.expandedKeys.has(node.key)) {\n state.toggleKey(node.key);\n e.stopPropagation();\n return;\n }\n }\n\n switch (e.key) {\n case 'ArrowLeft': {\n if (keyboardNavigationBehavior === 'arrow') {\n // Find the next focusable element within the row.\n let focusable = direction === 'rtl'\n ? walker.nextNode() as FocusableElement\n : walker.previousNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n // If there is no next focusable child, then return focus back to the row\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (keyboardNavigationBehavior === 'arrow') {\n let focusable = direction === 'rtl'\n ? walker.previousNode() as FocusableElement\n : walker.nextNode() as FocusableElement;\n\n if (focusable) {\n e.preventDefault();\n e.stopPropagation();\n focusSafely(focusable);\n scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});\n } else {\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'ltr') {\n focusSafely(ref.current);\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n } else {\n walker.currentNode = ref.current;\n let lastElement = last(walker);\n if (lastElement) {\n focusSafely(lastElement);\n scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});\n }\n }\n }\n }\n break;\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 && ref.current.contains(e.target as Element)) {\n e.stopPropagation();\n e.preventDefault();\n ref.current.parentElement.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n );\n }\n break;\n case 'Tab': {\n if (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 let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n walker.currentNode = document.activeElement;\n let next = e.shiftKey ? walker.previousNode() : walker.nextNode();\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let onFocus = (e) => {\n keyWhenFocused.current = node.key;\n if (e.target !== ref.current) {\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(node.key);\n }\n return;\n }\n };\n\n let linkProps = itemStates.hasAction ? getSyntheticLinkProps(node.props) : {};\n // TODO: 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 let rowProps: DOMAttributes = mergeProps(itemProps, linkProps, {\n role: 'row',\n onKeyDownCapture: onKeyDown,\n onFocus,\n // 'aria-label': [(node.textValue || undefined), rowAnnouncement].filter(Boolean).join(', '),\n 'aria-label': node.textValue || undefined,\n 'aria-selected': state.selectionManager.canSelectItem(node.key) ? state.selectionManager.isSelected(node.key) : undefined,\n 'aria-disabled': state.selectionManager.isDisabled(node.key) || undefined,\n 'aria-labelledby': descriptionId && node.textValue ? `${getRowId(state, node.key)} ${descriptionId}` : undefined,\n id: getRowId(state, node.key)\n });\n\n if (isVirtualized) {\n rowProps['aria-rowindex'] = node.index + 1;\n }\n\n let gridCellProps = {\n role: 'gridcell',\n 'aria-colindex': 1\n };\n\n // TODO: should isExpanded and hasChildRows be a item state that gets returned by the hook?\n return {\n rowProps: {...mergeProps(rowProps, treeGridRowProps)},\n gridCellProps,\n descriptionProps: {\n id: descriptionId\n },\n ...itemStates\n };\n}\n\nfunction last(walker: TreeWalker) {\n let next: FocusableElement;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.module.js.map"}
|
package/dist/utils.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;IACvD,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAQ,GAAG,CAAC;IACvB,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,0CAAa,KAAK,CAAC;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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\nimport {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state);\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;CAUC,GAcM,MAAM,4CAAU,IAAI;AAEpB,SAAS,0CAAY,KAAmB,EAAE,GAAQ;IACvD,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAQ,GAAG,CAAC;IACvB,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,0CAAa,KAAK,CAAC;AACrC;AAEO,SAAS,0CAAa,GAAQ;IACnC,IAAI,OAAO,QAAQ,UACjB,OAAO,IAAI,OAAO,CAAC,QAAQ;IAG7B,OAAO,KAAK;AACd","sources":["packages/@react-aria/gridlist/src/utils.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\nimport {Key} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\n\ninterface ListMapShared {\n id: string,\n onAction: (key: Key) => void,\n linkBehavior?: 'action' | 'selection' | 'override',\n keyboardNavigationBehavior: 'arrow' | 'tab'\n}\n\n// Used to share:\n// id of the list and onAction between useList, useListItem, and useListSelectionCheckbox\nexport const listMap = new WeakMap<ListState<unknown>, ListMapShared>();\n\nexport function getRowId<T>(state: ListState<T>, key: Key) {\n let {id} = listMap.get(state);\n if (!id) {\n throw new Error('Unknown list');\n }\n\n return `${id}-${normalizeKey(key)}`;\n}\n\nexport function normalizeKey(key: Key): string {\n if (typeof key === 'string') {\n return key.replace(/\\s*/g, '');\n }\n\n return '' + key;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/gridlist",
|
|
3
|
-
"version": "3.8.2-nightly.
|
|
3
|
+
"version": "3.8.2-nightly.4664+10bac541a",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "3.0.0-nightly.
|
|
26
|
-
"@react-aria/grid": "3.9.2-nightly.
|
|
27
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
28
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
29
|
-
"@react-aria/selection": "3.0.0-nightly.
|
|
30
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
31
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
32
|
-
"@react-stately/list": "3.10.6-nightly.
|
|
33
|
-
"@react-stately/tree": "3.0.0-nightly.
|
|
34
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-aria/focus": "3.0.0-nightly.2952+10bac541a",
|
|
26
|
+
"@react-aria/grid": "3.9.2-nightly.4664+10bac541a",
|
|
27
|
+
"@react-aria/i18n": "3.0.0-nightly.2952+10bac541a",
|
|
28
|
+
"@react-aria/interactions": "3.0.0-nightly.2952+10bac541a",
|
|
29
|
+
"@react-aria/selection": "3.0.0-nightly.2952+10bac541a",
|
|
30
|
+
"@react-aria/utils": "3.0.0-nightly.2952+10bac541a",
|
|
31
|
+
"@react-stately/collections": "3.0.0-nightly.2952+10bac541a",
|
|
32
|
+
"@react-stately/list": "3.10.6-nightly.4664+10bac541a",
|
|
33
|
+
"@react-stately/tree": "3.0.0-nightly.2952+10bac541a",
|
|
34
|
+
"@react-types/shared": "3.0.0-nightly.2952+10bac541a",
|
|
35
35
|
"@swc/helpers": "^0.5.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "10bac541a2a5c666b443fe70f313455a405a5c77"
|
|
45
45
|
}
|
package/src/useGridList.ts
CHANGED
|
@@ -38,7 +38,14 @@ export interface GridListProps<T> extends CollectionBase<T>, MultipleSelection {
|
|
|
38
38
|
disabledBehavior?: DisabledBehavior
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLabelingProps {
|
|
41
|
+
export interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLabelingProps {
|
|
42
|
+
/**
|
|
43
|
+
* Whether keyboard navigation to focusable elements within grid list items is
|
|
44
|
+
* via the left/right arrow keys or the tab key.
|
|
45
|
+
* @default 'arrow'
|
|
46
|
+
*/
|
|
47
|
+
keyboardNavigationBehavior?: 'arrow' | 'tab'
|
|
48
|
+
}
|
|
42
49
|
|
|
43
50
|
export interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {
|
|
44
51
|
/** Whether the list uses virtual scrolling. */
|
|
@@ -80,7 +87,8 @@ export function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T
|
|
|
80
87
|
isVirtualized,
|
|
81
88
|
keyboardDelegate,
|
|
82
89
|
onAction,
|
|
83
|
-
linkBehavior = 'action'
|
|
90
|
+
linkBehavior = 'action',
|
|
91
|
+
keyboardNavigationBehavior = 'arrow'
|
|
84
92
|
} = props;
|
|
85
93
|
|
|
86
94
|
if (!props['aria-label'] && !props['aria-labelledby']) {
|
|
@@ -100,7 +108,7 @@ export function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T
|
|
|
100
108
|
});
|
|
101
109
|
|
|
102
110
|
let id = useId(props.id);
|
|
103
|
-
listMap.set(state, {id, onAction, linkBehavior});
|
|
111
|
+
listMap.set(state, {id, onAction, linkBehavior, keyboardNavigationBehavior});
|
|
104
112
|
|
|
105
113
|
let descriptionProps = useHighlightSelectionDescription({
|
|
106
114
|
selectionManager: state.selectionManager,
|
package/src/useGridListItem.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
|
|
|
67
67
|
|
|
68
68
|
// let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');
|
|
69
69
|
let {direction} = useLocale();
|
|
70
|
-
let {onAction, linkBehavior} = listMap.get(state);
|
|
70
|
+
let {onAction, linkBehavior, keyboardNavigationBehavior} = listMap.get(state);
|
|
71
71
|
let descriptionId = useSlotId();
|
|
72
72
|
|
|
73
73
|
// We need to track the key of the item at the time it was last focused so that we force
|
|
@@ -139,56 +139,60 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
|
|
|
139
139
|
|
|
140
140
|
switch (e.key) {
|
|
141
141
|
case 'ArrowLeft': {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
143
|
+
// Find the next focusable element within the row.
|
|
144
|
+
let focusable = direction === 'rtl'
|
|
145
|
+
? walker.nextNode() as FocusableElement
|
|
146
|
+
: walker.previousNode() as FocusableElement;
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else {
|
|
153
|
-
// If there is no next focusable child, then return focus back to the row
|
|
154
|
-
e.preventDefault();
|
|
155
|
-
e.stopPropagation();
|
|
156
|
-
if (direction === 'rtl') {
|
|
157
|
-
focusSafely(ref.current);
|
|
158
|
-
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
148
|
+
if (focusable) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
e.stopPropagation();
|
|
151
|
+
focusSafely(focusable);
|
|
152
|
+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
159
153
|
} else {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
154
|
+
// If there is no next focusable child, then return focus back to the row
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
e.stopPropagation();
|
|
157
|
+
if (direction === 'rtl') {
|
|
158
|
+
focusSafely(ref.current);
|
|
159
|
+
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
160
|
+
} else {
|
|
161
|
+
walker.currentNode = ref.current;
|
|
162
|
+
let lastElement = last(walker);
|
|
163
|
+
if (lastElement) {
|
|
164
|
+
focusSafely(lastElement);
|
|
165
|
+
scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});
|
|
166
|
+
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
170
|
break;
|
|
169
171
|
}
|
|
170
172
|
case 'ArrowRight': {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
if (keyboardNavigationBehavior === 'arrow') {
|
|
174
|
+
let focusable = direction === 'rtl'
|
|
175
|
+
? walker.previousNode() as FocusableElement
|
|
176
|
+
: walker.nextNode() as FocusableElement;
|
|
174
177
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
} else {
|
|
181
|
-
e.preventDefault();
|
|
182
|
-
e.stopPropagation();
|
|
183
|
-
if (direction === 'ltr') {
|
|
184
|
-
focusSafely(ref.current);
|
|
185
|
-
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
178
|
+
if (focusable) {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
e.stopPropagation();
|
|
181
|
+
focusSafely(focusable);
|
|
182
|
+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
|
|
186
183
|
} else {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
focusSafely(
|
|
191
|
-
scrollIntoViewport(
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
e.stopPropagation();
|
|
186
|
+
if (direction === 'ltr') {
|
|
187
|
+
focusSafely(ref.current);
|
|
188
|
+
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
|
|
189
|
+
} else {
|
|
190
|
+
walker.currentNode = ref.current;
|
|
191
|
+
let lastElement = last(walker);
|
|
192
|
+
if (lastElement) {
|
|
193
|
+
focusSafely(lastElement);
|
|
194
|
+
scrollIntoViewport(lastElement, {containingElement: getScrollParent(ref.current)});
|
|
195
|
+
}
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
}
|
|
@@ -207,6 +211,18 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
|
|
|
207
211
|
);
|
|
208
212
|
}
|
|
209
213
|
break;
|
|
214
|
+
case 'Tab': {
|
|
215
|
+
if (keyboardNavigationBehavior === 'tab') {
|
|
216
|
+
// If there is another focusable element within this item, stop propagation so the tab key
|
|
217
|
+
// is handled by the browser and not by useSelectableCollection (which would take us out of the list).
|
|
218
|
+
let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
|
|
219
|
+
walker.currentNode = document.activeElement;
|
|
220
|
+
let next = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
221
|
+
if (next) {
|
|
222
|
+
e.stopPropagation();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
210
226
|
}
|
|
211
227
|
};
|
|
212
228
|
|
package/src/utils.ts
CHANGED
|
@@ -16,7 +16,8 @@ import type {ListState} from '@react-stately/list';
|
|
|
16
16
|
interface ListMapShared {
|
|
17
17
|
id: string,
|
|
18
18
|
onAction: (key: Key) => void,
|
|
19
|
-
linkBehavior?: 'action' | 'selection' | 'override'
|
|
19
|
+
linkBehavior?: 'action' | 'selection' | 'override',
|
|
20
|
+
keyboardNavigationBehavior: 'arrow' | 'tab'
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// Used to share:
|