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cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,GAErC,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IACE,eAAe,QACd,CAAA,aAAa,GAAG,CAAC,gBAAgB,WAAW,OAAO,CAAC,cAAc,OAAO,UAAS,KACnF,gBAAgB,WAAW,UAAU,IAErC,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/react-stately/src/tabs/useTabListState.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 {\n Collection,\n CollectionBase,\n CollectionStateBase,\n Key,\n Node,\n SingleSelection\n} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '../list/useSingleSelectListState';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListProps<T>\n extends\n CollectionBase<T>,\n Omit<\n SingleSelection,\n 'disallowEmptySelection' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange'\n > {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void;\n}\n\nexport interface TabListStateOptions<T>\n extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean;\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange\n ? key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }\n : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey:\n props.defaultSelectedKey ??\n findDefaultSelectedKey(\n props.collection,\n props.disabledKeys ? new Set(props.disabledKeys) : new Set()\n ) ??\n undefined\n });\n\n let {selectionManager, collection, selectedKey: currentSelectedKey} = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (\n props.selectedKey == null &&\n (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))\n ) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (\n (selectedKey != null && selectionManager.focusedKey == null) ||\n (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)\n ) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(\n collection: Collection<Node<T>> | undefined,\n disabledKeys: Set<Key>\n) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey !== collection.getLastKey()\n ) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (\n selectedKey != null &&\n (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) &&\n selectedKey === collection.getLastKey()\n ) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.cjs.map"}