fix: use trigger-id instead of target

Because target might already be unmounted
experiment/tanstack-table
Tienson Qin 2024-05-22 20:49:44 +08:00
parent 0dab32c038
commit 5b99610212
3 changed files with 18 additions and 22 deletions

View File

@ -64,14 +64,15 @@
(let [[index config] (get-popup id)] (let [[index config] (get-popup id)]
(when index (when index
(swap! *popups #(->> % (medley/remove-nth index) (vec))) (swap! *popups #(->> % (medley/remove-nth index) (vec)))
(let [{:keys [auto-focus? target]} config] (let [{:keys [auto-focus? target trigger-id]} config]
(when (and auto-focus? target) (when (and auto-focus? target)
(when-let [target (if trigger-id (js/document.getElementById trigger-id) target)]
(d/add-class! target "ls-popup-closed") (d/add-class! target "ls-popup-closed")
(.focus target)))))) (.focus target)))))))
(defn show! (defn show!
[^js event content & {:keys [id as-dropdown? as-content? align root-props content-props [^js event content & {:keys [id as-dropdown? as-content? align root-props content-props
on-before-hide on-after-hide] :as opts}] on-before-hide on-after-hide trigger-id] :as opts}]
(let [*target (volatile! nil) (let [*target (volatile! nil)
position (cond position (cond
(vector? event) event (vector? event) event
@ -97,6 +98,7 @@
(upsert-popup! (upsert-popup!
(merge opts (merge opts
{:id (or id (gen-id)) :target (deref *target) {:id (or id (gen-id)) :target (deref *target)
:trigger-id trigger-id
:open? true :content content :position position :open? true :content content :position position
:as-dropdown? as-dropdown? :as-dropdown? as-dropdown?
:as-content? as-content? :as-content? as-content?

View File

@ -251,14 +251,6 @@
distinct)] distinct)]
(if (seq values') (if (seq values')
(add-existing-values property values' opts) (add-existing-values property values' opts)
(if (= :page property-type)
(property-value/select-page property
{:multiple-choices? false
:dropdown? false
:close-modal? false
:on-chosen (fn [chosen]
(p/let [_closed-value (<upsert-closed-value! property {:value chosen})]
(shui/popup-hide! id)))})
(item-config (item-config
property property
nil nil
@ -266,7 +258,7 @@
(fn [value icon description] (fn [value icon description]
(<upsert-closed-value! property {:value value (<upsert-closed-value! property {:value value
:description description :description description
:icon icon})))))))) :icon icon})))))))
{:content-props {:class "w-auto"}})))} {:content-props {:class "w-auto"}})))}
(ui/icon "plus" {:size 16}) (ui/icon "plus" {:size 16})
"Add choice"))])) "Add choice"))]))

View File

@ -64,7 +64,6 @@
[] []
(state/set-state! :editor/new-property-key nil) (state/set-state! :editor/new-property-key nil)
(state/set-state! :editor/new-property-input-id nil) (state/set-state! :editor/new-property-input-id nil)
(state/set-state! :editor/properties nil)
(state/clear-edit!)) (state/clear-edit!))
(defn <create-new-block! (defn <create-new-block!
@ -625,15 +624,18 @@
(:object :page :date) (:object :page :date)
(property-value-select-page block property select-opts' opts))]) (property-value-select-page block property select-opts' opts))])
trigger-id (str "trigger-" (:container-id opts) "-" (:db/id block) "-" (:db/id property))
show! (fn [target] show! (fn [target]
(when-not (or (util/link? target) (.closest target "a") config/publishing?) (when-not (or (util/link? target) (.closest target "a") config/publishing?)
(shui/popup-show! target popup-content (shui/popup-show! target popup-content
{:align "start" {:align "start"
:as-dropdown? true :as-dropdown? true
:auto-focus? true})))] :auto-focus? true
:trigger-id trigger-id})))]
(shui/trigger-as (shui/trigger-as
:div.jtrigger.flex.flex-1.w-full :div.jtrigger.flex.flex-1.w-full
{:ref *el {:ref *el
:id trigger-id
:tabIndex 0 :tabIndex 0
:on-click #(show! (.-target %))} :on-click #(show! (.-target %))}
(if (string/blank? value) (if (string/blank? value)