Skip to content

Add new event modifier 'self' #3372

Closed
Closed
@samuelgozi

Description

@samuelgozi

Is your feature request related to a problem? Please describe.
Event modifiers are long to type, and they could use shorter names or aliases, and in addition, it would be very helpful to have an additional self modifier that is very common.

Describe the solution you'd like
I would like to have the next aliases (inspiration from vue) for the modifiers:
stop as an alias for stopPropagation and prevent as an alias for preventDefault.

In addition, I would like to have a self modifier, that essentially checks that the clicked element is the one on which I added the event listener.

Describe alternatives you've considered
For the self modifier:

<script context="module">
        let el;
	function closeMenu(e) {
		if (e.target !== el) return;
                ...do stuff...
	}
</script>

<div bind:this={el} on:click|stopPropagation={doSomething}>
...
</div>

How important is this feature to you?
Events are at the very core of every reactive web app, I think that making it a little bit easier to use, is very important. In addition, It shouldn't be hard to do.

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