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
12 changes: 10 additions & 2 deletions projects/element-ng/tooltip/si-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { SiTooltipService, TooltipRef } from './si-tooltip.service';
'(mouseenter)': 'show()',
'(touchstart)': 'hide()',
'(focusout)': 'hide()',
'(mouseleave)': 'hide()'
'(mouseleave)': 'hide()',
'(pointerdown)': 'pointerDown()'
}
})
export class SiTooltipDirective implements OnDestroy {
Expand Down Expand Up @@ -63,6 +64,7 @@ export class SiTooltipDirective implements OnDestroy {
private showTimeout?: ReturnType<typeof setTimeout>;
private tooltipService = inject(SiTooltipService);
private elementRef = inject(ElementRef);
private isPointerDown = false;

ngOnDestroy(): void {
this.clearShowTimeout();
Expand Down Expand Up @@ -95,11 +97,16 @@ export class SiTooltipDirective implements OnDestroy {
tooltipContext: this.tooltipContext
});
this.tooltipRef.show();
this.isPointerDown = false;
}, delay);
}

protected focusIn(): void {
this.showTooltip(true);
this.showTooltip(!this.isPointerDown);
}

protected pointerDown(): void {
this.isPointerDown = true;
}
Comment on lines +108 to 110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The isPointerDown flag is set here but only reset when the tooltip is shown or hidden. If a pointerdown event occurs without a corresponding show/hide action (e.g., on a non-focusable element), the flag can get stuck as true. This could cause future keyboard focus events to be incorrectly delayed.

To prevent this, the flag should be reset automatically after the event sequence. Using setTimeout ensures the flag is transient, covering the pointerdown -> focus sequence without affecting later, unrelated focus events.

Suggested change
protected pointerDown(): void {
this.isPointerDown = true;
}
protected pointerDown(): void {
this.isPointerDown = true;
setTimeout(() => (this.isPointerDown = false), 0);
}


protected show(): void {
Expand All @@ -109,5 +116,6 @@ export class SiTooltipDirective implements OnDestroy {
protected hide(): void {
this.clearShowTimeout();
this.tooltipRef?.hide();
this.isPointerDown = false;
}
}
Loading