Skip to content

Add support for attaching event listeners to the global window #2405

@vultix

Description

@vultix

Feature Request

It's common to want to attach event listeners to the global window. For example, a custom slider element will want to listen to mousedown locally on the slider, but mousemove globally on the window.

Svelte has a svelte:window special element for exactly these use cases.

Implement Suggestion

Taking a cue from svelte, we could add something like a window special element that events can be attached to:

rsx! {
    dioxus:window {
        onmousemove: move |event| handle_mousemove(event)
    }
    div {
        id: "slider",
        onmousedown: move |event| handle_mousedown(event),
        ...
    }
}

We could also introduce a new use_window_event hook or something similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions