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

Expose disabled state on <Tab /> component #2918

Merged
merged 2 commits into from
Jan 9, 2024
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: 3 additions & 1 deletion packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Expose `disabled` state on `<Tab />` component ([#2918](https://github.com/tailwindlabs/headlessui/pull/2918))

## [2.0.0-alpha.4] - 2024-01-03

Expand Down
6 changes: 6 additions & 0 deletions packages/@headlessui-react/src/components/tabs/tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
Expand All @@ -553,6 +554,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
Expand All @@ -562,6 +564,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)

Expand All @@ -574,6 +577,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
Expand All @@ -583,6 +587,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
Expand All @@ -592,6 +597,7 @@ describe('Rendering', () => {
active: false,
focus: false,
autofocus: false,
disabled: false,
})
)
})
Expand Down
4 changes: 3 additions & 1 deletion packages/@headlessui-react/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ type TabRenderPropArg = {
active: boolean
autofocus: boolean
selected: boolean
disabled: boolean
}
type TabPropsWeControl = 'aria-controls' | 'aria-selected' | 'role' | 'tabIndex'

Expand Down Expand Up @@ -512,8 +513,9 @@ function TabFn<TTag extends ElementType = typeof DEFAULT_TAB_TAG>(
active,
focus,
autofocus: props.autoFocus ?? false,
disabled: props.disabled ?? false,
}) satisfies TabRenderPropArg,
[selected, hover, focus, active, props.autoFocus]
[selected, hover, focus, active, props.autoFocus, props.disabled]
)

let ourProps = mergeProps(
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 @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `immediate` prop to `<Combobox />` for immediately opening the Combobox when the `input` receives focus ([#2686](https://github.com/tailwindlabs/headlessui/pull/2686))
- Add `virtual` prop to `Combobox` component ([#2779](https://github.com/tailwindlabs/headlessui/pull/2779))

### Fixed

- Expose `disabled` state on `<Tab />` component ([#2918](https://github.com/tailwindlabs/headlessui/pull/2918))

## [1.7.17] - 2024-01-08

### Fixed
Expand Down
12 changes: 6 additions & 6 deletions packages/@headlessui-vue/src/components/tabs/tabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,25 +463,25 @@ describe('Rendering', () => {
await new Promise<void>(nextTick)

expect(document.querySelector('[data-tab="0"]')).toHaveTextContent(
JSON.stringify({ selected: true })
JSON.stringify({ selected: true, disabled: false })
)
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
JSON.stringify({ selected: false })
JSON.stringify({ selected: false, disabled: false })
)
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
JSON.stringify({ selected: false })
JSON.stringify({ selected: false, disabled: false })
)

await click(getTabs()[1])

expect(document.querySelector('[data-tab="0"]')).toHaveTextContent(
JSON.stringify({ selected: false })
JSON.stringify({ selected: false, disabled: false })
)
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
JSON.stringify({ selected: true })
JSON.stringify({ selected: true, disabled: false })
)
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
JSON.stringify({ selected: false })
JSON.stringify({ selected: false, disabled: false })
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export let Tab = defineComponent({
)

return () => {
let slot = { selected: selected.value }
let slot = { selected: selected.value, disabled: props.disabled ?? false }
let { id, ...theirProps } = props
let ourProps = {
ref: internalTabRef,
Expand Down