From 5228a764685e8764585aedc7c4f94fdc544375e0 Mon Sep 17 00:00:00 2001 From: mathieu Date: Sat, 16 May 2026 21:33:33 +0200 Subject: [PATCH] fix(hosts,applications): fix modal re-open bug and autofocus first field Move the add-modal auto-close Effect from each modal component to its parent page component. This prevents the stale-value re-trigger bug where the Effect would immediately close the modal on second open because action.value() still held the previous Ok result. Also add autofocus on the first input field of each add modal using NodeRef so the user can start typing immediately on open. Co-Authored-By: Claude Sonnet 4.6 --- src/client/applications.rs | 22 ++++++++++++++++++++-- src/client/hosts.rs | 22 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/client/applications.rs b/src/client/applications.rs index e5cd526..8fc67d8 100644 --- a/src/client/applications.rs +++ b/src/client/applications.rs @@ -8,6 +8,7 @@ use leptos::prelude::*; use leptos::form::ActionForm; +use leptos::html::Input; use crate::api::applications::{ ApplicationWithCounts, CreateApplication, DeleteApplication, @@ -21,9 +22,12 @@ fn AddApplicationModal( create_action: ServerAction, show_modal: RwSignal, ) -> impl IntoView { + let name_ref = NodeRef::::new(); + + // Focus the name field as soon as the modal is mounted. Effect::new(move |_| { - if let Some(Ok(_)) = create_action.value().get() { - show_modal.set(false); + if let Some(el) = name_ref.get() { + let _ = el.focus(); } }); @@ -43,6 +47,7 @@ fn AddApplicationModal(