fix(core): ignore non-primary pointer buttons in tap gesture (#1329)

This commit is contained in:
rahim
2026-04-14 12:26:32 -07:00
committed by GitHub
parent 7daec38b88
commit c7d4021bde
2 changed files with 33 additions and 4 deletions
+3 -1
View File
@@ -48,7 +48,8 @@ export class GestureCoordinator {
listen(
this.#target,
'pointerdown',
() => {
(event) => {
if (event.button !== 0) return;
pointerDownTime = Date.now();
},
{ signal }
@@ -58,6 +59,7 @@ export class GestureCoordinator {
this.#target,
'pointerup',
(event) => {
if (event.button !== 0) return;
if (Date.now() - pointerDownTime > TAP_THRESHOLD) return;
if (isInteractiveTarget(event)) return;
@@ -48,6 +48,30 @@ describe('createTapGesture', () => {
expect(handler).not.toHaveBeenCalled();
});
it('does not fire on secondary button (right-click)', () => {
const container = setup();
const handler = vi.fn();
createTapGesture(container, handler);
pointerDown(container, { button: 2 });
vi.advanceTimersByTime(50);
pointerUp(container, { pointerType: 'mouse', clientX: 150, button: 2 });
expect(handler).not.toHaveBeenCalled();
});
it('does not fire on auxiliary button (middle-click)', () => {
const container = setup();
const handler = vi.fn();
createTapGesture(container, handler);
pointerDown(container, { button: 1 });
vi.advanceTimersByTime(50);
pointerUp(container, { pointerType: 'mouse', clientX: 150, button: 1 });
expect(handler).not.toHaveBeenCalled();
});
it('does not fire when disabled', () => {
const container = setup();
const handler = vi.fn();
@@ -456,13 +480,16 @@ describe('interactive child filtering', () => {
// Helpers
// ---------------------------------------------------------------------------
function pointerDown(target: HTMLElement): void {
target.dispatchEvent(new Event('pointerdown', { bubbles: true }));
function pointerDown(target: HTMLElement, init: { button?: number } = {}): void {
const event = new Event('pointerdown', { bubbles: true });
Object.defineProperty(event, 'button', { value: init.button ?? 0 });
target.dispatchEvent(event);
}
function pointerUp(target: HTMLElement, init: { pointerType: string; clientX: number }): void {
function pointerUp(target: HTMLElement, init: { pointerType: string; clientX: number; button?: number }): void {
const event = new Event('pointerup', { bubbles: true });
Object.defineProperty(event, 'pointerType', { value: init.pointerType });
Object.defineProperty(event, 'clientX', { value: init.clientX });
Object.defineProperty(event, 'button', { value: init.button ?? 0 });
target.dispatchEvent(event);
}