feat(html): add scroll method to MountedData (#3722)

* feat(html): add `scroll` method to MountedData

* feat(desktop): implement `scroll` method for DesktopElement

* feat(liveview): implement `scroll` method for LiveviewElement

* feat(web): implement `scroll` method for web_sys::Element

* docs(examples): add new example for `scroll` method

* fix(web): remove unncecessary f64 cast (clippy)

* fix(interpreter): return missing boolean from js

* docs(example): unwrap result instead of discarding its error

* docs(examples): create scroll restoring example on routing

* fix clippy

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Youn MéloisandJonathan Kelley authored and GitHub committed 2025-05-07 12:45:47 -07:00
1 parent 60c1b0ead6
commit 85b373deff
11 files changed
+757 -607

No files matched your search

+21
View File
@@ -83,6 +83,27 @@ impl dioxus_html::RenderedElementBacking for Synthetic<web_sys::Element> {
Box::pin(async { Ok(()) })
}
fn scroll(
&self,
coordinates: dioxus_html::geometry::PixelsVector2D,
behavior: dioxus_html::ScrollBehavior,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = dioxus_html::MountedResult<()>>>> {
let options = web_sys::ScrollToOptions::new();
options.set_top(coordinates.y);
options.set_left(coordinates.x);
match behavior {
dioxus_html::ScrollBehavior::Instant => {
options.set_behavior(web_sys::ScrollBehavior::Instant);
}
dioxus_html::ScrollBehavior::Smooth => {
options.set_behavior(web_sys::ScrollBehavior::Smooth);
}
}
self.event.scroll_with_scroll_to_options(&options);
Box::pin(async { Ok(()) })
}
fn set_focus(
&self,
focus: bool,