Skip to content

Commit

Permalink
Add submenu position attribute on the li tag containing a submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlal99 committed Sep 13, 2024
1 parent b0a4069 commit 1c4546e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/extras/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ class ContextMenu {
this._updateItemsTitles();
this._updateItemsEnabledStatus();
this._showMenu(this._rootMenu.id, pageX, pageY);
this._updateSubMenuInfo();
this._shown = true;
this.fire("shown", {});
}
Expand Down Expand Up @@ -869,6 +870,22 @@ class ContextMenu {
}
}

_updateSubMenuInfo() {
if (!this._context) return;
let showOnLeft = null;
this._itemList.forEach((item) => {
if (item.subMenu) {
const itemElement = item.itemElement;
if (!showOnLeft) {
const itemRect = itemElement.getBoundingClientRect();
const subMenuWidth = 200; // TODO
showOnLeft = ((itemRect.right + subMenuWidth) > window.innerWidth);
}
itemElement.setAttribute("data-submenuposition", showOnLeft ? "left" : "right");
}
})
}

_showMenu(menuId, pageX, pageY) { // Shows the given menu, at the specified page coordinates
const menu = this._menuMap[menuId];
if (!menu) {
Expand Down

0 comments on commit 1c4546e

Please sign in to comment.