Skip to content

Add support for keyboard and mouse button modifiers for the on: directive. #4427

@rdytogokev

Description

@rdytogokev

Is your feature request related to a problem? Please describe.
I am coming from Vue.js and really like Svelte and the concepts it promotes.

One feature that Vue offers that I have become spoiled by, however, is their "Key" and "Mouse Button" modifiers for event listeners. I have noticed that Svelte also has modifiers for the on: directive. Which is coded like: on:eventname|modifiers={handler}. This is documented on svelte.dev.

This is great; but when listening for keyboard or mouse-specific events like keyup, keydown, or middle (a mouse button modifier); Vue goes the extra mile by providing additional modifiers that make coding a real pleasure. Here is an example: <input @keyup.enter="doSomething">. Now I don't have to code a keyCode check for the enter key. WooHoo!

An example of how this might look in Svelte is on:keyup.enter={doSomething}. With these nuanced modifiers the lazy spoiled coder that I am no longer has to add this line in my 'doSomething' function: if (event.key !== 'Enter') return;

Describe the solution you'd like
I would love it if all the modifiers that Vue has, could be added to the on: directive. This includes these keyboard modifiers: .enter, .tab, .delete, .esc, .space, .up, .down, .left, .right, .ctrl, .alt, .shift, and .meta
and these mouse button modifiers: .left, .right, and .middle,
as well as the .exact modifier.

The documentation and code can be found here:
Vue Key Modifiers Documentation
Vue System Key Modifiers Documentation
'v-on' API Documentation
'v-on' Source Code

Describe alternatives you've considered
So far I have just hand-coded something like this in the event handler function: if (event.key !== 'Enter'

How important is this feature to you?
This would be a nice extra to have, but I can do without it if you really don't want to provide. It just makes coding in Vue templates a real pleasure. One that I would love to see Svelte rock!

Additional note
I just wanted to take a moment to thank you for all the work you have done and your time considering this request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions