From f3d4fccb87f19da4c5261344b3e96caba31deb54 Mon Sep 17 00:00:00 2001 From: Kimo Knowles Date: Wed, 22 Nov 2023 20:15:06 +0100 Subject: [PATCH] Don't call on-click when a tab or ratio button is already selected Fixes #333 --- src/re_com/radio_button.cljs | 9 +++++---- src/re_com/tabs.cljs | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/re_com/radio_button.cljs b/src/re_com/radio_button.cljs index dcec2dbb..ca0269ba 100644 --- a/src/re_com/radio_button.cljs +++ b/src/re_com/radio_button.cljs @@ -51,8 +51,9 @@ (let [cursor "default" model (deref-or-value model) disabled? (deref-or-value disabled?) - callback-fn #(when (and on-change (not disabled?)) - (on-change value))] ;; call on-change with the :value arg + checked? (= model value) + callback-fn #(when (and on-change (not disabled?) (not checked?)) + (on-change value))] [h-box :src src :debug-as (or debug-as (reflect-current-component)) @@ -69,7 +70,7 @@ style) :type "radio" :disabled disabled? - :checked (= model value) + :checked checked? :on-change (handler-fn (callback-fn))} attr)] (when label @@ -80,4 +81,4 @@ :cursor cursor} label-style) :on-click (handler-fn (callback-fn))} - label])]]))) \ No newline at end of file + label])]]))) diff --git a/src/re_com/tabs.cljs b/src/re_com/tabs.cljs index 1d889eb8..e6785024 100644 --- a/src/re_com/tabs.cljs +++ b/src/re_com/tabs.cljs @@ -128,7 +128,8 @@ :key (str id) :class (str "btn btn-default " (if selected? "active ") "rc-tabs-btn " (get-in parts [:button :class])) :style style - :on-click (when on-change (handler-fn (on-change id)))} + :on-click (when (and on-change (not selected?)) + (handler-fn (on-change id)))} (when tooltip {:on-mouse-over (handler-fn (reset! showing id)) :on-mouse-out (handler-fn (swap! showing #(when-not (= id %) %)))})