From bc8c326c91d6dbdf547b26c68a29911611835a76 Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:56:18 +0800 Subject: [PATCH] fix: TimePicker scroll problem (#180) --- demo/src/components/switch_version.rs | 1 + thaw/src/scrollbar/mod.rs | 10 ++++ thaw/src/time_picker/mod.rs | 68 +++++++++++++++------------ 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/demo/src/components/switch_version.rs b/demo/src/components/switch_version.rs index c78933f..2c36d21 100644 --- a/demo/src/components/switch_version.rs +++ b/demo/src/components/switch_version.rs @@ -5,6 +5,7 @@ use thaw::*; pub fn SwitchVersion() -> impl IntoView { let options = vec![ SelectOption::new("main", "https://thawui.vercel.app".into()), + SelectOption::new("0.3.0", "https://thaw-gxcwse9r5-thaw.vercel.app".into()), SelectOption::new("0.2.6", "https://thaw-mzh1656cm-thaw.vercel.app".into()), SelectOption::new("0.2.5", "https://thaw-8og1kv8zs-thaw.vercel.app".into()), ]; diff --git a/thaw/src/scrollbar/mod.rs b/thaw/src/scrollbar/mod.rs index 6b801ab..d51c1b2 100644 --- a/thaw/src/scrollbar/mod.rs +++ b/thaw/src/scrollbar/mod.rs @@ -53,6 +53,8 @@ pub fn Scrollbar( if let Some(comp_ref) = comp_ref { comp_ref.load(ScrollbarRef { container_scroll_top, + container_ref, + content_ref, }); } @@ -335,10 +337,18 @@ enum ThumbStatus { #[derive(Clone)] pub struct ScrollbarRef { container_scroll_top: RwSignal, + container_ref: NodeRef, + pub content_ref: NodeRef, } impl ScrollbarRef { pub fn container_scroll_top(&self) -> i32 { self.container_scroll_top.get_untracked() } + + pub fn scroll_to_with_scroll_to_options(&self, options: &web_sys::ScrollToOptions) { + if let Some(el) = self.container_ref.get_untracked() { + el.scroll_to_with_scroll_to_options(options); + } + } } diff --git a/thaw/src/time_picker/mod.rs b/thaw/src/time_picker/mod.rs index 52df461..31d1319 100644 --- a/thaw/src/time_picker/mod.rs +++ b/thaw/src/time_picker/mod.rs @@ -3,8 +3,8 @@ mod theme; pub use theme::TimePickerTheme; use crate::{ - use_theme, Button, ButtonSize, ButtonVariant, Icon, Input, InputSuffix, Scrollbar, SignalWatch, - Theme, + use_theme, Button, ButtonSize, ButtonVariant, Icon, Input, InputSuffix, Scrollbar, + ScrollbarRef, SignalWatch, Theme, }; use chrono::{Local, NaiveTime, Timelike}; use leptos::*; @@ -165,9 +165,9 @@ fn Panel( _ = panel_ref; } - let hour_ref = create_node_ref::(); - let minute_ref = create_node_ref::(); - let second_ref = create_node_ref::(); + let hour_ref = ComponentRef::::new(); + let minute_ref = ComponentRef::::new(); + let second_ref = ComponentRef::::new(); comp_ref.load(PanelRef { hour_ref, minute_ref, @@ -188,8 +188,8 @@ fn Panel( ref=panel_ref >
-
- +
+ {(0..24) .map(|hour| { let comp_ref = ComponentRef::::default(); @@ -217,11 +217,11 @@ fn Panel( } }) .collect_view()} +
-
-
- +
+ {(0..60) .map(|minute| { let comp_ref = ComponentRef::::default(); @@ -249,11 +249,11 @@ fn Panel( } }) .collect_view()} +
-
-
- +
+ {(0..60) .map(|second| { let comp_ref = ComponentRef::::default(); @@ -281,8 +281,8 @@ fn Panel( } }) .collect_view()} +
-