MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useTabPanel

Function useTabPanel

packages/react-aria/src/tabs/useTabPanel.ts:34–59  ·  view source on GitHub ↗
(
  props: AriaTabPanelProps,
  state: TabListState<T> | null,
  ref: RefObject<Element | null>
)

Source from the content-addressed store, hash-verified

32 * container for the contents of a tab, and is shown when the tab is selected.
33 */
34export function useTabPanel<T>(
35 props: AriaTabPanelProps,
36 state: TabListState<T> | null,
37 ref: RefObject<Element | null>
38): TabPanelAria {
39 // The tabpanel should have tabIndex=0 when there are no tabbable elements within it.
40 // Otherwise, tabbing from the focused tab should go directly to the first tabbable element
41 // within the tabpanel.
42 let tabIndex = useHasTabbableChild(ref) ? undefined : 0;
43
44 const id = generateId(state, props.id ?? state?.selectedKey, 'tabpanel');
45 const tabPanelProps = useLabels({
46 ...props,
47 id,
48 'aria-labelledby': generateId(state, state?.selectedKey, 'tab')
49 });
50
51 return {
52 tabPanelProps: mergeProps(tabPanelProps, {
53 tabIndex,
54 role: 'tabpanel',
55 'aria-describedby': props['aria-describedby'],
56 'aria-details': props['aria-details']
57 })
58 };
59}

Callers 3

TabPanelFunction · 0.90
TabPanelInnerFunction · 0.85
TabPanelFunction · 0.85

Calls 4

useHasTabbableChildFunction · 0.90
generateIdFunction · 0.90
useLabelsFunction · 0.90
mergePropsFunction · 0.90

Tested by

no test coverage detected