From 9da8b03de2bd5f791ed3893ae4d485ce00347be5 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 24 Dec 2024 14:27:32 +0300 Subject: [PATCH] feat(maintain focus on cells): maintain focus while typing in cells; in progress --- src/components/editable_cell.rs | 16 +++++++++++++++ src/components/items_list.rs | 36 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/components/editable_cell.rs b/src/components/editable_cell.rs index 72d6c1e..2604931 100644 --- a/src/components/editable_cell.rs +++ b/src/components/editable_cell.rs @@ -4,8 +4,10 @@ use leptos::*; pub fn EditableCell( value: String, on_input: impl Fn(String) + 'static, + #[prop(optional)] key: Option, // Optional `key` prop ) -> impl IntoView { let (input_value, set_input_value) = create_signal(value.clone()); + let (has_focus, set_has_focus) = create_signal(false); // Track focus state locally let handle_input = move |e: web_sys::Event| { let new_value = event_target_value(&e); @@ -13,11 +15,25 @@ pub fn EditableCell( on_input(new_value); }; + let handle_focus = move |_: web_sys::FocusEvent| { + set_has_focus.set(true); + }; + + let handle_blur = move |_: web_sys::FocusEvent| { + set_has_focus.set(false); + }; + + // Use key to force updates only when necessary + let _key = key.unwrap_or_default(); + view! { } } diff --git a/src/components/items_list.rs b/src/components/items_list.rs index 4759a36..b6f8d5e 100644 --- a/src/components/items_list.rs +++ b/src/components/items_list.rs @@ -89,7 +89,7 @@ pub fn ItemsList( name: String::new(), description: String::new(), tags: vec![], - reviews:vec![], + reviews: vec![], wikidata_id: None, }); }); @@ -121,15 +121,15 @@ pub fn ItemsList( // Editable Name Field with Wikidata Integration - +
    {move || { let suggestions = wikidata_suggestions.get().to_vec(); suggestions.into_iter().map(|suggestion| { - // Clone all necessary fields upfront let label_for_click = suggestion.label.clone(); let label_for_display = suggestion.label.clone(); let description_for_click = suggestion.description.clone().unwrap_or_default(); @@ -146,34 +146,34 @@ pub fn ItemsList(
  • - { format!("{} - {}", label_for_display, description_for_display) } // Use the cloned version for display + { format!("{} - {}", label_for_display, description_for_display) }
  • - } - - }).collect::>() + } + }).collect::>() }}
// Editable Description Field - + // Tag Editor // Actions