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)]
(when index
(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)
(d/add-class! target "ls-popup-closed")
(.focus target))))))
(when-let [target (if trigger-id (js/document.getElementById trigger-id) target)]
(d/add-class! target "ls-popup-closed")
(.focus target)))))))
(defn show!
[^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)
position (cond
(vector? event) event
@ -97,6 +98,7 @@
(upsert-popup!
(merge opts
{:id (or id (gen-id)) :target (deref *target)
:trigger-id trigger-id
:open? true :content content :position position
:as-dropdown? as-dropdown?
:as-content? as-content?

View File

@ -251,22 +251,14 @@
distinct)]
(if (seq values')
(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
property
nil
(assoc opts :on-save
(fn [value icon description]
(<upsert-closed-value! property {:value value
:description description
:icon icon}))))))))
(item-config
property
nil
(assoc opts :on-save
(fn [value icon description]
(<upsert-closed-value! property {:value value
:description description
:icon icon})))))))
{:content-props {:class "w-auto"}})))}
(ui/icon "plus" {:size 16})
"Add choice"))]))

View File

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