From 134265094cbf117c8903c69fb41da22eb079eb70 Mon Sep 17 00:00:00 2001 From: Eva Date: Wed, 30 Mar 2022 11:23:27 +0200 Subject: [PATCH] :bug: Avoid numeric inputs to allow big numbers --- CHANGES.md | 1 + .../app/main/ui/components/numeric_input.cljs | 58 +++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6a8276cdd..c457ec5cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -42,6 +42,7 @@ ### :bug: Bugs fixed +- Avoid numeric inputs to allow big numbers [Taiga #2858](https://tree.taiga.io/project/penpot/issue/2858) - Fix component contex menu size [Taiga #2480](https://tree.taiga.io/project/penpot/issue/2480) - Add shadow to artboard make it lose the fill [Taiga #3139](https://tree.taiga.io/project/penpot/issue/3139) - Avoid numeric inputs to change its value without focusing them [Taiga #3140](https://tree.taiga.io/project/penpot/issue/3140) diff --git a/frontend/src/app/main/ui/components/numeric_input.cljs b/frontend/src/app/main/ui/components/numeric_input.cljs index ed7f3e56c..51300cfb6 100644 --- a/frontend/src/app/main/ui/components/numeric_input.cljs +++ b/frontend/src/app/main/ui/components/numeric_input.cljs @@ -73,44 +73,44 @@ parse-value (mf/use-callback - (mf/deps ref min-val max-val value nillable default-val) - (fn [] - (let [input-node (mf/ref-val ref) - new-value (-> (dom/get-value input-node) - (str/strip-suffix ".") - (sm/expr-eval value))] - (cond - (d/num? new-value) - (-> new-value - (cljs.core/max us/min-safe-int) - (cljs.core/min us/max-safe-int) - (cond-> - (d/num? min-val) - (cljs.core/max min-val) + (mf/deps ref min-val max-val value nillable default-val) + (fn [] + (let [input-node (mf/ref-val ref) + new-value (-> (dom/get-value input-node) + (str/strip-suffix ".") + (sm/expr-eval value))] + (cond + (d/num? new-value) + (-> new-value + (cljs.core/max (/ us/min-safe-int 2)) + (cljs.core/min (/ us/max-safe-int 2)) + (cond-> + (d/num? min-val) + (cljs.core/max min-val) - (d/num? max-val) - (cljs.core/min max-val))) + (d/num? max-val) + (cljs.core/min max-val))) - nillable - default-val + nillable + default-val - :else value)))) + :else value)))) update-input (mf/use-callback - (mf/deps ref) - (fn [new-value] - (let [input-node (mf/ref-val ref)] - (dom/set-value! input-node (fmt/format-number new-value))))) + (mf/deps ref) + (fn [new-value] + (let [input-node (mf/ref-val ref)] + (dom/set-value! input-node (fmt/format-number new-value))))) apply-value (mf/use-callback - (mf/deps on-change update-input value) - (fn [new-value] - (mf/set-ref-val! dirty-ref false) - (when (and (not= new-value value) (some? on-change)) - (on-change new-value)) - (update-input new-value))) + (mf/deps on-change update-input value) + (fn [new-value] + (mf/set-ref-val! dirty-ref false) + (when (and (not= new-value value) (some? on-change)) + (on-change new-value)) + (update-input new-value))) set-delta (mf/use-callback