瀏覽代碼

fix: date picker needs defaultMonth

Tienson Qin 1 年之前
父節點
當前提交
62986bc080
共有 1 個文件被更改,包括 19 次插入14 次删除
  1. 19 14
      src/main/frontend/components/property/value.cljs

+ 19 - 14
src/main/frontend/components/property/value.cljs

@@ -83,8 +83,10 @@
                  (try
                    (tc/to-local-date value)
                    (catch :default e
-                     (js/console.error e))))]
-
+                     (js/console.error e))))
+        initial-day (some-> value' (.getTime) (js/Date.))
+        initial-month (when value'
+                        (js/Date. (.getYear value') (.getMonth value')))]
     (shui/dropdown-menu
      {:open open?}
      (shui/dropdown-menu-trigger
@@ -108,19 +110,22 @@
        :onEscapeKeyDown #(set-open! false)}
       (shui/calendar
        {:mode "single"
-        :selected (some-> value' (.getTime) (js/Date.))
+        :initial-focus true
+        :selected initial-day
+        :default-month initial-month
         :on-select (fn [^js d]
-                            ;; force local to UTC
-                     (let [gd (goog.date.Date. (.getFullYear d) (.getMonth d) (.getDate d))]
-                       (let [journal (date/js-date->journal-title gd)]
-                         (p/do!
-                          (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
-                            (page-handler/<create! journal {:redirect? false
-                                                            :create-first-block? false}))
-                          (when (fn? on-change)
-                            (on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
-                          (set-open! false)
-                          (exit-edit-property)))))})))))
+                     ;; force local to UTC
+                     (when d
+                       (let [gd (goog.date.Date. (.getFullYear d) (.getMonth d) (.getDate d))]
+                         (let [journal (date/js-date->journal-title gd)]
+                           (p/do!
+                            (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
+                              (page-handler/<create! journal {:redirect? false
+                                                              :create-first-block? false}))
+                            (when (fn? on-change)
+                              (on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
+                            (set-open! false)
+                            (exit-edit-property))))))})))))
 
 
 (rum/defc property-value-date-picker