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

48 lines
2.0 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 {AriaTabPanelProps} from '@react-types/tabs';
import {DOMAttributes, RefObject} from '@react-types/shared';
import {generateId} from './utils';
import {mergeProps, useLabels} from '@react-aria/utils';
import {TabListState} from '@react-stately/tabs';
import {useHasTabbableChild} from '@react-aria/focus';
export interface TabPanelAria {
/** Props for the tab panel element. */
tabPanelProps: DOMAttributes
}
/**
* Provides the behavior and accessibility implementation for a tab panel. A tab panel is a container for
* the contents of a tab, and is shown when the tab is selected.
*/
export function useTabPanel<T>(props: AriaTabPanelProps, state: TabListState<T> | null, ref: RefObject<Element | null>): TabPanelAria {
// The tabpanel should have tabIndex=0 when there are no tabbable elements within it.
// Otherwise, tabbing from the focused tab should go directly to the first tabbable element
// within the tabpanel.
let tabIndex = useHasTabbableChild(ref) ? undefined : 0;
const id = generateId(state, props.id ?? state?.selectedKey, 'tabpanel');
const tabPanelProps = useLabels({...props, id, 'aria-labelledby': generateId(state, state?.selectedKey, 'tab')});
return {
tabPanelProps: mergeProps(tabPanelProps, {
tabIndex,
role: 'tabpanel',
'aria-describedby': props['aria-describedby'],
'aria-details': props['aria-details']
})
};
}