Browse Source

feat: add a default enter action for modal

Weihua Lu 4 years ago
parent
commit
b41322d3f4
2 changed files with 14 additions and 5 deletions
  1. 1 0
      src/main/frontend/handler/events.cljs
  2. 13 5
      src/main/frontend/ui.cljs

+ 1 - 0
src/main/frontend/handler/events.cljs

@@ -76,6 +76,7 @@
         [:b (config/get-local-dir repo)]]
        (ui/button
         "Grant"
+        :class "ui__modal-enter"
         :on-click (fn []
                     (nfs/check-directory-permission! repo)
                     (close-fn)))])))

+ 13 - 5
src/main/frontend/ui.cljs

@@ -118,13 +118,13 @@
        (merge
         {:type  "button"
          :class (str (util/hiccup->class klass) " " class)}
-        (dissoc option :background))
+        (dissoc option :background :class))
        text]
       [:button.ui__button
        (merge
         {:type  "button"
          :class (str (util/hiccup->class klass) " " class)}
-        (dissoc option :background))
+        (dissoc option :background :class))
        text])))
 
 (rum/defc notification-content
@@ -413,9 +413,17 @@
      (mixins/hide-when-esc-or-outside
       state
       :on-hide (fn []
-                 (-> (.querySelector (rum/dom-node state) "button.ui__modal-close")
-                     (.click)))
-      :outside? false)))
+                 (some->
+                  (.querySelector (rum/dom-node state) "button.ui__modal-close")
+                  (.click)))
+      :outside? false)
+     (mixins/on-key-down
+      state
+      {;; enter
+       13 (fn [state e]
+            (some->
+             (.querySelector (rum/dom-node state) "button.ui__modal-enter")
+             (.click)))})))
   []
   (let [modal-panel-content (state/sub :modal/panel-content)
         fullscreen? (state/sub :modal/fullscreen?)