chore: always insert contextmenu on map container parent

offsetParent will return whatever positionned parent element, so
when clicking on a marker it will be the marker container.
And we cannot add the contextmenu inside the map container, as it
the focusout element will be sent before the click action happen
on any item of the contextmenu.
This commit is contained in:
Yohan Boniface 2024-10-06 09:46:23 +02:00
parent 3c0d2b79ef
commit 581ec242b8

View file

@ -15,7 +15,6 @@ export default class ContextMenu extends Positioned {
})
}
open(event, items) {
const left = event.clientX
const top = event.clientY
@ -43,7 +42,11 @@ export default class ContextMenu extends Positioned {
this.container.appendChild(li)
}
}
const parent = document.elementFromPoint(left, top).offsetParent
// When adding contextmenu below the map container, clicking on any link will send the
// "focusout" element on link click, preventing to trigger the click action
const parent = document
.elementFromPoint(left, top)
.closest('.leaflet-container').parentNode
parent.appendChild(this.container)
if (this.options.fixed) {
this.setPosition({ left, top })