Skip to content

Commit 691d4c5

Browse files
committed
fixup! refactor(multiple): migrate Listbox and Tabs to ClickEventManager
1 parent 82b1b06 commit 691d4c5

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/aria/private/behaviors/event-manager/click-event-manager.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ import {
1515
Modifier,
1616
} from './event-manager';
1717

18+
/**
19+
* Gets whether an event could be a faked click event dispatched by a screen reader
20+
* or generated by the browser when Enter or Space keys are pressed.
21+
*/
22+
export function isFakeClick(event: PointerEvent): boolean {
23+
// Some screen readers will dispatch a fake click event when pressing enter or space on
24+
// a clickable element. We can distinguish these events when `event.buttons` is zero, or
25+
// `event.detail` is zero depending on the browser:
26+
// - `event.buttons` works on Firefox, but fails on Chrome.
27+
// - `detail` works on Chrome, but fails on Firefox.
28+
// Also, fake events might not have a valid pointerType.
29+
return event.buttons === 0 || event.detail === 0 || !event.pointerType;
30+
}
31+
1832
/**
1933
* An event manager that is specialized for handling click events.
2034
*
@@ -67,19 +81,6 @@ export class ClickEventManager<T extends PointerEvent> extends EventManager<T> {
6781
}
6882

6983
_isMatch(event: T, modifiers: ModifierInputs) {
70-
return this._isRealClick(event) && hasModifiers(event, modifiers);
71-
}
72-
73-
/**
74-
* Checks if the event is a "real" pointer click.
75-
*
76-
* Real clicks typically have a non-zero detail count (click count) and
77-
* a valid pointerType (e.g. 'mouse' or 'touch').
78-
*/
79-
private _isRealClick(event: T): boolean {
80-
if (event.detail === 0) return false;
81-
if (event.clientX === 0 && event.clientY === 0) return false;
82-
if (!event.pointerType) return false;
83-
return true;
84+
return !isFakeClick(event) && hasModifiers(event, modifiers);
8485
}
8586
}

0 commit comments

Comments
 (0)