Skip to content

Commit

Permalink
Merge pull request #1767 from xeokit/fix/XEOK-184
Browse files Browse the repository at this point in the history
Submenu is not visible/usable when there is not enough space on the sides
  • Loading branch information
xeolabs authored Dec 24, 2024
2 parents acc1f82 + 11f45fb commit 6194327
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/extras/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6194327

Please sign in to comment.