diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index a255a343e5..2b412e5c59 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix `FocusTrap` in `Dialog` when there is only 1 focusable element ([#2172](https://github.com/tailwindlabs/headlessui/pull/2172)) - Improve `Tabs` wrapping around when controlling the component and overflowing the `selectedIndex` ([#2213](https://github.com/tailwindlabs/headlessui/pull/2213)) +### Added + +- Allow setting `tabIndex` on the `Tab.Panel` ([#2214](https://github.com/tailwindlabs/headlessui/pull/2214)) + ## [1.7.7] - 2022-12-16 ### Fixed diff --git a/packages/@headlessui-react/src/components/tabs/tabs.tsx b/packages/@headlessui-react/src/components/tabs/tabs.tsx index 1a27038612..a43f8e92d4 100644 --- a/packages/@headlessui-react/src/components/tabs/tabs.tsx +++ b/packages/@headlessui-react/src/components/tabs/tabs.tsx @@ -520,7 +520,7 @@ let DEFAULT_PANEL_TAG = 'div' as const interface PanelRenderPropArg { selected: boolean } -type PanelPropsWeControl = 'role' | 'aria-labelledby' | 'tabIndex' +type PanelPropsWeControl = 'role' | 'aria-labelledby' let PanelRenderFeatures = Features.RenderStrategy | Features.Static let Panel = forwardRefWithAs(function Panel( @@ -529,7 +529,7 @@ let Panel = forwardRefWithAs(function Panel ) { let internalId = useId() - let { id = `headlessui-tabs-panel-${internalId}`, ...theirProps } = props + let { id = `headlessui-tabs-panel-${internalId}`, tabIndex = 0, ...theirProps } = props let { selectedIndex, tabs, panels } = useData('Tab.Panel') let actions = useActions('Tab.Panel') let SSRContext = useSSRTabsCounter('Tab.Panel') @@ -556,7 +556,7 @@ let Panel = forwardRefWithAs(function Panel `headlessui-tabs-panel-${useId()}` }, + tabIndex: { type: Number, default: 0 }, }, setup(props, { attrs, slots, expose }) { let api = useTabsContext('TabPanel') @@ -514,13 +515,13 @@ export let TabPanel = defineComponent({ return () => { let slot = { selected: selected.value } - let { id, ...theirProps } = props + let { id, tabIndex, ...theirProps } = props let ourProps = { ref: internalPanelRef, id, role: 'tabpanel', 'aria-labelledby': dom(api.tabs.value[myIndex.value])?.id, - tabIndex: selected.value ? 0 : -1, + tabIndex: selected.value ? tabIndex : -1, } if (!selected.value && props.unmount && !props.static) {