tailwindlabs / headlessui

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
https://headlessui.com
MIT License
25.81k stars 1.07k forks source link

Only handle form reset when `defaultValue` is used #3240

Closed RobinMalfait closed 4 months ago

RobinMalfait commented 4 months ago

This PR fixes a bug where it would call the onChange of a <Listbox> or <Combobox> component when used inside of a <form> even if no defaultValue was provided. This also happened for the <Checkbox> and <Switch> component but for the defaultChecked prop.

This means that the onChange would be called with undefined which your application might not expect.

This PR only calls onChange with the defaultValue (or defaultChecked for <Checkbox> or <Switch> components) if it is provided.

This PR also has a small refactor to ensure we can safely use defaultChecked and defaultValue in dependency arrays of hooks.

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 24, 2024 10:02pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 24, 2024 10:02pm