-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Uncontrolled Switch
checked
state not visible in DOM
#3317
Comments
Switch
state not synced to hidden input
Switch
checked
state not visible in DOM
Not sure I understand what's going on here, but the form itself seems unaffected by the fact the dev tools don't show the DOM update. Closing for now until I get a better grasp on the problem I'm seeing. |
Hey! My guess is that the devtools aren't reflecting the change because it is hidden but as you discovered already the value should still be synced correctly. I created a small reproduction that shows all the fields of the form to debug it: https://codesandbox.io/p/devbox/headlessui-switch-no-input-forked-ctlftn?file=%2Fsrc%2FApp.jsx%3A11%2C53 Note that the switch behaves as a native To answer your second question, we moved the hidden inputs into a hidden div for a few reasons:
Hope this helps! |
Thank you @RobinMalfait, this all makes perfect sense to me. Appreciate it! |
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v2.1.0
What browser are you using?
Chromium
Reproduction URL
https://codesandbox.io/p/devbox/headlessui-switch-no-input-qvyqvx?file=%2Fsrc%2FApp.jsx
Describe your issue
Edit: Modifying the below now. The change to
checked
isn't visible in the DOM, but the submitted form data is unaffected. So this is a much more minor issue than I thought.I'm currently attempting to upgrade from v1 to v2, and we've run into trouble with our uncontrolled
Switch
components. It seems v2 is not keeping thevalue
of the hiddeninput
in sync like v1 did.I've attached my best shot at a minimal reproduction, let me know if I'm doing something wrong.
(Side note, I don't know why v2 moves the hidden
input
to a weird hiddendiv
; this had me thinking for at least an hour that the hiddeninput
had simply disappeared. I liked it better when it was a simple sibling!)The text was updated successfully, but these errors were encountered: