Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vultix opened this issue May 10, 2024 · 2 comments
Open

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

vultix opened this issue May 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@vultix
Copy link

vultix commented May 10, 2024

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.

@DogeDark
Copy link
Member

On the desktop platform there is use_wry_event_handler. We use it in SDK here. I don't believe anything similar exists for Web though, aside from using the web-sys crate.

@ealmloff
Copy link
Member

There is some overlap with #628, and #1169. Some way to attach attributes/listeners to somewhere outside of children in Dioxus unlocks a bunch of new usecases

@ealmloff ealmloff added the enhancement New feature or request label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants