Skip to content

Commit

Permalink
fix(tooltip): show tooltip on touch
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Mar 17, 2023
1 parent 7ce9610 commit d421649
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ export default class TooltipElement extends HTMLElement {
private onFocus = this.show.bind(this);
private onMouseLeave = this.afterDelay.bind(this, this.hide);
private onBlur = this.hide.bind(this);
private onPointerUp = (e: PointerEvent) => {
if (e.pointerType === 'mouse') this.hide();
};

public connectedCallback(): void {
this.parent = this.parentNode as HTMLElement;

if (this.parent) {
this.parent.addEventListener('mouseenter', this.onMouseEnter);
this.parent.addEventListener('focus', this.onFocus);
this.parent.addEventListener('touchstart', this.onFocus);
this.parent.addEventListener('mouseleave', this.onMouseLeave);
this.parent.addEventListener('blur', this.onBlur);
this.parent.addEventListener('click', this.onBlur);
this.parent.addEventListener('pointerup', this.onPointerUp);

this.observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
Expand All @@ -51,9 +55,10 @@ export default class TooltipElement extends HTMLElement {
if (this.parent) {
this.parent.removeEventListener('mouseenter', this.onMouseEnter);
this.parent.removeEventListener('focus', this.onFocus);
this.parent.removeEventListener('touchstart', this.onFocus);
this.parent.removeEventListener('mouseleave', this.onMouseLeave);
this.parent.removeEventListener('blur', this.onBlur);
this.parent.removeEventListener('click', this.onBlur);
this.parent.removeEventListener('pointerup', this.onPointerUp);
this.parent = undefined;
}

Expand Down

0 comments on commit d421649

Please sign in to comment.