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

+27
View File
@@ -94,6 +94,33 @@ impl RenderedElementBacking for LiveviewElement {
})
}
fn scroll(
&self,
coordinates: PixelsVector2D,
behavior: dioxus_html::ScrollBehavior,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = MountedResult<()>>>> {
let script = format!(
"return window.interpreter.scroll({}, {}, {}, {});",
self.id.0,
coordinates.x,
coordinates.y,
serde_json::to_string(&behavior).expect("Failed to serialize ScrollBehavior")
);
let fut = self.query.new_query::<bool>(&script).resolve();
Box::pin(async move {
match fut.await {
Ok(true) => Ok(()),
Ok(false) => MountedResult::Err(dioxus_html::MountedError::OperationFailed(
Box::new(DesktopQueryError::FailedToQuery),
)),
Err(err) => {
MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err)))
}
}
})
}
fn set_focus(
&self,
focus: bool,