Skip to content

Commit 2b7a57e

Browse files
authored
Expose disabled state on <Tab /> component (#2918)
* 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
1 parent b83b5b6 commit 2b7a57e

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Expose `disabled` state on `<Tab />` component ([#2918](https://github.com/tailwindlabs/headlessui/pull/2918))
1113

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

packages/@headlessui-react/src/components/tabs/tabs.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ describe('Rendering', () => {
544544
active: false,
545545
focus: false,
546546
autofocus: false,
547+
disabled: false,
547548
})
548549
)
549550
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
@@ -553,6 +554,7 @@ describe('Rendering', () => {
553554
active: false,
554555
focus: false,
555556
autofocus: false,
557+
disabled: false,
556558
})
557559
)
558560
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
@@ -562,6 +564,7 @@ describe('Rendering', () => {
562564
active: false,
563565
focus: false,
564566
autofocus: false,
567+
disabled: false,
565568
})
566569
)
567570

@@ -574,6 +577,7 @@ describe('Rendering', () => {
574577
active: false,
575578
focus: false,
576579
autofocus: false,
580+
disabled: false,
577581
})
578582
)
579583
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
@@ -583,6 +587,7 @@ describe('Rendering', () => {
583587
active: false,
584588
focus: false,
585589
autofocus: false,
590+
disabled: false,
586591
})
587592
)
588593
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
@@ -592,6 +597,7 @@ describe('Rendering', () => {
592597
active: false,
593598
focus: false,
594599
autofocus: false,
600+
disabled: false,
595601
})
596602
)
597603
})

packages/@headlessui-react/src/components/tabs/tabs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ type TabRenderPropArg = {
388388
active: boolean
389389
autofocus: boolean
390390
selected: boolean
391+
disabled: boolean
391392
}
392393
type TabPropsWeControl = 'aria-controls' | 'aria-selected' | 'role' | 'tabIndex'
393394

@@ -512,8 +513,9 @@ function TabFn<TTag extends ElementType = typeof DEFAULT_TAB_TAG>(
512513
active,
513514
focus,
514515
autofocus: props.autoFocus ?? false,
516+
disabled: props.disabled ?? false,
515517
}) satisfies TabRenderPropArg,
516-
[selected, hover, focus, active, props.autoFocus]
518+
[selected, hover, focus, active, props.autoFocus, props.disabled]
517519
)
518520

519521
let ourProps = mergeProps(

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add `immediate` prop to `<Combobox />` for immediately opening the Combobox when the `input` receives focus ([#2686](https://github.com/tailwindlabs/headlessui/pull/2686))
1313
- Add `virtual` prop to `Combobox` component ([#2779](https://github.com/tailwindlabs/headlessui/pull/2779))
1414

15+
### Fixed
16+
17+
- Expose `disabled` state on `<Tab />` component ([#2918](https://github.com/tailwindlabs/headlessui/pull/2918))
18+
1519
## [1.7.17] - 2024-01-08
1620

1721
### Fixed

packages/@headlessui-vue/src/components/tabs/tabs.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,25 +463,25 @@ describe('Rendering', () => {
463463
await new Promise<void>(nextTick)
464464

465465
expect(document.querySelector('[data-tab="0"]')).toHaveTextContent(
466-
JSON.stringify({ selected: true })
466+
JSON.stringify({ selected: true, disabled: false })
467467
)
468468
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
469-
JSON.stringify({ selected: false })
469+
JSON.stringify({ selected: false, disabled: false })
470470
)
471471
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
472-
JSON.stringify({ selected: false })
472+
JSON.stringify({ selected: false, disabled: false })
473473
)
474474

475475
await click(getTabs()[1])
476476

477477
expect(document.querySelector('[data-tab="0"]')).toHaveTextContent(
478-
JSON.stringify({ selected: false })
478+
JSON.stringify({ selected: false, disabled: false })
479479
)
480480
expect(document.querySelector('[data-tab="1"]')).toHaveTextContent(
481-
JSON.stringify({ selected: true })
481+
JSON.stringify({ selected: true, disabled: false })
482482
)
483483
expect(document.querySelector('[data-tab="2"]')).toHaveTextContent(
484-
JSON.stringify({ selected: false })
484+
JSON.stringify({ selected: false, disabled: false })
485485
)
486486
})
487487

packages/@headlessui-vue/src/components/tabs/tabs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export let Tab = defineComponent({
423423
)
424424

425425
return () => {
426-
let slot = { selected: selected.value }
426+
let slot = { selected: selected.value, disabled: props.disabled ?? false }
427427
let { id, ...theirProps } = props
428428
let ourProps = {
429429
ref: internalTabRef,

0 commit comments

Comments
 (0)