click-events-have-key-events: v-on:keyup.enter already triggers v-on:click event.
See original GitHub issueDescribe the bug
When using a @click
event, I’m prompted to add a @keyup.enter
or other keyboard event. However, this frequently leads to “doubleclicks”, i.e.:
<button @click="doSomething" @keyup.enter="doSomething">
In this example, pressing Enter
triggers both @keyup.enter
and @click
.
To Reproduce Steps to reproduce the behavior:
- Create element with both
@click
and@keyup.enter
- Create function, logging when function is fired by the above.
- Use
Enter
key on element. - Open Developer Tools -> Console.
- See function has fired twice: A keyboard event and a mouse event, if you examine the event.
Expected behavior Following eslint rules shouldn’t cause strange, actual sideeffects.
Desktop (please complete the following information):
- OS: Windows 10
- Browser Chrome
- Version 80.0.3987.132
Additional context In my case, I detect the generated click event and return out of function with:
if(!event.sourceCapabilities) {return}
…or relevant variants where appropriate.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12
Top Results From Across the Web
Jquery: how to trigger click event on pressing enter key
I have used trigger() to execute click and bind it on the keyup event insted of keydown because click event comprises of two...
Read more >Click events are triggered with 'enter' keyPress ... - GitHub
But this issue is not about the button. It's about how a keypress event is magically converted to a click event on the...
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 >JavaScript | Trigger a button on ENTER key - GeeksforGeeks
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This...
Read more >Event Handling - Vue.js
Inline handlers: Inline JavaScript to be executed when the event is triggered (similar to the native onclick attribute). Method handlers: A property name...
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 FreeTop 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
Top GitHub Comments
After some chats with folks on Twiiter, apparently the updated version of this eslint plugin is https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility
A work around I have found is:
Example: https://jsfiddle.net/frscqt0p
Explanation: