enhance(ux): support enter key shortcut for the shui button

pull/11055/head
charlie 2024-03-14 14:36:37 +08:00
parent b625bf555e
commit c74f1749c8
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
(ns logseq.shui.base.core
(:require [logseq.shui.util :as util]
[rum.core :as rum]))
(def button-base (util/lsui-wrap "Button" {:static? false}))
(def link (util/lsui-wrap "Link"))
;; Note: don't define component with rum/defc
;; to be compatible for the radix as-child option
(defn button
[& props-and-children]
(let [props (first props-and-children)
children (rest props-and-children)
on-key-up' (:on-key-up props)
children (if (map? props) children (cons props children))
props (assoc (if (map? props) props {})
:on-key-up (fn [^js e]
;; TODO: return value
(when (fn? on-key-up') (on-key-up' e))
(when (= "Enter" (.-key e))
(some-> (.-target e) (.click)))))]
(apply button-base props children)))