primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.15k stars 4.54k forks source link

p-contextMenu: Submenu goes out of screen at the bottom of the view #12647

Open bence-balogh-intland opened 1 year ago

bence-balogh-intland commented 1 year ago

Describe the bug

Submenus are not fully visible, when the Context menu is positioned near to the bottom, or there are many submenu items, those overhang the bottom of the screen.

I was able to reproduce it in between the versions of v13 and v15.

Please find the behavior on the screenshoot: image

Please notice that:

Environment

Stackblitz

Reproducer

https://stackblitz.com/edit/github-dnrd8e

Angular version

13-15

PrimeNG version

13-15

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

16.18.0

Browser(s)

Chrome 109

Steps to reproduce the behavior

  1. Open Stackblitz link
  2. Right click on blue context menu target element
  3. Hover over "Open me"
  4. Observe the behavior

Expected behavior

When submenu's bottom overhangs the bottom of the screen, it should:

A) Align submenu's bottom to page bottom

or

B) Align submenu's bottom to the bottom of the parent menu item ("Open me" - in the example)

oleggd commented 1 year ago

Hi, faced the same issue and found that in contextmenu.ts -> positionSubmenu(sublist) available space calculation is not taking into account all previous height of parents

calculations: if (parseInt(containerOffset.top) + itemOuterHeight + sublistHeight > viewport.height - DomHandler.calculateScrollbarHeight()) { sublist.style.removeProperty('top'); sublist.style.bottom = '0px'; } else { sublist.style.removeProperty('bottom'); sublist.style.top = '0px'; }

containerOffset.top - top of whole menu under of item1 itemOuterHeight - height of item3 sublistHeight - height of submenu item3

So, height of item1 + item2 is not taking into account. Maybe containerOffset.top should be top of parent item - item3. Hope i understood calculation correctly and this can help you.

Thanks

stity commented 10 months ago

Related issue : https://github.com/primefaces/primeng/issues/12541