From 11f45fb69203d7ab721ba86149810d701c13d8f2 Mon Sep 17 00:00:00 2001 From: ijlal99 Date: Tue, 24 Dec 2024 17:30:28 +0500 Subject: [PATCH] Submenu is not visible/usable when there is not enough space on the sides --- src/extras/ContextMenu/ContextMenu.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/extras/ContextMenu/ContextMenu.js b/src/extras/ContextMenu/ContextMenu.js index 0b8b1b8852..1f7c477554 100644 --- a/src/extras/ContextMenu/ContextMenu.js +++ b/src/extras/ContextMenu/ContextMenu.js @@ -738,12 +738,19 @@ class ContextMenu { const menuRect = subMenuElement.getBoundingClientRect(); const subMenuWidth = 200; // TODO - const showOnLeft = ((itemRect.right + subMenuWidth) > window.innerWidth); + const showOnRight = (itemRect.right + subMenuWidth) < window.innerWidth; + const showOnLeft = (itemRect.left - subMenuWidth) > 0; - if (showOnLeft) { - self._showMenu(subMenu.id, itemRect.left - subMenuWidth, itemRect.top - 1); - } else { + if(showOnRight) self._showMenu(subMenu.id, itemRect.right - 5, itemRect.top - 1); + else if (showOnLeft) + self._showMenu(subMenu.id, itemRect.left - subMenuWidth, itemRect.top - 1); + else { + const spaceOnLeft = itemRect.left, spaceOnRight = window.innerWidth - itemRect.right; + if(spaceOnRight > spaceOnLeft) + self._showMenu(subMenu.id, itemRect.right - 5 - (subMenuWidth - spaceOnRight), itemRect.top - 1); + else + self._showMenu(subMenu.id, itemRect.left - spaceOnLeft, itemRect.top - 1); } lastSubMenu = subMenu;