Skip to content

fix(cdk/a11y): Fix the touch/program origin regression introduced in the recent FocusMonitor refactor. - #22754

Merged
wagnermaciel merged 4 commits into
angular:input-modalityfrom
zelliott:focus-monitor-touch-fix
May 25, 2021
Merged

wagnermaciel merged 4 commits into
angular:input-modalityfrom
zelliott:focus-monitor-touch-fix

Conversation

@zelliott

@zelliott zelliott commented May 21, 2021 •

Copy link
Copy Markdown
Contributor

#22489 purposefully introduced a regression into FocusMonitor when touch events are quickly followed by programmatic focus events (read the PR for more details). It was thought this regression was fine because (1) it allowed us to remove a bunch of specialized touch logic from FocusMonitor, (2) it allows us to easily integrate InputModalityDetector, and (3) we didn't believe that mixing up touch/program attribution was that big of a deal, as not many consumers would style things differently between the two cases.

It turns out that many components display focus overlays on program focus and not on touch focus (these are styles that are built-in to AM). This regression thus led to failures when testing in g3 where tests would open popups via touch that programmatically focus their first focusable element. Given this, I decided to just go ahead and fix the regression. In reviewing this PR, it may help to review how the pre-InputModalityDetector FocusMonitor handled touch events (this implementation is largely similar but has some minor differences).

This PR also fixes a subtle bug in how the pre-InputModalityDetector implementation handled programmatic focus events that quickly follow touch events in EVENTUAL mode. This Stackblitz demonstrates and describes the bug: https://stackblitz.com/edit/angular-ivy-syzr9m. Additionally, it fixes an even subtler bug with touch-triggered programmatic focus events again in EVENTUAL mode, but I won't bother spinning up a demo unless people are curious.

Note: I also already ran a TPG for this PR on top of the rest of the input modality work and all looks good.

@google-cla google-cla Bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 21, 2021

/** Gets the target of an event, accounting for Shadow DOM. */
function getTarget(event: Event): HTMLElement|null {
export function getTarget(event: Event): HTMLElement|null {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, this file and the input-modality-detector.ts file both import from one another. I'd like to avoid this if possible. Should I move this small helper to a separate file? If so, where's a good place? @crisbeto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up moving getTarget to input-modality-detector.ts to resolve the circular dependencies (apparently there's some circular deps golden check), but it still doesn't feel like the right place for this small helper to live.


/**
* The most recently detected input modality event target. Is null if no input modality has been
* detected or if the associated event target is null for some unknown reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure in what case the event target would be null, but apparently it's possible (at least per the types).

* @param focusEventTarget The target of the focus event under examination.
*/
private _shouldBeAttributedToTouch(focusEventTarget: HTMLElement | null): boolean {
// Please note that this check is not perfect. Consider the following edge case:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially copied from

// Note(mmalerba): This implementation is not quite perfect, there is a small edge case.
.

@zelliott
zelliott marked this pull request as ready for review May 24, 2021 15:58
@zelliott
zelliott requested review from crisbeto and removed request for devversion May 24, 2021 15:58

@jelbourn jelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gltm

@jelbourn jelbourn added merge safe target: feature This PR is targeted for a feature branch (outside of main and semver branches) action: merge The PR is ready for merge by the caretaker labels May 25, 2021
@wagnermaciel
wagnermaciel merged commit 126964a into angular:input-modality May 25, 2021
jelbourn pushed a commit that referenced this pull request Jun 7, 2021
…the recent FocusMonitor refactor. (#22754)

* fix(cdk/a11y): Fix the touch/program origin regression introduced in the recent FocusMonitor refactor.
wagnermaciel pushed a commit that referenced this pull request Jun 10, 2021
…the recent FocusMonitor refactor. (#22754)

* fix(cdk/a11y): Fix the touch/program origin regression introduced in the recent FocusMonitor refactor.
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jun 25, 2021
@jelbourn jelbourn added the Accessibility This issue is related to accessibility (a11y) label Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Accessibility This issue is related to accessibility (a11y) action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: feature This PR is targeted for a feature branch (outside of main and semver branches)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants