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F;AACF","sources":["packages/react-aria/src/tabs/useTab.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 AriaLabelingProps,\n DOMAttributes,\n FocusableElement,\n Key,\n RefObject\n} from '@react-types/shared';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {generateId} from './utils';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TabListState} from 'react-stately/useTabListState';\nimport {useFocusable} from '../interactions/useFocusable';\nimport {useLinkProps} from '../utils/openLink';\nimport {useSelectableItem} from '../selection/useSelectableItem';\n\nexport interface AriaTabProps extends AriaLabelingProps {\n /** The key of the tab. */\n key: Key;\n /** Whether the tab should be disabled. */\n isDisabled?: boolean;\n /** Whether the tab selection should occur on press up instead of press down. */\n shouldSelectOnPressUp?: boolean;\n}\n\nexport interface TabAria {\n /** Props for the tab element. */\n tabProps: DOMAttributes;\n /** Whether the tab is currently selected. */\n isSelected: boolean;\n /** Whether the tab is disabled. */\n isDisabled: boolean;\n /** Whether the tab is currently in a pressed state. */\n isPressed: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tab.\n * When selected, the associated tab panel is shown.\n */\nexport function useTab<T>(\n props: AriaTabProps,\n state: TabListState<T>,\n ref: RefObject<FocusableElement | null>\n): TabAria {\n let {key, isDisabled: propsDisabled, shouldSelectOnPressUp} = props;\n let {selectionManager: manager, selectedKey} = state;\n\n let isSelected = key === selectedKey;\n\n let isDisabled = propsDisabled || state.isDisabled || state.selectionManager.isDisabled(key);\n let item = state.collection.getItem(key);\n let {itemProps, isPressed} = useSelectableItem({\n selectionManager: manager,\n key,\n ref,\n isDisabled,\n // Link tabs should behave like native anchors (navigate on press up)\n // This avoids reopening beforeunload dialogs when browsers replay\n // queued pointer enter/leave events after cancellation.\n shouldSelectOnPressUp: shouldSelectOnPressUp ?? item?.props.href != null,\n linkBehavior: 'selection'\n });\n\n let tabId = generateId(state, key, 'tab');\n let tabPanelId = generateId(state, key, 'tabpanel');\n let {tabIndex} = itemProps;\n\n let domProps = filterDOMProps(item?.props, {labelable: true});\n delete domProps.id;\n let linkProps = useLinkProps(item?.props);\n let {focusableProps} = useFocusable(\n {\n ...item?.props,\n isDisabled\n },\n ref\n );\n\n return {\n tabProps: mergeProps(domProps, focusableProps, linkProps, itemProps, {\n id: tabId,\n 'aria-selected': isSelected,\n 'aria-disabled': isDisabled || undefined,\n 'aria-controls': isSelected ? tabPanelId : undefined,\n tabIndex: isDisabled ? undefined : tabIndex,\n role: 'tab'\n }),\n isSelected,\n isDisabled,\n isPressed\n };\n}\n"],"names":[],"version":3,"file":"useTab.mjs.map"}