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

+19
View File
@@ -39,6 +39,15 @@ pub trait RenderedElementBacking: std::any::Any {
Box::pin(async { Err(MountedError::NotSupported) })
}
/// Scroll to the given element offsets
fn scroll(
&self,
_coordinates: PixelsVector2D,
_behavior: ScrollBehavior,
) -> Pin<Box<dyn Future<Output = MountedResult<()>>>> {
Box::pin(async { Err(MountedError::NotSupported) })
}
/// Set the focus on the element
fn set_focus(&self, _focus: bool) -> Pin<Box<dyn Future<Output = MountedResult<()>>>> {
Box::pin(async { Err(MountedError::NotSupported) })
@@ -119,6 +128,16 @@ impl MountedData {
self.inner.scroll_to(behavior)
}
/// Scroll to the given element offsets
#[doc(alias = "scrollTo")]
pub fn scroll(
&self,
coordinates: PixelsVector2D,
behavior: ScrollBehavior,
) -> Pin<Box<dyn Future<Output = MountedResult<()>>>> {
self.inner.scroll(coordinates, behavior)
}
/// Set the focus on the element
#[doc(alias = "focus")]
#[doc(alias = "blur")]