Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting tabIndex on the Tab.Panel #2214

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix crash when reading `headlessuiFocusGuard` of `relatedTarget` in the `FocusTrap` component ([#2203](https://github.com/tailwindlabs/headlessui/pull/2203))
- Fix `FocusTrap` in `Dialog` when there is only 1 focusable element ([#2172](https://github.com/tailwindlabs/headlessui/pull/2172))

### 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 @@ -495,7 +495,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 @@ -504,7 +504,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 @@ -531,7 +531,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 @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix crash when reading `headlessuiFocusGuard` of `relatedTarget` in the `FocusTrap` component ([#2203](https://github.com/tailwindlabs/headlessui/pull/2203))
- Fix `FocusTrap` in `Dialog` when there is only 1 focusable element ([#2172](https://github.com/tailwindlabs/headlessui/pull/2172))

### 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 @@ -431,6 +431,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 @@ -462,13 +463,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