mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 12:21:38 +02:00
🐛 Fix incorrect event handling on dropdown menu
Related to react18 event handling new behavior
This commit is contained in:
parent
27534702fb
commit
cf2ee435c0
1 changed files with 19 additions and 16 deletions
|
@ -10,6 +10,7 @@
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :as globals]
|
||||||
[app.util.keyboard :as kbd]
|
[app.util.keyboard :as kbd]
|
||||||
|
[app.util.timers :as tm]
|
||||||
[goog.events :as events]
|
[goog.events :as events]
|
||||||
[goog.object :as gobj]
|
[goog.object :as gobj]
|
||||||
[rumext.v2 :as mf])
|
[rumext.v2 :as mf])
|
||||||
|
@ -18,24 +19,26 @@
|
||||||
(mf/defc dropdown'
|
(mf/defc dropdown'
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [children (gobj/get props "children")
|
(let [children (gobj/get props "children")
|
||||||
on-close (gobj/get props "on-close")
|
on-close (gobj/get props "on-close")
|
||||||
ref (gobj/get props "container")
|
container-ref (gobj/get props "container")
|
||||||
|
listening-ref (mf/use-ref nil)
|
||||||
|
|
||||||
on-click
|
on-click
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [target (dom/get-target event)
|
(when (mf/ref-val listening-ref)
|
||||||
|
(let [target (dom/get-target event)
|
||||||
|
|
||||||
;; MacOS ctrl+click sends two events: context-menu and click.
|
;; MacOS ctrl+click sends two events: context-menu and click.
|
||||||
;; In order to not have two handlings we ignore ctrl+click for this platform
|
;; In order to not have two handlings we ignore ctrl+click for this platform
|
||||||
mac-ctrl-click? (and (cfg/check-platform? :macos) (kbd/ctrl? event))]
|
mac-ctrl-click? (and (cfg/check-platform? :macos) (kbd/ctrl? event))]
|
||||||
(when (and (not mac-ctrl-click?)
|
(when (and (not mac-ctrl-click?)
|
||||||
(not (.-data-no-close ^js target)))
|
(not (.-data-no-close ^js target)))
|
||||||
(if ref
|
(if container-ref
|
||||||
(let [parent (mf/ref-val ref)]
|
(let [parent (mf/ref-val container-ref)]
|
||||||
(when-not (or (not parent) (.contains parent target))
|
(when-not (or (not parent) (.contains parent target))
|
||||||
(on-close)))
|
(on-close)))
|
||||||
(on-close)))))
|
(on-close))))))
|
||||||
|
|
||||||
on-keyup
|
on-keyup
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
@ -47,8 +50,8 @@
|
||||||
(let [keys [(events/listen globals/document EventType.CLICK on-click)
|
(let [keys [(events/listen globals/document EventType.CLICK on-click)
|
||||||
(events/listen globals/document EventType.CONTEXTMENU on-click)
|
(events/listen globals/document EventType.CONTEXTMENU on-click)
|
||||||
(events/listen globals/document EventType.KEYUP on-keyup)]]
|
(events/listen globals/document EventType.KEYUP on-keyup)]]
|
||||||
#(doseq [key keys]
|
(tm/schedule #(mf/set-ref-val! listening-ref true))
|
||||||
(events/unlistenByKey key))))]
|
#(run! events/unlistenByKey keys)))]
|
||||||
|
|
||||||
(mf/use-effect on-mount)
|
(mf/use-effect on-mount)
|
||||||
children))
|
children))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue