Skip to content

Commit

Permalink
Fix #2837: TieredMenu/ContextMenu hieght handling (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Dec 2, 2022
1 parent 8fcccaf commit d5331d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/lib/contextmenu/ContextMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export const ContextMenuSub = React.memo((props) => {

const position = () => {
const parentItem = submenuRef.current.parentElement;
const containerOffset = DomHandler.getOffset(submenuRef.current.parentElement);
const containerOffset = DomHandler.getOffset(parentItem);
const viewport = DomHandler.getViewport();
const sublistWidth = submenuRef.current.offsetParent ? submenuRef.current.offsetWidth : DomHandler.getHiddenElementOuterWidth(submenuRef.current);
const itemOuterWidth = DomHandler.getOuterWidth(parentItem.children[0]);
const top = parseInt(containerOffset.top, 10) + submenuRef.current.offsetHeight;
const top = parseInt(containerOffset.top, 10) + submenuRef.current.offsetHeight - DomHandler.getWindowScrollTop();

if (top > viewport.height) {
submenuRef.current.style.top = viewport.height - top + 'px';
Expand Down
7 changes: 7 additions & 0 deletions components/lib/tieredmenu/TieredMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const TieredMenuSub = React.memo((props) => {
const viewport = DomHandler.getViewport();
const sublistWidth = elementRef.current.offsetParent ? elementRef.current.offsetWidth : DomHandler.getHiddenElementOuterWidth(elementRef.current);
const itemOuterWidth = DomHandler.getOuterWidth(parentItem.children[0]);
const top = parseInt(containerOffset.top, 10) + elementRef.current.offsetHeight - DomHandler.getWindowScrollTop();

if (top > viewport.height) {
elementRef.current.style.top = viewport.height - top + 'px';
} else {
elementRef.current.style.top = '0px';
}

if (parseInt(containerOffset.left, 10) + itemOuterWidth + sublistWidth > viewport.width - DomHandler.calculateScrollbarWidth()) {
DomHandler.addClass(elementRef.current, 'p-submenu-list-flipped');
Expand Down

0 comments on commit d5331d1

Please sign in to comment.