From 82eb91a2fe9a8f8020e4f3ce9b241632d2fe79af Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 8 Jan 2025 15:18:00 +0300 Subject: [PATCH] fix(item_list): make the `show_suggestions` signal more specific to each name field --- src/components/items_list.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/items_list.rs b/src/components/items_list.rs index af6e3e2..e518ee7 100644 --- a/src/components/items_list.rs +++ b/src/components/items_list.rs @@ -28,7 +28,7 @@ pub fn ItemsList( let (custom_properties, set_custom_properties) = create_signal(Vec::::new()); // state to manage suggestions visibility - let (show_suggestions, set_show_suggestions) = create_signal(false); + let (show_suggestions, set_show_suggestions) = create_signal(HashMap::::new()); // Ensure there's an initial empty row set_items.set(vec![Item { @@ -181,25 +181,31 @@ pub fn ItemsList( set_focused_cell=set_focused_cell.clone() on_focus=Some(Callback::new(move |_| { log!("Input focused, showing suggestions"); - set_show_suggestions.set(true); + set_show_suggestions.update(|suggestions| { + suggestions.insert(format!("name-{}", index), true); + }); })) on_blur=Some(Callback::new(move |_| { log!("Input blurred, delaying hiding suggestions"); spawn_local(async move { gloo_timers::future::sleep(std::time::Duration::from_millis(500)).await; log!("Hiding suggestions after delay"); - set_show_suggestions.set(false); + set_show_suggestions.update(|suggestions| { + suggestions.insert(format!("name-{}", index), false); + }); }); })) /> {move || { - if show_suggestions.get() { + if *show_suggestions.get().get(&format!("name-{}", index)).unwrap_or(&false) { log!("Rendering suggestions list"); view! {
    @@ -232,7 +238,9 @@ pub fn ItemsList( item.name = label_for_click.clone(); } }); - set_show_suggestions.set(false); + set_show_suggestions.update(|suggestions| { + suggestions.insert(format!("name-{}", index), false); + }); }> { format!("{} - {}", label_for_display, description_for_display) }