Skip to content

Commit

Permalink
Merge pull request #1148 from exadel-inc/EFRS-1394_Tooltip_points_to_…
Browse files Browse the repository at this point in the history
…the_wrong_image

Added directive to handle tooltip arrow
  • Loading branch information
pospielov authored Aug 19, 2023
2 parents 2625768 + f6307a5 commit 04e6523
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
>
<mat-icon>highlight_off</mat-icon>
</div>
<div *ngSwitchCase="progressEnum.Failed" class="image-load-failed" [matTooltip]="error" matTooltipClass="top-arrow">
<div *ngSwitchCase="progressEnum.Failed" tooltipArrowHandler class="image-load-failed" [matTooltip]="error" matTooltipClass="top-arrow">
<mat-icon>warning_amber</mat-icon>
</div>
<div *ngSwitchCase="progressEnum.InProgress" class="image-load-in-progress">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import { CircleLoadingProgressComponent } from './circle-loading-progress.compon
import { MatIconModule } from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatTooltipModule } from '@angular/material/tooltip';
import { SharedModule } from 'src/app/shared/shared.module';

@NgModule({
declarations: [CircleLoadingProgressComponent],
exports: [CircleLoadingProgressComponent],
imports: [CommonModule, MatIconModule, MatProgressSpinnerModule, MatTooltipModule],
imports: [CommonModule, MatIconModule, MatProgressSpinnerModule, MatTooltipModule, SharedModule],
})
export class CircleLoadingProgressModule {}
10 changes: 10 additions & 0 deletions ui/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TooltipArrowHandlerDirective } from './tooltip-arrow-handler.directive';

@NgModule({
declarations: [TooltipArrowHandlerDirective],
imports: [CommonModule],
exports: [TooltipArrowHandlerDirective],
})
export class SharedModule {}
37 changes: 37 additions & 0 deletions ui/src/app/shared/tooltip-arrow-handler.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { OverlayContainer } from '@angular/cdk/overlay';
import { Directive, ElementRef, HostListener, Renderer2 } from '@angular/core';
import { MatTooltip } from '@angular/material/tooltip';

@Directive({
selector: '[tooltipArrowHandler]',
})
export class TooltipArrowHandlerDirective {
constructor(
private el: ElementRef,
private renderer: Renderer2,
private matTooltip: MatTooltip,
private overlayContainer: OverlayContainer
) {}

@HostListener('mouseenter') onMouseEnter() {
const position = this.el.nativeElement.getBoundingClientRect();

if (this.matTooltip) {
setTimeout(() => {
const tooltipElements = this.overlayContainer.getContainerElement().querySelectorAll('.mat-tooltip-panel');
const tooltipElement = Array.from(tooltipElements).find(el => {
return el.textContent === this.matTooltip.message;
});

if (tooltipElement) {
const tooltipPosition = tooltipElement.getBoundingClientRect();
if (tooltipPosition.bottom <= position.top) {
this.matTooltip.tooltipClass = 'bottom-arrow';
} else {
this.matTooltip.tooltipClass = 'top-arrow';
}
}
}, 0);
}
}
}

0 comments on commit 04e6523

Please sign in to comment.