Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions projects/element-ng/tooltip/si-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class SiTooltipDirective implements OnDestroy {
protected describedBy = `__tooltip_${SiTooltipDirective.idCounter++}`;

private tooltipRef?: TooltipRef;
private isTooltipVisible = false;
private tooltipService = inject(SiTooltipService);
private elementRef = inject(ElementRef);
private destroyer = new Subject<void>();
Expand All @@ -83,6 +84,17 @@ export class SiTooltipDirective implements OnDestroy {
placement: this.placement()
});
this.tooltipRef.show(this.siTooltip(), this.tooltipContext());
this.isTooltipVisible = true;
}

@HostListener('click')
// Ensures dismissible tooltip works on Safari by manually focusing the trigger.
// See MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#clicking_and_focus
// See WebKit Bug #22261: https://bugs.webkit.org/show_bug.cgi?id=22261#c68
protected manuallyFocusTrigger(): void {
if (!this.isTooltipVisible) {
this.elementRef.nativeElement.focus();
}
}

@HostListener('focus')
Expand All @@ -102,6 +114,7 @@ export class SiTooltipDirective implements OnDestroy {
@HostListener('focusout')
protected hide(): void {
this.tooltipRef?.hide();
this.isTooltipVisible = false;
this.destroyer.next();
}

Expand Down
Loading