Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltip on PrimeNG tree node icon

I have a requirement to add tooltip to PrimeNG Tree node icon. Could you please suggest me if there is a way to achieve this functionality.

like image 650
Mohan Avatar asked Mar 23 '26 20:03

Mohan


1 Answers

to achieve what you are trying to do you need to use a template inside your primeng tree like here:

<p-tree #tree [value]="assembliesTree"
    selectionMode="single"
    [pTooltip]="desiredTooltip"
    (mouseover)="nodeTooltipOver($event)"
    (mouseout)="nodeTooltipOut($event)"
    [(selection)]="..."
    (onNodeSelect)="..."
    (onNodeExpand)="..."
<template let-node pTemplate type="default">
    <span pTooltip="{{ desiredTooltip }}">{{ node.label }}</span>
</template>

You need to import the primeNG tooltip component so you can use it in (span inside the template). The tooltip inside the span will read the content of the string variable desiredTooltip, so you need to declare it in your component:

@Component({
    ...
})
export class ThreedViewerComponent implements AfterViewInit {

private desiredTooltip: string;

...

Then write the functions that modified the variable when the mouse enter or leave a node:

nodeTooltipOver(parameter) {
    if (parameter) {
        this.desiredTooltip = 'your tooltip';
    }
}

on mouseout you might want to clear the tooltip.

like image 189
Dino Avatar answered Mar 26 '26 09:03

Dino