Skip to content

Commit

Permalink
Don't call on-click when a tab or ratio button is already selected
Browse files Browse the repository at this point in the history
Fixes #333
  • Loading branch information
kimo-k committed Nov 22, 2023
1 parent 3662373 commit f3d4fcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/re_com/radio_button.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -69,7 +70,7 @@
style)
:type "radio"
:disabled disabled?
:checked (= model value)
:checked checked?
:on-change (handler-fn (callback-fn))}
attr)]
(when label
Expand All @@ -80,4 +81,4 @@
:cursor cursor}
label-style)
:on-click (handler-fn (callback-fn))}
label])]])))
label])]])))
3 changes: 2 additions & 1 deletion src/re_com/tabs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 %) %)))})
Expand Down

0 comments on commit f3d4fcc

Please sign in to comment.