mirror of
https://github.com/penpot/penpot.git
synced 2026-09-13 07:30:24 +00:00
🐛 Fix error when get-parent-with-data encounters non-Element nodes
The get-parent-with-data function traverses the DOM using parentElement to find an ancestor with a specific data-* attribute. When the current node is a non-Element DOM node (e.g. Document node reached from event handlers on window), accessing .-dataset returns undefined, causing obj/in? to throw "right-hand side of 'in' should be an object". This adds a nodeType check to skip non-Element nodes during traversal and continue up the parent chain. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
2d616cf9c0
commit
577f00dd24
@ -170,8 +170,17 @@
|
|||||||
[^js node name]
|
[^js node name]
|
||||||
(let [name (str/camel name)]
|
(let [name (str/camel name)]
|
||||||
(loop [current node]
|
(loop [current node]
|
||||||
(if (or (nil? current) (obj/in? (.-dataset current) name))
|
(cond
|
||||||
|
(nil? current)
|
||||||
|
nil
|
||||||
|
|
||||||
|
(not= (.-nodeType current) js/Node.ELEMENT_NODE)
|
||||||
|
(recur (.-parentElement current))
|
||||||
|
|
||||||
|
(obj/in? (.-dataset current) name)
|
||||||
current
|
current
|
||||||
|
|
||||||
|
:else
|
||||||
(recur (.-parentElement current))))))
|
(recur (.-parentElement current))))))
|
||||||
|
|
||||||
(defn get-parent-with-selector
|
(defn get-parent-with-selector
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user