Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset form-like components when the parent <form> resets #2004

Merged
merged 11 commits into from
Nov 9, 2022

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
1 participant