Skip to content

when using on:click or keypress .ect enable what button to listen to #6401

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

Closed
Bradley-H opened this issue Jun 13, 2021 · 1 comment
Closed

Comments

@Bradley-H
Copy link

i'm sorry if this is already enabled I didn't see it in the docs.

Anyhow, I recently used Vue, and I think they had a good idea on quick implementation on what button to listen to. I think Svelte could benefit from this.

right now it's something like this in a function

function riode(e){
if (e.key = "Enter") {
// whatever//
}
}
I think we can just outright scrape the entire if statement and just on the onclick or whatever have

on:keypress|Enter={function} to shorten it entirely.

@Conduitry
Copy link
Member

This has come up before in #3193, #4427, #5795, and maybe others, and has previously been rejected because the number of keystrokes saved really is quite minimal. You can just do on:keypress={(e) => e.key === 'Enter' && whatever()}, which is a lot more explicit, and introduces no new API surface area to document, or test, or fix bugs in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants