Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/primefaces/primeng
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Dec 13, 2023
2 parents 3e5d44d + 9628a69 commit 6e50880
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions src/app/components/panelmenu/panelmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class PanelMenuSub {
[focusedItemId]="focused ? focusedItemId : undefined"
[activeItemPath]="activeItemPath()"
[transitionOptions]="transitionOptions"
[items]="processedItems()"
[items]="processedItems"
[parentExpanded]="parentExpanded"
(itemToggle)="onItemToggle($event)"
(keydown)="onKeyDown($event)"
Expand All @@ -300,7 +300,14 @@ export class PanelMenuSub {
class: 'p-element'
}
})
export class PanelMenuList implements OnChanges {
export class PanelMenuList {
@Input() set model(value: MenuItem[] | undefined) {
this._model = value;
this._processedItems = this.createProcessedItems(this._model || []);
}
get model(): MenuItem[] | undefined {
return this._model;
}
@Input() panelId: string | undefined;

@Input() id: string | undefined;
Expand Down Expand Up @@ -337,10 +344,19 @@ export class PanelMenuList implements OnChanges {

activeItemPath = signal<any[]>([]);

processedItems = signal<any[]>([]);
_model: any;

_processedItems: any[];

get processedItems() {
if (!this._processedItems || !this._processedItems.length) {
this._processedItems = this.createProcessedItems(this.model || []);
}
return this._processedItems;
}

visibleItems = computed(() => {
const processedItems = this.processedItems();
const processedItems = this.processedItems;
return this.flatItems(processedItems);
});

Expand All @@ -349,11 +365,11 @@ export class PanelMenuList implements OnChanges {
return focusedItem && focusedItem.item?.id ? focusedItem.item.id : ObjectUtils.isNotEmpty(this.focusedItem()) ? `${this.panelId}_${this.focusedItem().key}` : undefined;
}

ngOnChanges(changes: SimpleChanges) {
if (changes && changes.items && changes.items.currentValue) {
this.processedItems.set(this.createProcessedItems(changes.items.currentValue || []));
}
}
// ngOnChanges(changes: SimpleChanges) {
// if (changes && changes.items && changes.items.currentValue) {
// this._processedItems = this.createProcessedItems(changes.items.currentValue || []);
// }
// }

getItemProp(processedItem, name) {
return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name]) : undefined;
Expand Down Expand Up @@ -429,7 +445,7 @@ export class PanelMenuList implements OnChanges {
}

findProcessedItemByItemKey(key, processedItems?, level = 0) {
processedItems = processedItems || this.processedItems();
processedItems = processedItems || this.processedItems;
if (processedItems && processedItems.length) {
for (let i = 0; i < processedItems.length; i++) {
const processedItem = processedItems[i];
Expand Down Expand Up @@ -493,9 +509,9 @@ export class PanelMenuList implements OnChanges {
expanded && activeItemPath.push(processedItem);

this.activeItemPath.set(activeItemPath);
const processedItems = this.processedItems();
const processedItems = this.processedItems;
const newProcessedItems = processedItems.map((item) => (item === processedItem ? processedItem : item));
this.processedItems.set(newProcessedItems);
this._processedItems = newProcessedItems;
this.focusedItem.set(processedItem);
}

Expand Down Expand Up @@ -792,6 +808,7 @@ export class PanelMenuList implements OnChanges {
>
<div class="p-panelmenu-content" [attr.data-pc-section]="'menucontent'">
<p-panelMenuList
[model]="model"
[panelId]="getPanelId(i, item)"
[items]="getItemProp(item, 'items')"
[itemTemplate]="itemTemplate"
Expand Down Expand Up @@ -838,7 +855,13 @@ export class PanelMenu implements AfterContentInit {
* An array of menuitems.
* @group Props
*/
@Input() model: MenuItem[] | undefined;
@Input() set model(value: MenuItem[] | undefined) {
this._model = value;

}
get model(): MenuItem[] | undefined {
return this._model;
}
/**
* Inline style of the component.
* @group Props
Expand Down Expand Up @@ -882,6 +905,12 @@ export class PanelMenu implements AfterContentInit {

activeItem = signal<any>(null);



_model: MenuItem[] | undefined;



ngOnInit() {
this.id = this.id || UniqueComponentId();
}
Expand Down Expand Up @@ -1094,3 +1123,4 @@ export class PanelMenu implements AfterContentInit {
declarations: [PanelMenu, PanelMenuSub, PanelMenuList]
})
export class PanelMenuModule {}

0 comments on commit 6e50880

Please sign in to comment.