-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cdk/a11y): detect fake touchstart events from screen readers (#21987
) We currently have handling for the case where a `mousedown` event is thrown off by a fake `mousedown` listener that may be dispatched by a screen reader when an element is activated. It turns out that if the device has touch support, screen readers may dispatch a fake `touchstart` event instead of a fake `mousedown`. These changes add another utility function that allows us to distinguish the fake events and fix some issues where keyboard focus wasn't being shown because of the fake `touchstart` events. Fixes #21947.
- Loading branch information
Showing
7 changed files
with
63 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** Gets whether an event could be a faked `mousedown` event dispatched by a screen reader. */ | ||
export function isFakeMousedownFromScreenReader(event: MouseEvent): boolean { | ||
// We can typically distinguish between these faked mousedown events and real mousedown events | ||
// using the "buttons" property. While real mousedowns will indicate the mouse button that was | ||
// pressed (e.g. "1" for the left mouse button), faked mousedowns will usually set the property | ||
// value to 0. | ||
return event.buttons === 0; | ||
} | ||
|
||
/** Gets whether an event could be a faked `touchstart` event dispatched by a screen reader. */ | ||
export function isFakeTouchstartFromScreenReader(event: TouchEvent): boolean { | ||
const touch: Touch | undefined = (event.touches && event.touches[0]) || | ||
(event.changedTouches && event.changedTouches[0]); | ||
|
||
// A fake `touchstart` can be distinguished from a real one by looking at the `identifier` | ||
// which is typically >= 0 on a real device versus -1 from a screen reader. Just to be safe, | ||
// we can also look at `radiusX` and `radiusY`. This behavior was observed against a Windows 10 | ||
// device with a touch screen running NVDA v2020.4 and Firefox 85 or Chrome 88. | ||
return !!touch && touch.identifier === -1 && (touch.radiusX == null || touch.radiusX === 1) && | ||
(touch.radiusY == null || touch.radiusY === 1); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters