Skip to content

Commit

Permalink
Fixes #16934
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Dec 5, 2024
1 parent ac90038 commit 030695c
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions packages/primeng/src/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChangeDetectionStrategy,
Component,
ContentChild,
ContentChildren,
ElementRef,
EventEmitter,
forwardRef,
Expand All @@ -16,14 +17,15 @@ import {
OnInit,
Optional,
Output,
QueryList,
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { find, findSingle, focus, hasClass, removeAccents, resolveFieldData } from '@primeuix/utils';
import { BlockableUI, ScrollerOptions, SharedModule, TranslationKeys, TreeDragDropService, TreeNode } from 'primeng/api';
import { BlockableUI, PrimeTemplate, ScrollerOptions, SharedModule, TranslationKeys, TreeDragDropService, TreeNode } from 'primeng/api';
import { BaseComponent } from 'primeng/basecomponent';
import { Checkbox } from 'primeng/checkbox';
import { IconField } from 'primeng/iconfield';
Expand Down Expand Up @@ -138,15 +140,15 @@ import {
<span [class]="getIcon()" *ngIf="node.icon || node.expandedIcon || node.collapsedIcon"></span>
<span class="p-tree-node-label">
<span *ngIf="!tree.nodeTemplate">{{ node.label }}</span>
<span *ngIf="tree.nodeTemplate">
<ng-container *ngTemplateOutlet="tree.nodeTemplate; context: { $implicit: node }"></ng-container>
<span *ngIf="!tree.getTemplateForNode(node)">{{ node.label }}</span>
<span *ngIf="tree.getTemplateForNode(node)">
<ng-container *ngTemplateOutlet="tree.getTemplateForNode(node); context: { $implicit: node }"></ng-container>
</span>
</span>
</div>
<ul class="p-tree-node-children" style="display: none;" *ngIf="!tree.virtualScroll && node.children && node.expanded" [style.display]="node.expanded ? 'block' : 'none'" role="group">
<p-treeNode
*ngFor="let childNode of node.children; let firstChild = first; let lastChild = last; let index = index; trackBy: tree.trackBy"
*ngFor="let childNode of node.children; let firstChild = first; let lastChild = last; let index = index; trackBy: tree.trackBy.bind(this)"
[node]="childNode"
[parentNode]="node"
[firstChild]="firstChild"
Expand Down Expand Up @@ -769,7 +771,7 @@ export class UITreeNode extends BaseComponent implements OnInit {
<div #wrapper class="p-tree-root" [style.max-height]="scrollHeight">
<ul class="p-tree-root-children" *ngIf="getRootNode()" role="tree" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledBy">
<p-treeNode
*ngFor="let node of getRootNode(); let firstChild = first; let lastChild = last; let index = index; trackBy: trackBy"
*ngFor="let node of getRootNode(); let firstChild = first; let lastChild = last; let index = index; trackBy: trackBy.bind(this)"
[node]="node"
[firstChild]="firstChild"
[lastChild]="lastChild"
Expand Down Expand Up @@ -1113,6 +1115,54 @@ export class Tree extends BaseComponent implements OnInit, OnChanges, OnDestroy,

@ViewChild('wrapper') wrapperViewChild: Nullable<ElementRef>;

@ContentChildren(PrimeTemplate) private _templates: QueryList<PrimeTemplate> | undefined;

ngAfterContentInit() {
if ((this._templates as QueryList<PrimeTemplate>).length) {
this._templateMap = {};
}

(this._templates as QueryList<PrimeTemplate>).forEach((item) => {
switch (item.getType()) {
case 'header':
this.headerTemplate = item.template;
break;

case 'empty':
this.emptymessageTemplate = item.template;
break;

case 'footer':
this.footerTemplate = item.template;
break;

case 'loader':
this.loaderTemplate = item.template;
break;

case 'togglericon':
this.togglericonTemplate = item.template;
break;

case 'checkboxicon':
this.checkboxiconTemplate = item.template;
break;

case 'loadingicon':
this.loadingiconTemplate = item.template;
break;

case 'filtericon':
this.filtericonTemplate = item.template;
break;

default:
this._templateMap[<any>item.name] = item.template;
break;
}
});
}

serializedValue: Nullable<TreeNode<any>[]>;

public nodeTouched: boolean | undefined | null;
Expand Down

0 comments on commit 030695c

Please sign in to comment.