From 7b29f7da377ed7893fe5237625148138194f23a9 Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:20:00 +0800 Subject: [PATCH] fix: the position is messed up when switching DatePicker panels (#240) --- thaw/src/date_picker/panel/date_panel.rs | 13 ++++++-- thaw/src/date_picker/panel/month_panel.rs | 14 +++++++-- thaw/src/date_picker/panel/year_panel.rs | 13 ++++++-- thaw_components/src/binder/mod.rs | 38 +++++++++++++++++------ thaw_components/src/lib.rs | 2 +- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/thaw/src/date_picker/panel/date_panel.rs b/thaw/src/date_picker/panel/date_panel.rs index abb6d31..1757803 100644 --- a/thaw/src/date_picker/panel/date_panel.rs +++ b/thaw/src/date_picker/panel/date_panel.rs @@ -1,8 +1,9 @@ use super::PanelVariant; use crate::{Button, ButtonAppearance, ButtonSize, CalendarItemDate}; use chrono::{Datelike, Days, Month, Months, NaiveDate}; -use leptos::prelude::*; +use leptos::{html, prelude::*}; use std::ops::Deref; +use thaw_components::FollowerInjection; use thaw_utils::{now_date, ArcOneCallback}; #[component] @@ -12,6 +13,14 @@ pub fn DatePanel( close_panel: ArcOneCallback>, panel_variant: RwSignal, ) -> impl IntoView { + let follower = FollowerInjection::expect_context(); + let panel_ref = NodeRef::::new(); + Effect::new(move || { + let Some(_) = panel_ref.get() else { + return; + }; + follower.refresh_position(); + }); let dates = Memo::new(move |_| { let show_date = show_date.get(); let show_date_month = show_date.month(); @@ -87,7 +96,7 @@ pub fn DatePanel( } }; view! { -
+