Skip to content

Commit

Permalink
chore: updated menu interaction model
Browse files Browse the repository at this point in the history
  • Loading branch information
TarunAdobe committed Jul 25, 2024
1 parent 344344e commit bcc18dd
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/menu/src/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,20 @@ export class Menu extends SizedMixin(SpectrumElement, { noDefaultSize: true }) {
}
}

private willSynthesizeClick = 0;
// if the click and pointerup events are on the same target, we should not
// handle the click event.
private pointerUpTarget = null as EventTarget | null;

private handleClick(event: Event): void {
if (this.willSynthesizeClick) {
cancelAnimationFrame(this.willSynthesizeClick);
this.willSynthesizeClick = 0;
if (this.pointerUpTarget === event.target) {
this.pointerUpTarget = null;
return;
}
this.handlePointerBasedSelection(event);
}

private handlePointerup(event: Event): void {
this.willSynthesizeClick = requestAnimationFrame(() => {
event.target?.dispatchEvent(new Event('click'));
this.willSynthesizeClick = 0;
});
this.pointerUpTarget = event.target;
this.handlePointerBasedSelection(event);
}

Expand Down

0 comments on commit bcc18dd

Please sign in to comment.