Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(a11y): focus monitor not checking children if monitor is called multiple times with different parameters #19237

Merged

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented May 3, 2020

With the current logic, if an element is being monitored with checkChildren set to true and then we start monitoring it with false, the initial monitor call will stop checking the children, because we take the checkChildren value from the most-recent call. This is something that we discussed in #19135 (comment), but now we have a case where it can happen: setting a tooltip on a sort header. The sort header looks for child focus, whereas the tooltip doesn't, causing the sort focus indication to break.

These changes fix the issue by treating all focus as checkChildren, as soon as there's at least one call to monitor with checkChildren turned on.

Fixes #19218.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels May 3, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 3, 2020
cachedInfo.checkChildren = checkChildren;
if (cachedInfo) {
if (checkChildren) {
cachedInfo.checkChildren = true;
Copy link
Member Author

@crisbeto crisbeto May 3, 2020

Choose a reason for hiding this comment

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

@mmalerba I think that this will work for most of the cases, but I'm not sure whether it's ideal. This means that the initial subscriber that signed up only for focus events on the element will now get emissions from children as well. Ideally, we'd be keeping track of two separate streams: own focus and child focus, but I didn't do it in this PR, because there are some issues with having two streams:

  1. There can be a conflict between the CSS focus classes, because both the checkChildren and the non-checkChildren calls are trying to set classes on the same element.
  2. We'd need a way to match focus either to the own focus stream or the child focus stream. Matching it is easy, but it can have performance implications, because we'd have to loop through and check all of the monitored elements on each focus and blur event.
  3. We'd have to introduce a checkChildren parameter on stopMonitoring so that the two streams can be stopped independently. This would either have to be breaking API change, or we'd introduce memory leaks in people's code, because their stopMonitoring calls won't work anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok those are some good points, especially #⁠1. Can you file a design issue with the above and link it in a TODO? This PR seems like the best option for the moment, but it would be good to have that documented

…ultiple times with different parameters

With the current logic, if an element is being monitored with `checkChildren` set to `true` and then we start monitoring it with `false`, the initial monitor call will stop checking the children, because we take the `checkChildren` value from the most-recent call. This is something that we discussed in angular#19135 (comment), but now we have a case where it can happen: setting a tooltip on a sort header. The sort header looks for child focus, whereas the tooltip doesn't, causing the sort focus indication to break.

These changes fix the issue by treating all focus as `checkChildren`, as soon as there's at least one call to `monitor` with `checkChildren` turned on.

Fixes angular#19218.
@crisbeto crisbeto force-pushed the 19218/focus-monitor-multiple-calls branch from d3eecb1 to a4d4ea2 Compare May 5, 2020 15:44
@crisbeto
Copy link
Member Author

crisbeto commented May 5, 2020

I've addressed the feedback @mmalerba.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added lgtm action: merge The PR is ready for merge by the caretaker labels May 5, 2020
@mmalerba mmalerba merged commit fe87bda into angular:master May 13, 2020
mmalerba pushed a commit that referenced this pull request May 15, 2020
…ultiple times with different parameters (#19237)

With the current logic, if an element is being monitored with `checkChildren` set to `true` and then we start monitoring it with `false`, the initial monitor call will stop checking the children, because we take the `checkChildren` value from the most-recent call. This is something that we discussed in #19135 (comment), but now we have a case where it can happen: setting a tooltip on a sort header. The sort header looks for child focus, whereas the tooltip doesn't, causing the sort focus indication to break.

These changes fix the issue by treating all focus as `checkChildren`, as soon as there's at least one call to `monitor` with `checkChildren` turned on.

Fixes #19218.
@angular-automatic-lock-bot
Copy link

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 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(MatSort/MatTooltip): Sort headers keyboard focus indicator not working when the header has a MatTooltip
3 participants