From ae8dd4d3927713a8b90098d6219e0694370518c7 Mon Sep 17 00:00:00 2001 From: Danielle Huisman Date: Mon, 1 Apr 2024 16:01:59 +0200 Subject: [PATCH] Attempt to fix use_scroll behaviour --- packages/leptos/tests/visual/src/spec/arrow.rs | 14 +++++++++++++- .../leptos/tests/visual/src/spec/auto_placement.rs | 1 + packages/leptos/tests/visual/src/spec/scroll.rs | 1 + .../leptos/tests/visual/src/utils/use_scroll.rs | 11 +++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/leptos/tests/visual/src/spec/arrow.rs b/packages/leptos/tests/visual/src/spec/arrow.rs index 83585c2..0472338 100644 --- a/packages/leptos/tests/visual/src/spec/arrow.rs +++ b/packages/leptos/tests/visual/src/spec/arrow.rs @@ -69,13 +69,25 @@ pub fn Arrow() -> impl IntoView { let arrow_y = move || arrow_data().and_then(|arrow_data| arrow_data.y); let center_offset_value = move || arrow_data().map(|arrow_data| arrow_data.center_offset); - let UseScrollReturn { scroll_ref, .. } = use_scroll(UseScrollOptions { + let UseScrollReturn { + scroll_ref, + update_scroll, + .. + } = use_scroll(UseScrollOptions { reference_ref, floating_ref, update, rtl: None, }); + // Match React test behaviour + let placement_update_scroll = update_scroll.clone(); + let padding_update_scroll = update_scroll.clone(); + let add_offset_update_scroll = update_scroll.clone(); + _ = watch(placement, move |_, _, _| placement_update_scroll(), false); + _ = watch(padding, move |_, _, _| padding_update_scroll(), false); + _ = watch(add_offset, move |_, _, _| add_offset_update_scroll(), false); + view! {

Arrow

diff --git a/packages/leptos/tests/visual/src/spec/auto_placement.rs b/packages/leptos/tests/visual/src/spec/auto_placement.rs index 3d6b8ee..e78ca3c 100644 --- a/packages/leptos/tests/visual/src/spec/auto_placement.rs +++ b/packages/leptos/tests/visual/src/spec/auto_placement.rs @@ -84,6 +84,7 @@ pub fn AutoPlacement() -> impl IntoView { let UseScrollReturn { scroll_ref, indicator, + .. } = use_scroll(UseScrollOptions { reference_ref, floating_ref, diff --git a/packages/leptos/tests/visual/src/spec/scroll.rs b/packages/leptos/tests/visual/src/spec/scroll.rs index 38bc5ae..d69001a 100644 --- a/packages/leptos/tests/visual/src/spec/scroll.rs +++ b/packages/leptos/tests/visual/src/spec/scroll.rs @@ -37,6 +37,7 @@ pub fn Scroll() -> impl IntoView { let UseScrollReturn { scroll_ref, indicator, + .. } = use_scroll(UseScrollOptions { reference_ref, floating_ref, diff --git a/packages/leptos/tests/visual/src/utils/use_scroll.rs b/packages/leptos/tests/visual/src/utils/use_scroll.rs index 537d839..bb2f9df 100644 --- a/packages/leptos/tests/visual/src/utils/use_scroll.rs +++ b/packages/leptos/tests/visual/src/utils/use_scroll.rs @@ -19,6 +19,7 @@ pub struct UseScrollOptions { pub struct UseScrollReturn { pub scroll_ref: NodeRef
, pub indicator: Rc HtmlElement
>, + pub update_scroll: Rc, } pub fn use_scroll( @@ -60,6 +61,7 @@ pub fn use_scroll( let (ancestors, set_ancestors) = create_signal::>(vec![]); let (scroll, set_scroll) = create_signal::>(None); + let is_update_required = create_rw_signal(false); let local_update_update = update.clone(); let local_update_indicator_update = indicator_update_rc.clone(); @@ -74,6 +76,10 @@ pub fn use_scroll( let effect_local_update = local_update.clone(); create_effect(move |_| { + if is_update_required.get() { + is_update_required.set_untracked(false); + } + if let Some(reference) = reference_ref() { let mut ancestors = get_overflow_ancestors(&reference, vec![], true); @@ -137,8 +143,13 @@ pub fn use_scroll( } }; + let update_scroll = move || { + is_update_required.set(true); + }; + UseScrollReturn { scroll_ref, indicator: Rc::new(indicator), + update_scroll: Rc::new(update_scroll), } }