-
Notifications
You must be signed in to change notification settings - Fork 1.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
Allow Enter
for form submit in RadioGroup
, Switch
and Combobox
improvements
#1285
Conversation
This pull request is being automatically deployed with Vercel (learn more). headlessui-react – ./packages/playground-react🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/FqYF7CFaSYmAsqJ9qDmPXNGPD1K5 headlessui-vue – ./packages/playground-vue🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/4QpY5VKqRrXAxBoGT2R9CR2daoPo |
31bf3ff
to
96f14b6
Compare
96f14b6
to
cd879d3
Compare
Combobox
Combobox
Combobox
Combobox
cd879d3
to
a813b2e
Compare
This will allow us to _try_ and submit a form based on any element you pass it. It will try and lookup the current form and if it is submittable it will attempt to submit it. Instead of submitting the form directly, we try to follow the native browser support where it looks for the first `input[type=submit]`, `input[type=image]`, `button` or `button[type=submit]`, then it clicks it. This allows you to disable your submit button, or have an `onClick` that does an `event.preventDefault()` just like the native form in a browser would do.
When the Combobox is closed, then the `Enter` keydown event will be ignored and thus not use `event.preventDefault()`. With recent changes where we always have an active option, it means that you will always be able to select an option. If we have no option at all (some edge case) or when the combobox is closed, then the `Enter` keydown event will just bubble, allowing you to submit a form. Fixes: #1282 This is a continuation of a PR ([#1176](#1176)) provided by Alexander, so wanted to include them as a co-author because of their initial work. Co-authored-by: Alexander Lyon <arlyon@me.com>
a813b2e
to
f6368a8
Compare
Enter
for form submit in RadioGroup
, Switch
and Combobox
improvements
When the Combobox is closed, then the
Enter
keydown event will be ignored and thus not useevent.preventDefault()
.With recent changes where we always have an active option, it means that you will always be able to select an option.
If we have no option at all (some edge case) or when the combobox is closed, then the
Enter
keydown event will just bubble, allowing you to submit a form.Fixes: #1282
This is a continuation of a PR (#1176) provided by Alexander, so wanted to include them as a co-author because of their initial work.
This also applies a few more form related improvements.
display: none
to theVisuallyHidden
component, otherwise even with thehidden
andreadOnly
attributes it is still focusable...Enter
on other form related elements.