From 581ec242b8ba1dff7fc79ec29d45f5bb9aa960d1 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 6 Oct 2024 09:46:23 +0200 Subject: [PATCH] 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. --- umap/static/umap/js/modules/ui/contextmenu.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/modules/ui/contextmenu.js b/umap/static/umap/js/modules/ui/contextmenu.js index 0787d5ea..8d2603b5 100644 --- a/umap/static/umap/js/modules/ui/contextmenu.js +++ b/umap/static/umap/js/modules/ui/contextmenu.js @@ -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 })