Skip to content

Stimulus action @window or @document equilvalent?  #311

@100phlecs

Description

@100phlecs

I noticed in the guides as well as the bind.ts tests that one cannot register actions to listen to global events.

What's the catalyst way of solving this?

For example, one may want to listen for a scroll event in the global scope, or a global event from a library like Turbo, such as turbo:before-visit@window to persist state changes between HTML pages that have the same custom element. I also use it to register window keybindings for when the custom element will not be in focus.

One could very well register it within the custom element with window.addEventListener -- but one of the main things attractive about Stimulus is that it handles event registration and destruction for you

Are there plans to support this, or if not, what is your suggested strategy for dealing with event listeners on the global scope?

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