From 5b99610212a4b221d1c256037b816a9f072786f3 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 22 May 2024 20:49:44 +0800 Subject: [PATCH] fix: use trigger-id instead of target Because target might already be unmounted --- deps/shui/src/logseq/shui/popup/core.cljs | 10 ++++---- .../components/property/closed_value.cljs | 24 +++++++------------ .../frontend/components/property/value.cljs | 6 +++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/deps/shui/src/logseq/shui/popup/core.cljs b/deps/shui/src/logseq/shui/popup/core.cljs index d7f9f5b75..57077123c 100644 --- a/deps/shui/src/logseq/shui/popup/core.cljs +++ b/deps/shui/src/logseq/shui/popup/core.cljs @@ -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? diff --git a/src/main/frontend/components/property/closed_value.cljs b/src/main/frontend/components/property/closed_value.cljs index c36a76ff7..da66a24fa 100644 --- a/src/main/frontend/components/property/closed_value.cljs +++ b/src/main/frontend/components/property/closed_value.cljs @@ -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 (