Skip to content

Commit

Permalink
Merge pull request #15444 from f94e59/master
Browse files Browse the repository at this point in the history
fix tieredMenuSub not positioning itself within viewport
  • Loading branch information
cetincakiroglu authored May 3, 2024
2 parents 34a3d68 + 0cd14ad commit 6ffdcef
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/app/components/tieredmenu/tieredmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
booleanAttribute,
effect,
forwardRef,
input,
numberAttribute,
signal
} from '@angular/core';
Expand Down Expand Up @@ -176,7 +177,7 @@ import { ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primeng/utils';
[itemTemplate]="itemTemplate"
[autoDisplay]="autoDisplay"
[menuId]="menuId"
[activeItemPath]="activeItemPath"
[activeItemPath]="activeItemPath()"
[focusedItemId]="focusedItemId"
[ariaLabelledBy]="getItemId(processedItem)"
[level]="level + 1"
Expand Down Expand Up @@ -217,7 +218,7 @@ export class TieredMenuSub implements AfterContentInit {

@Input() focusedItemId: string | undefined;

@Input() activeItemPath: any[];
activeItemPath = input<any[]>([]);

@Input({ transform: numberAttribute }) tabindex: number = 0;

Expand All @@ -233,7 +234,14 @@ export class TieredMenuSub implements AfterContentInit {

@ViewChild('sublist', { static: true }) sublistViewChild: ElementRef;

constructor(public el: ElementRef, public renderer: Renderer2, @Inject(forwardRef(() => TieredMenu)) public tieredMenu: TieredMenu) {}
constructor(public el: ElementRef, public renderer: Renderer2, @Inject(forwardRef(() => TieredMenu)) public tieredMenu: TieredMenu) {
effect(() => {
const path = this.activeItemPath();
if (ObjectUtils.isNotEmpty(path)) {
this.positionSubmenu();
}
})
}

ngAfterContentInit(): void {
this.positionSubmenu();
Expand All @@ -242,11 +250,11 @@ export class TieredMenuSub implements AfterContentInit {
positionSubmenu() {
const sublist = this.sublistViewChild && this.sublistViewChild.nativeElement;

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

if (parseInt(containerOffset.left, 10) + itemOuterWidth + sublistWidth > viewport.width - DomHandler.calculateScrollbarWidth()) {
Expand Down Expand Up @@ -310,8 +318,8 @@ export class TieredMenuSub implements AfterContentInit {
}

isItemActive(processedItem: any): boolean {
if (this.activeItemPath) {
return this.activeItemPath.some((path) => path.key === processedItem.key);
if (this.activeItemPath()) {
return this.activeItemPath().some((path) => path.key === processedItem.key);
}
}

Expand Down

0 comments on commit 6ffdcef

Please sign in to comment.