From ffb4d6a8907b06e6b4a260fa7fcd3c72bf36e5e4 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 7 Nov 2025 16:17:39 +0100 Subject: [PATCH] :bug: Fix input confirmation behavior is not uniform --- CHANGES.md | 1 + .../main/ui/components/editable_label.cljs | 2 +- .../src/app/main/ui/ds/controls/combobox.cljs | 4 ++- .../main/ui/ds/product/input_with_meta.cljs | 33 ++++++++++++++----- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 023c788c68..53738d3172 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,7 @@ - Fix search shortcut [Taiga #10265](https://tree.taiga.io/project/penpot/issue/10265) - Fix shortcut conflict in text editor (increase/decrease font size vs word selection) - Fix problem with plugins generating code for pages different than current one [Taiga #12312](https://tree.taiga.io/project/penpot/issue/12312) +- Fix input confirmation behavior is not uniform [Taiga #12294](https://tree.taiga.io/project/penpot/issue/12294) ## 2.11.0 (Unreleased) diff --git a/frontend/src/app/main/ui/components/editable_label.cljs b/frontend/src/app/main/ui/components/editable_label.cljs index 95103ddb67..b5d47056f2 100644 --- a/frontend/src/app/main/ui/components/editable_label.cljs +++ b/frontend/src/app/main/ui/components/editable_label.cljs @@ -70,7 +70,7 @@ :default-value value :on-key-up on-key-up :max-length max-input-length - :on-blur cancel-edition}] + :on-blur accept-edition}] [:span {:class [(stl/css :editable-label-text) class-label] :title tooltip} diff --git a/frontend/src/app/main/ui/ds/controls/combobox.cljs b/frontend/src/app/main/ui/ds/controls/combobox.cljs index 80c77dbeec..2f09761ae5 100644 --- a/frontend/src/app/main/ui/ds/controls/combobox.cljs +++ b/frontend/src/app/main/ui/ds/controls/combobox.cljs @@ -202,7 +202,9 @@ dom/get-value)] (reset! selected-id* value) (reset! filter-id* value) - (reset! focused-id* nil)))) + (reset! focused-id* nil) + (when (fn? on-change) + (on-change value))))) selected-option (mf/with-memo [options selected-id] diff --git a/frontend/src/app/main/ui/ds/product/input_with_meta.cljs b/frontend/src/app/main/ui/ds/product/input_with_meta.cljs index 31efcf1bc9..d615f67201 100644 --- a/frontend/src/app/main/ui/ds/product/input_with_meta.cljs +++ b/frontend/src/app/main/ui/ds/product/input_with_meta.cljs @@ -25,20 +25,25 @@ (mf/defc input-with-meta* {::mf/schema schema:input-with-meta} [{:keys [value meta max-length is-editing on-blur] :rest props}] - (let [editing* (mf/use-state (d/nilv is-editing false)) - editing? (deref editing*) + (let [title (if meta (str value ": " meta) value) + editing* (mf/use-state (d/nilv is-editing false)) + editing? (deref editing*) + input-ref (mf/use-ref) + last-node* (mf/use-ref nil) - input-ref (mf/use-ref) - input (mf/ref-val input-ref) - - title (if meta (str value ": " meta) value) + ref-cb (mf/use-fn + (fn [node] + ;; We need to keep the last not-null node for cleanup + (mf/set-ref-val! input-ref node) + (when node + (mf/set-ref-val! last-node* node)))) on-edit (mf/use-fn (fn [event] (dom/stop-propagation event) (reset! editing* true) - (dom/focus! input))) + (dom/focus! (mf/ref-val input-ref)))) on-stop-edit (mf/use-fn @@ -64,7 +69,7 @@ (when ^boolean enter? (dom/blur! node)) (when ^boolean esc? (dom/blur! node))))) - props (mf/spread-props props {:ref input-ref + props (mf/spread-props props {:ref ref-cb :default-value value :max-length (d/nilv max-length max-input-length) :auto-focus true @@ -72,6 +77,18 @@ :on-blur on-stop-edit :on-key-down handle-key-down})] + ;; Cleanup: Simulate a blur event + (mf/with-effect [on-blur last-node*] + (fn [] + (let [input (mf/ref-val last-node*) + fake-blur-event #js {:type "blur" + :target input + :currentTarget input + :stopPropagation (fn []) + :preventDefault (fn [])}] + (when input + (on-blur fake-blur-event))))) + (if editing? [:div {:class (stl/css :input-with-meta-edit-container)} [:> input* props]]