( props: AriaTabPanelProps, state: TabListState<T> | null, ref: RefObject<Element | null> )
| 32 | * container for the contents of a tab, and is shown when the tab is selected. |
| 33 | */ |
| 34 | export 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 | } |
no test coverage detected