Skip to content

Conversation

@RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Nov 9, 2022

This PR fixes an issue where the form-like components (Listbox, Switch, RadioGroup and Combobox) didn't reset its value to the defaultValue when the parent <form> received a reset event.

This PR also includes some refactoring for those components so that the change itself was a bit easier to apply.

Fixes: #1950

This splitsup the raw `[state, dispatch]` to separate `useActions` and `useData` hooks.

This allows us to make the actions themselves simpler and include logic
that doesn't really belong in the reducer itself.

This also allows us to expose data via the `useData` hook that doesn't
belong in the state exposed from the `useReducer` hook.

E.g.: we used to store a `propsRef` from the root `Listbox`, and update
the ref with the new props in a `useEffect`. Now, we will just expose
that information directly via the `useData` hook. This simplifies the
code, removes useEffect's and so on.
If the `isControlled` value changes, then the references to all the
functions changed. Now they won't because of the `useEvent` hooks.
@vercel
Copy link

vercel bot commented Nov 9, 2022

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

Name Status Preview Updated
headlessui-react ✅ Ready (Inspect) Visit Preview Nov 9, 2022 at 10:37PM (UTC)
headlessui-vue ✅ Ready (Inspect) Visit Preview Nov 9, 2022 at 10:37PM (UTC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React] Uncontrolled Listbox do not reset after running reset on the form

2 participants