[Combobox] How to prevent submit on enter #10202
Unanswered
saltnpixels
asked this question in
Q&A
Replies: 3 comments 1 reply
-
You can prevent the form submission by handling the onKeyDown event on the Combobox input: <form onSubmit={handleSubmit}>
<Combobox.Root collection={collection}>
<Combobox.Control>
<Combobox.Input
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.stopPropagation() // Prevents the event from bubbling to the form
}
}}
/>
</Combobox.Control>
<Combobox.Content>
{/* items */}
</Combobox.Content>
</Combobox.Root>
<button type="submit">Submit</button>
</form> |
Beta Was this translation helpful? Give feedback.
1 reply
-
yeah thats not working...i spent 3 hours trying everything. nothing works. |
Beta Was this translation helpful? Give feedback.
0 replies
-
well this worked |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
When I tried to use the combobox in a form and i was testing the arrow keys and pressed enter on an item it submits the form unlike the Select field. Is this intentional and can it be stopped?
Link to Reproduction
none
Steps to reproduce
No response
Chakra UI Version
3.21.0
Browser
No response
Operating System
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions