Files
NapCatQQ/.pnpm-store/v3/files/02/f1d74acca7240268a6f7f4c7d93d434fedcdc1f3111786dce6db32f3c07ea17bc208846dba0f182e46ce41acfe18e9d1bdf0440718437e8f7d47dfcde12891
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

78 lines
2.6 KiB
Plaintext

/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {AriaTabProps} from '@react-types/tabs';
import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
import {filterDOMProps, mergeProps, useLinkProps} from '@react-aria/utils';
import {generateId} from './utils';
import {TabListState} from '@react-stately/tabs';
import {useSelectableItem} from '@react-aria/selection';
export interface TabAria {
/** Props for the tab element. */
tabProps: DOMAttributes,
/** Whether the tab is currently selected. */
isSelected: boolean,
/** Whether the tab is disabled. */
isDisabled: boolean,
/** Whether the tab is currently in a pressed state. */
isPressed: boolean
}
/**
* Provides the behavior and accessibility implementation for a tab.
* When selected, the associated tab panel is shown.
*/
export function useTab<T>(
props: AriaTabProps,
state: TabListState<T>,
ref: RefObject<FocusableElement | null>
): TabAria {
let {key, isDisabled: propsDisabled, shouldSelectOnPressUp} = props;
let {selectionManager: manager, selectedKey} = state;
let isSelected = key === selectedKey;
let isDisabled = propsDisabled || state.isDisabled || state.selectionManager.isDisabled(key);
let {itemProps, isPressed} = useSelectableItem({
selectionManager: manager,
key,
ref,
isDisabled,
shouldSelectOnPressUp,
linkBehavior: 'selection'
});
let tabId = generateId(state, key, 'tab');
let tabPanelId = generateId(state, key, 'tabpanel');
let {tabIndex} = itemProps;
let item = state.collection.getItem(key);
let domProps = filterDOMProps(item?.props, {labelable: true});
delete domProps.id;
let linkProps = useLinkProps(item?.props);
return {
tabProps: mergeProps(domProps, linkProps, itemProps, {
id: tabId,
'aria-selected': isSelected,
'aria-disabled': isDisabled || undefined,
'aria-controls': isSelected ? tabPanelId : undefined,
tabIndex: isDisabled ? undefined : tabIndex,
role: 'tab'
}),
isSelected,
isDisabled,
isPressed
};
}