fix(ui): prevent button from being clicked twice when pressing enter key

pull/10832/head
situ2001 2024-01-07 14:24:04 +08:00 committed by Tienson Qin
parent ab37d30e2d
commit 38404da920
1 changed files with 17 additions and 3 deletions

View File

@ -1039,9 +1039,23 @@
(defn button
[text & {:keys []
:as opts}]
(if (map? text)
(button-inner nil text)
(button-inner text opts)))
(let [origin-on-key-down (get opts :on-key-down)
class-name (get opts :class)
wrapped-on-key-down (if (and
class-name
;; hint: mixins/on-key-down defined in ui/modal
(string/includes? class-name "ui__modal-enter"))
(fn [e]
(when origin-on-key-down (origin-on-key-down e))
(let [key-code (.-keyCode e)]
(cond
;; enter
(= key-code 13) (util/stop-propagation e))))
origin-on-key-down)
opts (assoc opts :on-key-down wrapped-on-key-down)]
(if (map? text)
(button-inner nil text)
(button-inner text opts))))
(rum/defc point
([] (point "bg-red-600" 5 nil))