Skip to content

Commit

Permalink
Allow setting tabIndex on the Tab.Panel (#2214)
Browse files Browse the repository at this point in the history
* allow setting `tabIndex` on the `Tab.Panel`

* update changelog
  • Loading branch information
RobinMalfait authored Jan 26, 2023
1 parent e2294f5 commit 2f13496
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/@headlessui-react/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(
Expand All @@ -529,7 +529,7 @@ let Panel = forwardRefWithAs(function Panel<TTag extends ElementType = typeof DE
ref: Ref<HTMLElement>
) {
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')
Expand All @@ -556,7 +556,7 @@ let Panel = forwardRefWithAs(function Panel<TTag extends ElementType = typeof DE
id,
role: 'tabpanel',
'aria-labelledby': tabs[myIndex]?.current?.id,
tabIndex: selected ? 0 : -1,
tabIndex: selected ? tabIndex : -1,
}

if (!selected && (theirProps.unmount ?? true) && !(theirProps.static ?? false)) {
Expand Down
4 changes: 4 additions & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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
Expand Down
5 changes: 3 additions & 2 deletions packages/@headlessui-vue/src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export let TabPanel = defineComponent({
static: { type: Boolean, default: false },
unmount: { type: Boolean, default: true },
id: { type: String, default: () => `headlessui-tabs-panel-${useId()}` },
tabIndex: { type: Number, default: 0 },
},
setup(props, { attrs, slots, expose }) {
let api = useTabsContext('TabPanel')
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2f13496

Please sign in to comment.