Skip to content

Commit 14c7944

Browse files
authored
fix(multiple): update fake event detection in aria (#34004)
Aligns the fake event detection in Angular Aria with the approach we've been using for a while in the CDK. It works a bit better across browsers.
1 parent 8fc6eac commit 14c7944

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,16 @@ import {
1717

1818
/**
1919
* Gets whether an event could be a simulated click event.
20-
*
21-
* Screen readers and keyboard activation (Enter/Space) often dispatch fake click
22-
* events. We distinguish them by checking if `event.detail` is zero or if
23-
* `event.pointerType` is missing.
2420
*/
25-
export function isFakeClick(event: PointerEvent): boolean {
26-
return event.detail === 0 || !event.pointerType;
21+
function isFakeClick(event: MouseEvent): boolean {
22+
return event.detail === 0 && event.screenX === 0 && event.screenY === 0;
2723
}
2824

2925
/**
3026
* Gets whether an event is a programmatic click (e.g. triggered by .click() or .dispatchEvent()).
3127
* Programmatic events are untrusted.
3228
*/
33-
export function isProgrammaticClick(event: Event): boolean {
29+
function isProgrammaticClick(event: Event): boolean {
3430
return !event.isTrusted;
3531
}
3632

@@ -85,7 +81,7 @@ export class ClickEventManager<T extends PointerEvent> extends EventManager<T> {
8581
};
8682
}
8783

88-
_isMatch(event: T, modifiers: ModifierInputs) {
84+
private _isMatch(event: T, modifiers: ModifierInputs) {
8985
const isAllowed = isProgrammaticClick(event) || !isFakeClick(event);
9086
return isAllowed && hasModifiers(event, modifiers);
9187
}

0 commit comments

Comments
 (0)