Add support for attaching event listeners to the global window
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.
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.
There is some overlap with https://github.com/DioxusLabs/dioxus/issues/628, and https://github.com/DioxusLabs/dioxus/issues/1169. Some way to attach attributes/listeners to somewhere outside of children in Dioxus unlocks a bunch of new usecases