Skip to content

Commit

Permalink
fix: tieredMenuSub improve self-positioning in viewPort when viewPort…
Browse files Browse the repository at this point in the history
… has been resized between activations
  • Loading branch information
Cihan Polat committed May 3, 2024
1 parent efb963d commit e3ce981
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/app/components/tieredmenu/tieredmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ import { ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primeng/utils';
class: 'p-element'
}
})
export class TieredMenuSub implements AfterContentInit {
export class TieredMenuSub {
@Input() items: any[];

@Input() itemTemplate: HTMLElement | undefined;
Expand Down Expand Up @@ -243,22 +243,21 @@ export class TieredMenuSub implements AfterContentInit {
})
}

ngAfterContentInit(): void {
this.positionSubmenu();
}

positionSubmenu() {
const sublist = this.sublistViewChild && this.sublistViewChild.nativeElement;

if (sublist && !DomHandler.hasClass(sublist, 'p-submenu-list-flipped')) {
if (sublist) {
const parentItem = sublist.parentElement.parentElement;
const containerOffset = DomHandler.getOffset(parentItem);
const viewport = DomHandler.getViewport();
const sublistWidth = sublist.offsetParent ? sublist.offsetWidth : DomHandler.getOuterWidth(sublist);
const itemOuterWidth = DomHandler.getOuterWidth(parentItem.children[0]);
const sublistFlippedClass = 'p-submenu-list-flipped';

if (parseInt(containerOffset.left, 10) + itemOuterWidth + sublistWidth > viewport.width - DomHandler.calculateScrollbarWidth()) {
DomHandler.addClass(sublist, 'p-submenu-list-flipped');
DomHandler.addClass(sublist, sublistFlippedClass);
} else if (DomHandler.hasClass(sublist, sublistFlippedClass)) {
DomHandler.removeClass(sublist, sublistFlippedClass);
}
}
}
Expand Down

0 comments on commit e3ce981

Please sign in to comment.