Skip to content

Commit

Permalink
Expose disabled state on <Tab /> component (#2918)
Browse files Browse the repository at this point in the history
* expose `disabled` on `<Tab/>` component

This will expose it such that you can use it with `ui-disabled`. In the
Alpha version of React, you can also use `data-[disabled]` because it
will be exposed as `data-disabled` over there as well.

Fixes: #2864

* update changelog
  • Loading branch information
RobinMalfait authored Jan 9, 2024
1 parent b83b5b6 commit 2b7a57e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
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

2 comments on commit 2b7a57e

@vercel
Copy link

@vercel vercel bot commented on 2b7a57e Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-vue – ./playgrounds/vue

headlessui-vue.vercel.app
headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue-tailwindlabs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 2b7a57e Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-react – ./playgrounds/react

headlessui-react-tailwindlabs.vercel.app
headlessui-react.vercel.app
headlessui-react-git-main-tailwindlabs.vercel.app

Please sign in to comment.