diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md
index 41f8949a72..a1bab7ab88 100644
--- a/packages/@headlessui-react/CHANGELOG.md
+++ b/packages/@headlessui-react/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Prevent default behaviour when clicking outside of a `Dialog.Panel` ([#2919](https://github.com/tailwindlabs/headlessui/pull/2919))
- Add `hidden` attribute to internal `` component when the `Features.Hidden` feature is used ([#2955](https://github.com/tailwindlabs/headlessui/pull/2955))
- Allow setting custom `tabIndex` on the `` component ([#2966](https://github.com/tailwindlabs/headlessui/pull/2966))
+- Forward `disabled` state to hidden inputs in form-like components ([#3004](https://github.com/tailwindlabs/headlessui/pull/3004))
## [1.7.18] - 2024-01-08
diff --git a/packages/@headlessui-react/src/components/combobox/combobox.test.tsx b/packages/@headlessui-react/src/components/combobox/combobox.test.tsx
index 505c85f1ad..38a91a12e5 100644
--- a/packages/@headlessui-react/src/components/combobox/combobox.test.tsx
+++ b/packages/@headlessui-react/src/components/combobox/combobox.test.tsx
@@ -5655,6 +5655,48 @@ describe('Form compatibility', () => {
expect(submits).lastCalledWith([['delivery', 'pickup']])
})
+ it('should not submit the data if the Combobox is disabled', async () => {
+ let submits = jest.fn()
+
+ function Example() {
+ let [value, setValue] = useState('home-delivery')
+ return (
+
+ )
+ }
+
+ render()
+
+ // Open combobox
+ await click(getComboboxButton())
+
+ // Submit the form
+ await click(getByText('Submit'))
+
+ // Verify that the form has been submitted
+ expect(submits).toHaveBeenLastCalledWith([
+ ['foo', 'bar'], // The only available field
+ ])
+ })
+
it('should be possible to submit a form with a complex value object', async () => {
let submits = jest.fn()
let options = [
diff --git a/packages/@headlessui-react/src/components/combobox/combobox.tsx b/packages/@headlessui-react/src/components/combobox/combobox.tsx
index bdacf6d1ca..1e43f8f0e7 100644
--- a/packages/@headlessui-react/src/components/combobox/combobox.tsx
+++ b/packages/@headlessui-react/src/components/combobox/combobox.tsx
@@ -942,6 +942,7 @@ function ComboboxFn {
expect(submits).lastCalledWith([['delivery', 'pickup']])
})
+ it('should not submit the data if the Listbox is disabled', async () => {
+ let submits = jest.fn()
+
+ function Example() {
+ let [value, setValue] = useState('home-delivery')
+ return (
+
+ )
+ }
+
+ render()
+
+ // Open listbox
+ await click(getListboxButton())
+
+ // Submit the form
+ await click(getByText('Submit'))
+
+ // Verify that the form has been submitted
+ expect(submits).toHaveBeenLastCalledWith([
+ ['foo', 'bar'], // The only available field
+ ])
+ })
+
it('should be possible to submit a form with a complex value object', async () => {
let submits = jest.fn()
let options = [
diff --git a/packages/@headlessui-react/src/components/listbox/listbox.tsx b/packages/@headlessui-react/src/components/listbox/listbox.tsx
index 154883fabf..e97cb2f8e1 100644
--- a/packages/@headlessui-react/src/components/listbox/listbox.tsx
+++ b/packages/@headlessui-react/src/components/listbox/listbox.tsx
@@ -566,6 +566,7 @@ function ListboxFn<
hidden: true,
readOnly: true,
form: formName,
+ disabled,
name,
value,
})}
diff --git a/packages/@headlessui-react/src/components/radio-group/radio-group.test.tsx b/packages/@headlessui-react/src/components/radio-group/radio-group.test.tsx
index 4b182c5986..c7a4adae39 100644
--- a/packages/@headlessui-react/src/components/radio-group/radio-group.test.tsx
+++ b/packages/@headlessui-react/src/components/radio-group/radio-group.test.tsx
@@ -1485,6 +1485,41 @@ describe('Form compatibility', () => {
})
)
+ it('should not submit the data if the RadioGroup is disabled', async () => {
+ let submits = jest.fn()
+
+ function Example() {
+ let [value, setValue] = useState('home-delivery')
+ return (
+
+ )
+ }
+
+ render()
+
+ // Submit the form
+ await click(getByText('Submit'))
+
+ // Verify that the form has been submitted
+ expect(submits).toHaveBeenLastCalledWith([
+ ['foo', 'bar'], // The only available field
+ ])
+ })
+
it(
'should be possible to submit a form with a complex value object',
suppressConsoleLogs(async () => {
diff --git a/packages/@headlessui-react/src/components/radio-group/radio-group.tsx b/packages/@headlessui-react/src/components/radio-group/radio-group.tsx
index f6251e9461..f8441e1a07 100644
--- a/packages/@headlessui-react/src/components/radio-group/radio-group.tsx
+++ b/packages/@headlessui-react/src/components/radio-group/radio-group.tsx
@@ -350,6 +350,7 @@ function RadioGroupFn {
// Verify that the form has been submitted
expect(submits).lastCalledWith([['fruit', 'apple']])
})
+
+ it('should not submit the data if the Switch is disabled', async () => {
+ let submits = jest.fn()
+
+ function Example() {
+ let [state, setState] = useState(true)
+ return (
+
+ )
+ }
+
+ render()
+
+ // Submit the form
+ await click(getByText('Submit'))
+
+ // Verify that the form has been submitted
+ expect(submits).toHaveBeenLastCalledWith([
+ ['foo', 'bar'], // The only available field
+ ])
+ })
})
diff --git a/packages/@headlessui-react/src/components/switch/switch.tsx b/packages/@headlessui-react/src/components/switch/switch.tsx
index a4d6393f65..6aa48b021c 100644
--- a/packages/@headlessui-react/src/components/switch/switch.tsx
+++ b/packages/@headlessui-react/src/components/switch/switch.tsx
@@ -114,6 +114,7 @@ export type SwitchProps = Props<
onChange?(checked: boolean): void
name?: string
value?: string
+ disabled?: boolean
form?: string
tabIndex?: number
}
@@ -129,6 +130,7 @@ function SwitchFn(
checked: controlledChecked,
defaultChecked = false,
onChange: controlledOnChange,
+ disabled = false,
name,
value,
form,
@@ -172,6 +174,7 @@ function SwitchFn(
'aria-checked': checked,
'aria-labelledby': groupContext?.labelledby,
'aria-describedby': groupContext?.describedby,
+ disabled,
onClick: handleClick,
onKeyUp: handleKeyUp,
onKeyPress: handleKeyPress,
@@ -198,6 +201,7 @@ function SwitchFn(
type: 'checkbox',
hidden: true,
readOnly: true,
+ disabled,
form,
checked,
name,
diff --git a/packages/@headlessui-vue/CHANGELOG.md b/packages/@headlessui-vue/CHANGELOG.md
index 21d72dd3a6..06db4c9cb7 100644
--- a/packages/@headlessui-vue/CHANGELOG.md
+++ b/packages/@headlessui-vue/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don’t override explicit `disabled` prop for components inside `