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 9, 2024
1 parent d04749e commit 8b2ca3c
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 @@ -189,7 +189,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 @@ -239,21 +239,20 @@ export class TieredMenuSub implements AfterContentInit {
});
}

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

positionSubmenu() {
if (isPlatformBrowser(this.tieredMenu.platformId)) {
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 8b2ca3c

Please sign in to comment.