Skip to content

Svelte 5: Include event modifiers previously found pre svelte 5 as functions available from the svelte library #11458

@JacobSilasBentley

Description

@JacobSilasBentley

Describe the problem

I would like for the functionality of event modifiers previously available before svelte 5 for example 'click', 'once' and 'preventDefault' (shown below) to be readily available in svelte 5.

<button on:click|once|preventDefault={handler}>...</button>

Describe the proposed solution

In the preview documentation it suggests creating functions to replace event modifiers.

So the following:

<button on:once|preventDefault={handler}>...</button>

would be rewritten as:

<button onclick={once(preventDefault(handler))}>...</button>

In my opinion, it would be nice if these functions were available from the svelte library itself rather than having to write them independently. This would bring parity between svelte 4 in and svelte 5 for this feature and help minimise work needed for migration.

I understand the addition of these functions needs to be considered against the trade-off of additional bloat to the library, especially as these are relatively quick and simple functions to write (though ensuring the typing is correct adds some difficulty in my experience).

I would be happy to put in a PR for the change if it is deemed a worthwhile addition.

Importance

nice to have

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