diff --git a/src/app/components/tieredmenu/tieredmenu.ts b/src/app/components/tieredmenu/tieredmenu.ts index 04b83fd0291..568e9a944f6 100755 --- a/src/app/components/tieredmenu/tieredmenu.ts +++ b/src/app/components/tieredmenu/tieredmenu.ts @@ -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; @@ -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); } } }