Original:
I am having a hard time getting my matTooptip directive to work properly in the case of when using a mat-select element. The issue is that no matter what, even if ellipsis is present, the tooptip is always disabled. This directive, btw, works fine for
My directive looks as follows
import { Directive, ElementRef, HostListener, OnInit } from '@angular/core';
import { MatTooltip } from '@angular/material/tooltip';
@Directive({
selector: '[tooltipIfEllipsis]'
})
export class TooltipIfEllipsisDirective {
constructor(
private matTooltip: MatTooltip,
private elementRef: ElementRef<HTMLElement>) { }
@HostListener('mouseenter', ['$event'])
setTooltipState(): void {
const element = this.elementRef.nativeElement;
this.matTooltip.disabled = (element.scrollWidth <= element.clientWidth && element.clientHeight >= element.scrollHeight);
}
}
Every time I hover over my mat-select, which is defined as follows, the directive is always evaluating to true. How can I make this directive work with a mat-select, or is there a different way to check for ellipsis?
<mat-select
class="dropdown-select"
[(value)]="sessionTypeId"
(selectionChange)="onDropdownChange($event)"
matTooltip=""
defaultTooltip="'No assigned session types for this coach'"
conditionalMatTooltip
[conditionalTooltip]="selectedSessionType?.Name + ' - ' + selectedSessionType?.Length + ' Minutes'"
[conditionMet]="sessionTypes.length > 0"
tooltipIfEllipsis
placeholder="'Select a session type'"
name="sessionTypes">
<mat-select-trigger *ngIf="sessionTypes.length == 0">
<span [ngStyle]="{ 'color': '#2199E8' }">Select a session type</span>
</mat-select-trigger>
<mat-option style="color: #2199E8" *ngIf="sessionTypes.length == 0" [value]="'N/A'">
Select a session type
</mat-option>
<mat-option *ngFor="let c of sessionTypes" [value]="c.Id" [matTooltip]="c.Name + ' - ' + c.Length + ' Minutes'" tooltipIfEllipsis>
{{c.Name}} - {{c.Length}} Minutes
</mat-option>
</mat-select>