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CAAC,aAAa,KAAK,aAAa,SAAS;IACnE,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,sDAA2B,EAAE,CAAC,GAAG;IAEjC,OAAO;mBACL;IACF;AACF","sources":["packages/react-aria/src/gridlist/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 FocusStrategy,\n Key,\n KeyboardDelegate,\n LayoutDelegate,\n MultipleSelection,\n RefObject\n} from '@react-types/shared';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {listMap} from './utils';\nimport {ListState} from 'react-stately/useListState';\nimport {mergeProps} from '../utils/mergeProps';\nimport {useGridSelectionAnnouncement} from '../grid/useGridSelectionAnnouncement';\nimport {useHasTabbableChild} from '../focus/useHasTabbableChild';\nimport {useHighlightSelectionDescription} from '../grid/useHighlightSelectionDescription';\nimport {useId} from '../utils/useId';\nimport {useSelectableList} from '../selection/useSelectableList';\n\nexport interface GridListProps<T> extends CollectionBase<T>, MultipleSelection {\n /** Whether to auto focus the gridlist or an option. */\n autoFocus?: boolean | FocusStrategy;\n /**\n * Handler that is called when a user performs an action on an item. The exact user event depends\n * on the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: (key: Key) => void;\n /**\n * Whether `disabledKeys` applies to all interactions, or only selection.\n *\n * @default 'all'\n */\n disabledBehavior?: DisabledBehavior;\n /** Whether selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\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 *\n * @default 'arrow'\n */\n keyboardNavigationBehavior?: 'arrow' | 'tab';\n /**\n * Whether pressing the escape key should clear selection in the grid list or not.\n *\n * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n * easily clear selection. Only use if the escape key is being handled externally or should not\n * trigger selection clearing contextually.\n *\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none';\n}\n\nexport interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {\n /** Whether the list uses virtual scrolling. */\n isVirtualized?: boolean;\n /**\n * Whether typeahead navigation is disabled.\n *\n * @default false\n */\n disallowTypeAhead?: boolean;\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate;\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate;\n /**\n * Whether focus should wrap around when the end/start is reached.\n *\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 *\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override';\n /**\n * Which item in the collection to focus when tabbing into the collection. Overrides default\n * roving tab index like behavior.\n *\n * @private\n */\n UNSTABLE_focusOnEntry?: 'first' | 'last';\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\n * children. A grid list displays data in a single column and enables a user to navigate its\n * contents via directional navigation keys.\n *\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>(\n props: AriaGridListOptions<T>,\n state: ListState<T>,\n ref: RefObject<HTMLElement | null>\n): GridListAria {\n let {\n isVirtualized,\n keyboardDelegate,\n layoutDelegate,\n onAction,\n disallowTypeAhead,\n linkBehavior = 'action',\n keyboardNavigationBehavior = 'arrow',\n escapeKeyBehavior = 'clearSelection',\n shouldSelectOnPressUp\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,\n layoutDelegate,\n isVirtualized,\n selectOnFocus: state.selectionManager.selectionBehavior === 'replace',\n shouldFocusWrap: props.shouldFocusWrap,\n linkBehavior,\n disallowTypeAhead,\n autoFocus: props.autoFocus,\n escapeKeyBehavior,\n UNSTABLE_focusOnEntry: props.UNSTABLE_focusOnEntry\n });\n\n let id = useId(props.id);\n listMap.set(state, {\n id,\n onAction,\n linkBehavior,\n keyboardNavigationBehavior,\n shouldSelectOnPressUp\n });\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':\n 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.cjs.map"}