@react-aria/gridlist 3.13.3 → 3.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +3 -1
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useGridListItem.main.js +13 -1
- package/dist/useGridListItem.main.js.map +1 -1
- package/dist/useGridListItem.mjs +13 -1
- package/dist/useGridListItem.module.js +13 -1
- package/dist/useGridListItem.module.js.map +1 -1
- package/dist/useGridListSection.main.js +43 -0
- package/dist/useGridListSection.main.js.map +1 -0
- package/dist/useGridListSection.mjs +38 -0
- package/dist/useGridListSection.module.js +38 -0
- package/dist/useGridListSection.module.js.map +1 -0
- package/package.json +11 -11
- package/src/index.ts +1 -0
- package/src/useGridListItem.ts +4 -1
- package/src/useGridListSection.ts +60 -0
package/dist/import.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {useGridList as $f47efb0c3a859cf2$export$664f9155035607eb} from "./useGridList.mjs";
|
|
2
2
|
import {useGridListItem as $4e8b0456ef72939f$export$9610e69494fadfd2} from "./useGridListItem.mjs";
|
|
3
3
|
import {useGridListSelectionCheckbox as $e52ffc04a4adbd52$export$e29f2573fabbf7b9} from "./useGridListSelectionCheckbox.mjs";
|
|
4
|
+
import {useGridListSection as $d6848ac28ff5c637$export$8a024deed275af3f} from "./useGridListSection.mjs";
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* Copyright 2022 Adobe. All rights reserved.
|
|
@@ -17,5 +18,6 @@ import {useGridListSelectionCheckbox as $e52ffc04a4adbd52$export$e29f2573fabbf7b
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export {$f47efb0c3a859cf2$export$664f9155035607eb as useGridList, $4e8b0456ef72939f$export$9610e69494fadfd2 as useGridListItem, $e52ffc04a4adbd52$export$e29f2573fabbf7b9 as useGridListSelectionCheckbox, $d6848ac28ff5c637$export$8a024deed275af3f as useGridListSection};
|
|
21
23
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var $acf209ae814f1c93$exports = require("./useGridList.main.js");
|
|
2
2
|
var $f7116f5928c03f32$exports = require("./useGridListItem.main.js");
|
|
3
3
|
var $43131ea217bc2ad3$exports = require("./useGridListSelectionCheckbox.main.js");
|
|
4
|
+
var $6e114d409ef8350d$exports = require("./useGridListSection.main.js");
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
function $parcel$export(e, n, v, s) {
|
|
@@ -10,6 +11,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
10
11
|
$parcel$export(module.exports, "useGridList", () => $acf209ae814f1c93$exports.useGridList);
|
|
11
12
|
$parcel$export(module.exports, "useGridListItem", () => $f7116f5928c03f32$exports.useGridListItem);
|
|
12
13
|
$parcel$export(module.exports, "useGridListSelectionCheckbox", () => $43131ea217bc2ad3$exports.useGridListSelectionCheckbox);
|
|
14
|
+
$parcel$export(module.exports, "useGridListSection", () => $6e114d409ef8350d$exports.useGridListSection);
|
|
13
15
|
/*
|
|
14
16
|
* Copyright 2022 Adobe. All rights reserved.
|
|
15
17
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -25,4 +27,5 @@ $parcel$export(module.exports, "useGridListSelectionCheckbox", () => $43131ea217
|
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
|
|
30
|
+
|
|
28
31
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/gridlist/src/index.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\nexport {useGridList} from './useGridList';\nexport {useGridListItem} from './useGridListItem';\nexport {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';\nexport {useGridListSection} from './useGridListSection';\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":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {useGridList as $f47efb0c3a859cf2$export$664f9155035607eb} from "./useGridList.module.js";
|
|
2
2
|
import {useGridListItem as $4e8b0456ef72939f$export$9610e69494fadfd2} from "./useGridListItem.module.js";
|
|
3
3
|
import {useGridListSelectionCheckbox as $e52ffc04a4adbd52$export$e29f2573fabbf7b9} from "./useGridListSelectionCheckbox.module.js";
|
|
4
|
+
import {useGridListSection as $d6848ac28ff5c637$export$8a024deed275af3f} from "./useGridListSection.module.js";
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* Copyright 2022 Adobe. All rights reserved.
|
|
@@ -17,5 +18,6 @@ import {useGridListSelectionCheckbox as $e52ffc04a4adbd52$export$e29f2573fabbf7b
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export {$f47efb0c3a859cf2$export$664f9155035607eb as useGridList, $4e8b0456ef72939f$export$9610e69494fadfd2 as useGridListItem, $e52ffc04a4adbd52$export$e29f2573fabbf7b9 as useGridListSelectionCheckbox, $d6848ac28ff5c637$export$8a024deed275af3f as useGridListSection};
|
|
21
23
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/gridlist/src/index.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\nexport {useGridList} from './useGridList';\nexport {useGridListItem} from './useGridListItem';\nexport {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';\nexport {useGridListSection} from './useGridListSection';\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":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -112,6 +112,24 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
|
|
|
112
112
|
* @param state - State of the list, as returned by `useListState`.
|
|
113
113
|
*/
|
|
114
114
|
export function useGridListSelectionCheckbox<T>(props: AriaGridSelectionCheckboxProps, state: ListState<T>): GridSelectionCheckboxAria;
|
|
115
|
+
interface AriaGridListSectionProps {
|
|
116
|
+
/** An accessibility label for the section. Required if `heading` is not present. */
|
|
117
|
+
'aria-label'?: string;
|
|
118
|
+
}
|
|
119
|
+
interface GridListSectionAria {
|
|
120
|
+
/** Props for the wrapper list item. */
|
|
121
|
+
rowProps: DOMAttributes;
|
|
122
|
+
/** Props for the heading element, if any. */
|
|
123
|
+
rowHeaderProps: DOMAttributes;
|
|
124
|
+
/** Props for the grid's row group element. */
|
|
125
|
+
rowGroupProps: DOMAttributes;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Provides the behavior and accessibility implementation for a section in a grid list.
|
|
129
|
+
* See `useGridList` for more details about grid list.
|
|
130
|
+
* @param props - Props for the section.
|
|
131
|
+
*/
|
|
132
|
+
export function useGridListSection<T>(props: AriaGridListSectionProps, state: ListState<T>, ref: RefObject<HTMLElement | null>): GridListSectionAria;
|
|
115
133
|
export type { AriaGridSelectionCheckboxProps, GridSelectionCheckboxAria } from '@react-aria/grid';
|
|
116
134
|
|
|
117
135
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;ACgCA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,iBAAiB;IAC5E,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,mCAAmC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB;IACzF;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7C;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAA;CAC9C;AAED,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC;IACpF,+CAA+C;IAC/C,aAAa,CAAC,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AC,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;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,GAAG,IAAI,CAAC,GAAG,gBAAgB,CA6PhK;ACzSD;;;;GAIG;AACH,6CAA6C,CAAC,EAAE,KAAK,EAAE,8BAA8B,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,yBAAyB,CAUrI;ACfD;IACE,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;IACE,uCAAuC;IACvC,QAAQ,EAAE,aAAa,CAAC;IAExB,6CAA6C;IAC7C,cAAc,EAAE,aAAa,CAAC;IAE9B,8CAA8C;IAC9C,aAAa,EAAE,aAAa,CAAA;CAC7B;AAED;;;;GAIG;AAEH,mCAAmC,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,mBAAmB,CAqBnJ;ACxCD,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/useGridListSection.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,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';\nexport {useGridListSection} from './useGridListSection';\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"}
|
|
@@ -246,7 +246,19 @@ function $f7116f5928c03f32$export$9610e69494fadfd2(props, state, ref) {
|
|
|
246
246
|
'aria-labelledby': descriptionId && node.textValue ? `${(0, $7db02799adae605d$exports.getRowId)(state, node.key)} ${descriptionId}` : undefined,
|
|
247
247
|
id: (0, $7db02799adae605d$exports.getRowId)(state, node.key)
|
|
248
248
|
});
|
|
249
|
-
if (isVirtualized)
|
|
249
|
+
if (isVirtualized) {
|
|
250
|
+
let { collection: collection } = state;
|
|
251
|
+
let nodes = [
|
|
252
|
+
...collection
|
|
253
|
+
];
|
|
254
|
+
// TODO: refactor ListCollection to store an absolute index of a node's position?
|
|
255
|
+
rowProps['aria-rowindex'] = nodes.find((node)=>node.type === 'section') ? [
|
|
256
|
+
...collection.getKeys()
|
|
257
|
+
].filter((key)=>{
|
|
258
|
+
var _collection_getItem;
|
|
259
|
+
return ((_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.type) !== 'section';
|
|
260
|
+
}).findIndex((key)=>key === node.key) + 1 : node.index + 1;
|
|
261
|
+
}
|
|
250
262
|
let gridCellProps = {
|
|
251
263
|
role: 'gridcell',
|
|
252
264
|
'aria-colindex': 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAiCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAmEpH,aAA6B;IAlErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,EACd,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,yBAAE,qBAAqB,EAAC,GAAG,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC;IAC9F,IAAI,gBAAgB,CAAA,GAAA,+BAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,mBAAK,EAAc;IACxC,IAAI,QAAQ;YAMP;QALH,yFAAyF;QACzF,kCAAkC;QAClC,IACE,IAAI,OAAO,KAAK,QACf,CAAA,AAAC,eAAe,OAAO,IAAI,QAAQ,KAAK,GAAG,KAAK,eAAe,OAAO,IACvE,GAAC,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,QAAQ,CAAC,SAAS,aAAa,EAAA,GAE7C,CAAA,GAAA,iCAAU,EAAE,IAAI,OAAO;IAE3B;IAEA,I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AChB,IAAI;QACN;QACA,GAAG,UAAU;IACf;AACF;AAEA,SAAS,2BAAK,MAAkB;IAC9B,IAAI,OAAgC;IACpC,IAAI,OAAgC;IACpC,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, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, 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 /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: 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 | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} = 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<Key | null>(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 ref.current !== null &&\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 = props.hasChildItems;\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 let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\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 let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = [...siblings].filter(row => row.type === 'item').length;\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || 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 onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\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 }\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 onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n switch (e.key) {\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\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\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,\n 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 | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAiCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAmEpH,aAA6B;IAlErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,EACd,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,yBAAE,qBAAqB,EAAC,GAAG,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC;IAC9F,IAAI,gBAAgB,CAAA,GAAA,+BAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,mBAAK,EAAc;IACxC,IAAI,QAAQ;YAMP;QALH,yFAAyF;QACzF,kCAAkC;QAClC,IACE,IAAI,OAAO,KAAK,QACf,CAAA,AAAC,eAAe,OAAO,IAAI,QAAQ,KAAK,GAAG,KAAK,eAAe,OAAO,IACvE,GAAC,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,QAAQ,CAAC,SAAS,aAAa,EAAA,GAE7C,CAAA,GAAA,iCAAU,EAAE,IAAI,OAAO;IAE3B;IAEA,IAAI,mBAAgD,CAAC;IACrD,IAAI,eAAe,MAAM,aAAa;IACtC,IAAI,UAAU,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,GAAG;IACpD,IAAI,QAAQ,QAAQ,kBAAkB,OAAO;YAG5B,+BAAA;QAFf,2IAA2I;QAC3I,UAAU;QACV,IAAI,YAAW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N,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,OAAgC;IACpC,IAAI,OAAgC;IACpC,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, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, 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 /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: 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 | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} = 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<Key | null>(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 ref.current !== null &&\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 = props.hasChildItems;\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 let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\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 let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = [...siblings].filter(row => row.type === 'item').length;\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || 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 onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\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 }\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 onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n switch (e.key) {\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\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\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,\n 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 let {collection} = state;\n let nodes = [...collection];\n // TODO: refactor ListCollection to store an absolute index of a node's position?\n rowProps['aria-rowindex'] = nodes.find(node => node.type === 'section') ? [...collection.getKeys()].filter((key) => collection.getItem(key)?.type !== 'section').findIndex((key) => key === node.key) + 1 : 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 | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\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
|
@@ -240,7 +240,19 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
240
240
|
'aria-labelledby': descriptionId && node.textValue ? `${(0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)} ${descriptionId}` : undefined,
|
|
241
241
|
id: (0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)
|
|
242
242
|
});
|
|
243
|
-
if (isVirtualized)
|
|
243
|
+
if (isVirtualized) {
|
|
244
|
+
let { collection: collection } = state;
|
|
245
|
+
let nodes = [
|
|
246
|
+
...collection
|
|
247
|
+
];
|
|
248
|
+
// TODO: refactor ListCollection to store an absolute index of a node's position?
|
|
249
|
+
rowProps['aria-rowindex'] = nodes.find((node)=>node.type === 'section') ? [
|
|
250
|
+
...collection.getKeys()
|
|
251
|
+
].filter((key)=>{
|
|
252
|
+
var _collection_getItem;
|
|
253
|
+
return ((_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.type) !== 'section';
|
|
254
|
+
}).findIndex((key)=>key === node.key) + 1 : node.index + 1;
|
|
255
|
+
}
|
|
244
256
|
let gridCellProps = {
|
|
245
257
|
role: 'gridcell',
|
|
246
258
|
'aria-colindex': 1
|
|
@@ -240,7 +240,19 @@ function $4e8b0456ef72939f$export$9610e69494fadfd2(props, state, ref) {
|
|
|
240
240
|
'aria-labelledby': descriptionId && node.textValue ? `${(0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)} ${descriptionId}` : undefined,
|
|
241
241
|
id: (0, $ce9b18daab526bbd$export$f45c25170b9a99c2)(state, node.key)
|
|
242
242
|
});
|
|
243
|
-
if (isVirtualized)
|
|
243
|
+
if (isVirtualized) {
|
|
244
|
+
let { collection: collection } = state;
|
|
245
|
+
let nodes = [
|
|
246
|
+
...collection
|
|
247
|
+
];
|
|
248
|
+
// TODO: refactor ListCollection to store an absolute index of a node's position?
|
|
249
|
+
rowProps['aria-rowindex'] = nodes.find((node)=>node.type === 'section') ? [
|
|
250
|
+
...collection.getKeys()
|
|
251
|
+
].filter((key)=>{
|
|
252
|
+
var _collection_getItem;
|
|
253
|
+
return ((_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.type) !== 'section';
|
|
254
|
+
}).findIndex((key)=>key === node.key) + 1 : node.index + 1;
|
|
255
|
+
}
|
|
244
256
|
let gridCellProps = {
|
|
245
257
|
role: 'gridcell',
|
|
246
258
|
'aria-colindex': 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAiCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAmEpH,aAA6B;IAlErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,EACd,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,yBAAE,qBAAqB,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG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;QAChE,mBAAmB,iBAAiB,KAAK,SAAS,GAAG,GAAG,CAAA,GAAA,yCAAO,EAAE,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,eAAe,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,OAAgC;IACpC,IAAI,OAAgC;IACpC,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, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, 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 /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: 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 | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} = 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<Key | null>(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 ref.current !== null &&\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 = props.hasChildItems;\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 let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\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 let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = [...siblings].filter(row => row.type === 'item').length;\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || 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 onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\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 }\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 onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n switch (e.key) {\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\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\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,\n 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 | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\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;;;;;;;AAiCD,MAAM,uCAAiB;IACrB,UAAU;QACR,KAAK;QACL,KAAK;IACP;IACA,YAAY;QACV,KAAK;QACL,KAAK;IACP;AACF;AAQO,SAAS,0CAAmB,KAA8B,EAAE,KAAkC,EAAE,GAAuC;QAmEpH,aAA6B;IAlErD,+EAA+E;IAC/E,IAAI,QACF,IAAI,iBACJ,aAAa,EACd,GAAG;IAEJ,2FAA2F;IAC3F,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,YAAC,QAAQ,gBAAE,YAAY,8BAAE,0BAA0B,yBAAE,qBAAqB,EAAC,GAAG,CAAA,GAAA,yCAAM,EAAE,GAAG,CAAC;IAC9F,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAE5B,wFAAwF;IACxF,6FAA6F;IAC7F,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAc;IACxC,IAAI,QAAQ;YAMP;QALH,yFAAyF;QACzF,kCAAkC;QAClC,IACE,IAAI,OAAO,KAAK,QACf,CAAA,AA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UAAU,EAAC,GAAG;QACnB,IAAI,QAAQ;eAAI;SAAW;QAC3B,iFAAiF;QACjF,QAAQ,CAAC,gBAAgB,GAAG,MAAM,IAAI,CAAC,CAAA,OAAQ,KAAK,IAAI,KAAK,aAAa;eAAI,WAAW,OAAO;SAAG,CAAC,MAAM,CAAC,CAAC;gBAAQ;mBAAA,EAAA,sBAAA,WAAW,OAAO,CAAC,kBAAnB,0CAAA,oBAAyB,IAAI,MAAK;WAAW,SAAS,CAAC,CAAC,MAAQ,QAAQ,KAAK,GAAG,IAAI,IAAI,KAAK,KAAK,GAAG;IAC3N;IAEA,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,OAAgC;IACpC,IAAI,OAAgC;IACpC,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, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {getRowId, listMap} from './utils';\nimport {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, 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 /** Whether this item has children, even if not loaded yet. */\n hasChildItems?: 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 | null>): GridListItemAria {\n // Copied from useGridCell + some modifications to make it not so grid specific\n let {\n node,\n isVirtualized\n } = props;\n\n // let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/gridlist');\n let {direction} = useLocale();\n let {onAction, linkBehavior, keyboardNavigationBehavior, shouldSelectOnPressUp} = 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<Key | null>(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 ref.current !== null &&\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 = props.hasChildItems;\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 let children = state.collection.getChildren?.(node.key);\n hasChildRows = hasChildRows || [...(children ?? [])].length > 1;\n\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 let setSize = 1;\n if (node.level > 0 && node?.parentKey != null) {\n let parent = state.collection.getItem(node.parentKey);\n if (parent) {\n // siblings must exist because our original node exists\n let siblings = state.collection.getChildren?.(parent.key)!;\n setSize = [...siblings].filter(row => row.type === 'item').length;\n }\n } else {\n setSize = [...state.collection].filter(row => row.level === 0 && row.type === 'item').length;\n }\n\n treeGridRowProps = {\n 'aria-expanded': isExpanded,\n 'aria-level': node.level + 1,\n 'aria-posinset': node?.index + 1,\n 'aria-setsize': setSize\n };\n }\n\n let {itemProps, ...itemStates} = useSelectableItem({\n selectionManager: state.selectionManager,\n key: node.key,\n ref,\n isVirtualized,\n shouldSelectOnPressUp: props.shouldSelectOnPressUp || 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 onKeyDownCapture = (e: ReactKeyboardEvent) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\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 }\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 onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target as Element) || !ref.current || !document.activeElement) {\n return;\n }\n\n switch (e.key) {\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\n if (next) {\n e.stopPropagation();\n }\n }\n }\n }\n };\n\n let syntheticLinkProps = useSyntheticLinkProps(node.props);\n let linkProps = itemStates.hasAction ? syntheticLinkProps : {};\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,\n 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 let {collection} = state;\n let nodes = [...collection];\n // TODO: refactor ListCollection to store an absolute index of a node's position?\n rowProps['aria-rowindex'] = nodes.find(node => node.type === 'section') ? [...collection.getKeys()].filter((key) => collection.getItem(key)?.type !== 'section').findIndex((key) => key === node.key) + 1 : 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 | null = null;\n let last: FocusableElement | null = null;\n do {\n last = walker.lastChild() as FocusableElement | null;\n if (last) {\n next = last;\n }\n } while (last);\n return next;\n}\n"],"names":[],"version":3,"file":"useGridListItem.module.js.map"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var $4IyTr$reactariautils = require("@react-aria/utils");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "useGridListSection", () => $6e114d409ef8350d$export$8a024deed275af3f);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
function $6e114d409ef8350d$export$8a024deed275af3f(props, state, ref) {
|
|
21
|
+
let { 'aria-label': ariaLabel } = props;
|
|
22
|
+
let headingId = (0, $4IyTr$reactariautils.useSlotId)();
|
|
23
|
+
let labelProps = (0, $4IyTr$reactariautils.useLabels)({
|
|
24
|
+
'aria-label': ariaLabel,
|
|
25
|
+
'aria-labelledby': headingId
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
rowProps: {
|
|
29
|
+
role: 'row'
|
|
30
|
+
},
|
|
31
|
+
rowHeaderProps: {
|
|
32
|
+
id: headingId,
|
|
33
|
+
role: 'rowheader'
|
|
34
|
+
},
|
|
35
|
+
rowGroupProps: {
|
|
36
|
+
role: 'rowgroup',
|
|
37
|
+
...labelProps
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=useGridListSection.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA4BM,SAAS,0CAAsB,KAA+B,EAAE,KAAmB,EAAE,GAAkC;IAC5H,IAAI,EAAC,cAAc,SAAS,EAAC,GAAG;IAChC,IAAI,YAAY,CAAA,GAAA,+BAAQ;IACxB,IAAI,aAAa,CAAA,GAAA,+BAAQ,EAAE;QACzB,cAAc;QACd,mBAAmB;IACrB;IAEA,OAAO;QACL,UAAU;YACR,MAAM;QACR;QACA,gBAAgB;YACd,IAAI;YACJ,MAAM;QACR;QACA,eAAe;YACb,MAAM;YACN,GAAG,UAAU;QACf;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSection.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 {DOMAttributes, RefObject} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\nimport {useLabels, useSlotId} from '@react-aria/utils';\n\nexport interface AriaGridListSectionProps {\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\nexport interface GridListSectionAria {\n /** Props for the wrapper list item. */\n rowProps: DOMAttributes,\n\n /** Props for the heading element, if any. */\n rowHeaderProps: DOMAttributes,\n\n /** Props for the grid's row group element. */\n rowGroupProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a grid list.\n * See `useGridList` for more details about grid list.\n * @param props - Props for the section.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useGridListSection<T>(props: AriaGridListSectionProps, state: ListState<T>, ref: RefObject<HTMLElement | null>): GridListSectionAria {\n let {'aria-label': ariaLabel} = props;\n let headingId = useSlotId();\n let labelProps = useLabels({\n 'aria-label': ariaLabel,\n 'aria-labelledby': headingId\n });\n\n return {\n rowProps: {\n role: 'row'\n },\n rowHeaderProps: {\n id: headingId,\n role: 'rowheader'\n },\n rowGroupProps: {\n role: 'rowgroup',\n ...labelProps\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSection.main.js.map"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {useSlotId as $6QchP$useSlotId, useLabels as $6QchP$useLabels} from "@react-aria/utils";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
function $d6848ac28ff5c637$export$8a024deed275af3f(props, state, ref) {
|
|
15
|
+
let { 'aria-label': ariaLabel } = props;
|
|
16
|
+
let headingId = (0, $6QchP$useSlotId)();
|
|
17
|
+
let labelProps = (0, $6QchP$useLabels)({
|
|
18
|
+
'aria-label': ariaLabel,
|
|
19
|
+
'aria-labelledby': headingId
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
rowProps: {
|
|
23
|
+
role: 'row'
|
|
24
|
+
},
|
|
25
|
+
rowHeaderProps: {
|
|
26
|
+
id: headingId,
|
|
27
|
+
role: 'rowheader'
|
|
28
|
+
},
|
|
29
|
+
rowGroupProps: {
|
|
30
|
+
role: 'rowgroup',
|
|
31
|
+
...labelProps
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export {$d6848ac28ff5c637$export$8a024deed275af3f as useGridListSection};
|
|
38
|
+
//# sourceMappingURL=useGridListSection.module.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {useSlotId as $6QchP$useSlotId, useLabels as $6QchP$useLabels} from "@react-aria/utils";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
function $d6848ac28ff5c637$export$8a024deed275af3f(props, state, ref) {
|
|
15
|
+
let { 'aria-label': ariaLabel } = props;
|
|
16
|
+
let headingId = (0, $6QchP$useSlotId)();
|
|
17
|
+
let labelProps = (0, $6QchP$useLabels)({
|
|
18
|
+
'aria-label': ariaLabel,
|
|
19
|
+
'aria-labelledby': headingId
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
rowProps: {
|
|
23
|
+
role: 'row'
|
|
24
|
+
},
|
|
25
|
+
rowHeaderProps: {
|
|
26
|
+
id: headingId,
|
|
27
|
+
role: 'rowheader'
|
|
28
|
+
},
|
|
29
|
+
rowGroupProps: {
|
|
30
|
+
role: 'rowgroup',
|
|
31
|
+
...labelProps
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export {$d6848ac28ff5c637$export$8a024deed275af3f as useGridListSection};
|
|
38
|
+
//# sourceMappingURL=useGridListSection.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA4BM,SAAS,0CAAsB,KAA+B,EAAE,KAAmB,EAAE,GAAkC;IAC5H,IAAI,EAAC,cAAc,SAAS,EAAC,GAAG;IAChC,IAAI,YAAY,CAAA,GAAA,gBAAQ;IACxB,IAAI,aAAa,CAAA,GAAA,gBAAQ,EAAE;QACzB,cAAc;QACd,mBAAmB;IACrB;IAEA,OAAO;QACL,UAAU;YACR,MAAM;QACR;QACA,gBAAgB;YACd,IAAI;YACJ,MAAM;QACR;QACA,eAAe;YACb,MAAM;YACN,GAAG,UAAU;QACf;IACF;AACF","sources":["packages/@react-aria/gridlist/src/useGridListSection.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 {DOMAttributes, RefObject} from '@react-types/shared';\nimport type {ListState} from '@react-stately/list';\nimport {useLabels, useSlotId} from '@react-aria/utils';\n\nexport interface AriaGridListSectionProps {\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\nexport interface GridListSectionAria {\n /** Props for the wrapper list item. */\n rowProps: DOMAttributes,\n\n /** Props for the heading element, if any. */\n rowHeaderProps: DOMAttributes,\n\n /** Props for the grid's row group element. */\n rowGroupProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a grid list.\n * See `useGridList` for more details about grid list.\n * @param props - Props for the section.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useGridListSection<T>(props: AriaGridListSectionProps, state: ListState<T>, ref: RefObject<HTMLElement | null>): GridListSectionAria {\n let {'aria-label': ariaLabel} = props;\n let headingId = useSlotId();\n let labelProps = useLabels({\n 'aria-label': ariaLabel,\n 'aria-labelledby': headingId\n });\n\n return {\n rowProps: {\n role: 'row'\n },\n rowHeaderProps: {\n id: headingId,\n role: 'rowheader'\n },\n rowGroupProps: {\n role: 'rowgroup',\n ...labelProps\n }\n };\n}\n"],"names":[],"version":3,"file":"useGridListSection.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/gridlist",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/focus": "^3.21.
|
|
30
|
-
"@react-aria/grid": "^3.14.
|
|
31
|
-
"@react-aria/i18n": "^3.12.
|
|
32
|
-
"@react-aria/interactions": "^3.25.
|
|
33
|
-
"@react-aria/selection": "^3.
|
|
34
|
-
"@react-aria/utils": "^3.
|
|
35
|
-
"@react-stately/list": "^3.
|
|
36
|
-
"@react-stately/tree": "^3.9.
|
|
37
|
-
"@react-types/shared": "^3.
|
|
29
|
+
"@react-aria/focus": "^3.21.2",
|
|
30
|
+
"@react-aria/grid": "^3.14.5",
|
|
31
|
+
"@react-aria/i18n": "^3.12.13",
|
|
32
|
+
"@react-aria/interactions": "^3.25.6",
|
|
33
|
+
"@react-aria/selection": "^3.26.0",
|
|
34
|
+
"@react-aria/utils": "^3.31.0",
|
|
35
|
+
"@react-stately/list": "^3.13.1",
|
|
36
|
+
"@react-stately/tree": "^3.9.3",
|
|
37
|
+
"@react-types/shared": "^3.32.1",
|
|
38
38
|
"@swc/helpers": "^0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
|
|
48
48
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
export {useGridList} from './useGridList';
|
|
14
14
|
export {useGridListItem} from './useGridListItem';
|
|
15
15
|
export {useGridListSelectionCheckbox} from './useGridListSelectionCheckbox';
|
|
16
|
+
export {useGridListSection} from './useGridListSection';
|
|
16
17
|
|
|
17
18
|
export type {AriaGridListOptions, AriaGridListProps, GridListAria, GridListProps} from './useGridList';
|
|
18
19
|
export type {AriaGridListItemOptions, GridListItemAria} from './useGridListItem';
|
package/src/useGridListItem.ts
CHANGED
|
@@ -291,7 +291,10 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
|
|
|
291
291
|
});
|
|
292
292
|
|
|
293
293
|
if (isVirtualized) {
|
|
294
|
-
|
|
294
|
+
let {collection} = state;
|
|
295
|
+
let nodes = [...collection];
|
|
296
|
+
// TODO: refactor ListCollection to store an absolute index of a node's position?
|
|
297
|
+
rowProps['aria-rowindex'] = nodes.find(node => node.type === 'section') ? [...collection.getKeys()].filter((key) => collection.getItem(key)?.type !== 'section').findIndex((key) => key === node.key) + 1 : node.index + 1;
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
let gridCellProps = {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
14
|
+
import type {ListState} from '@react-stately/list';
|
|
15
|
+
import {useLabels, useSlotId} from '@react-aria/utils';
|
|
16
|
+
|
|
17
|
+
export interface AriaGridListSectionProps {
|
|
18
|
+
/** An accessibility label for the section. Required if `heading` is not present. */
|
|
19
|
+
'aria-label'?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GridListSectionAria {
|
|
23
|
+
/** Props for the wrapper list item. */
|
|
24
|
+
rowProps: DOMAttributes,
|
|
25
|
+
|
|
26
|
+
/** Props for the heading element, if any. */
|
|
27
|
+
rowHeaderProps: DOMAttributes,
|
|
28
|
+
|
|
29
|
+
/** Props for the grid's row group element. */
|
|
30
|
+
rowGroupProps: DOMAttributes
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Provides the behavior and accessibility implementation for a section in a grid list.
|
|
35
|
+
* See `useGridList` for more details about grid list.
|
|
36
|
+
* @param props - Props for the section.
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
export function useGridListSection<T>(props: AriaGridListSectionProps, state: ListState<T>, ref: RefObject<HTMLElement | null>): GridListSectionAria {
|
|
40
|
+
let {'aria-label': ariaLabel} = props;
|
|
41
|
+
let headingId = useSlotId();
|
|
42
|
+
let labelProps = useLabels({
|
|
43
|
+
'aria-label': ariaLabel,
|
|
44
|
+
'aria-labelledby': headingId
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
rowProps: {
|
|
49
|
+
role: 'row'
|
|
50
|
+
},
|
|
51
|
+
rowHeaderProps: {
|
|
52
|
+
id: headingId,
|
|
53
|
+
role: 'rowheader'
|
|
54
|
+
},
|
|
55
|
+
rowGroupProps: {
|
|
56
|
+
role: 'rowgroup',
|
|
57
|
+
...labelProps
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|