Click events are triggered with 'enter' keyPress events inside forms
See original GitHub issueTriggering a keypress enter
event inside a form input type=text
that has also has a button
with a click listener without a defined type
will result in a SyntheticMouseEvent click
on that button and hit the clickHandler. Adding a type
will prevent this behavior.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:27
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Trigger a button click with JavaScript on the Enter key in a text ...
I've tweaked your code adding event.preventDefault(); before invoking click(); function while my page has a form and I've switched keyup with keypress as...
Read more >How To Trigger Button Click on Enter - W3Schools
Trigger a Button Click on Enter. Press the "Enter" key inside the input field to trigger the button: Button. Example.
Read more >Handling Events :: Eloquent JavaScript
Pressing a key fires "keydown" and "keyup" events. Pressing a mouse button fires "mousedown" , "mouseup" , and "click" events. Moving the mouse...
Read more >Element: keydown event - Web APIs | MDN
The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, ...
Read more >Keyboard: keydown and keyup - The Modern JavaScript Tutorial
The keydown events happens when a key is pressed down, and then keyup – when it's released. event.code and event.key. The key property...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
buttons are
type="submit"
by default in HTML, and pressing enter simulates a click on the button. This is standard HTML behavior, not specific to React.It’s actually on the event. Not the target. The following follows the correct pattern to descern the difference between a click event and a return event on a button.