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

Listen for focus event on calendar cells #24279

Merged

Conversation

zarend
Copy link
Contributor

@zarend zarend commented Jan 26, 2022

Description

Please see commit message for description.

Guide to reviewing this

Would probably make the most sense to reviewers to look at code changes in this order:

  1. MatCalendarBody._scheduleFocusActiveCellAfterViewChecked (used for refactoring handing keydown events without changing existing behavior)
  2. Tests added to src/material/datepicker/month-view.spec.ts (the behavior change this PR creates)
  3. MatCalendarBody._cellFocused
  4. MatMonthView._dateBecomesActive

@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch from 90e63ed to 0ab736c Compare January 26, 2022 21:46
@zarend zarend added Accessibility This issue is related to accessibility (a11y) area: material/datepicker dev-app preview When applied, previews of the dev-app are deployed to Firebase target: patch This PR is targeted for the next patch release labels Jan 26, 2022
@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch from 0ab736c to 5b3f379 Compare January 26, 2022 21:50
@github-actions
Copy link

@zarend zarend marked this pull request as ready for review January 26, 2022 22:19
@zarend zarend requested review from mmalerba and a team as code owners January 26, 2022 22:19
@josephperrott josephperrott removed the request for review from a team January 27, 2022 16:56
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 the action: merge The PR is ready for merge by the caretaker label Jan 27, 2022
@zarend zarend added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jan 28, 2022
@zarend zarend removed the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jan 31, 2022
src/material/datepicker/month-view.spec.ts Outdated Show resolved Hide resolved
src/material/datepicker/month-view.ts Outdated Show resolved Hide resolved
src/material/datepicker/month-view.ts Outdated Show resolved Hide resolved
'[data-mat-row="1"][data-mat-col="2"] button',
) as HTMLElement;

dispatchFakeEvent(year2022El, 'focus');
Copy link
Member

Choose a reason for hiding this comment

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

Would the test worked if you actually focused the element with .focus()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, not sure exactly what the question is here. If we changed this line to year2022El.focus() then the test would fail when we check that the focusSpy was not called.

An alternative would be to actually focus the element with .focus(), but assert that the focusSpy was called exactly one.

I went with dispathFakeEvent because that's what we use in all the other tests, but I'm open to suggestions.

src/material/datepicker/month-view.ts Outdated Show resolved Hide resolved
@jelbourn jelbourn removed the action: merge The PR is ready for merge by the caretaker label Feb 1, 2022
@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch 2 times, most recently from e35faa8 to 8152864 Compare February 4, 2022 22:57
@zarend
Copy link
Contributor Author

zarend commented Feb 4, 2022

@jelbourn , I've address the PR comments, and this is ready for your eyes again 👀

@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch 2 times, most recently from cb9b201 to 782f893 Compare February 5, 2022 00:18
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

lgtm

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Feb 5, 2022
@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch from 782f893 to 0805774 Compare February 5, 2022 01:37
When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Fixes angular#23483
@zarend zarend force-pushed the listen-for-focus-event-on-calendar-cells branch from 0805774 to e82f7a6 Compare February 5, 2022 01:39
@zarend zarend merged commit 052b97d into angular:master Feb 7, 2022
zarend added a commit that referenced this pull request Feb 7, 2022
…ell (#24279)

When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Fixes #23483

(cherry picked from commit 052b97d)
zarend added a commit that referenced this pull request Feb 8, 2022
zarend added a commit that referenced this pull request Feb 8, 2022
zarend added a commit that referenced this pull request Feb 8, 2022
…lendar cell (#24279)" (#24380)

This reverts commit 052b97d.

(cherry picked from commit e04e4a7)
zarend added a commit to zarend/components that referenced this pull request Feb 9, 2022
When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Note that this is the second attempt at this. First attempt was angular#24279,
which was reverted in angular#24380 due to an internal issue.

Fixes angular#23483
zarend added a commit that referenced this pull request Feb 14, 2022
When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Note that this is the second attempt at this. First attempt was #24279,
which was reverted in #24380 due to an internal issue.

Fixes #23483
amysorto pushed a commit to amysorto/components that referenced this pull request Feb 15, 2022
…ell (angular#24279)

When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Fixes angular#23483
amysorto pushed a commit to amysorto/components that referenced this pull request Feb 15, 2022
amysorto pushed a commit to amysorto/components that referenced this pull request Feb 15, 2022
…lar#24384)

When a a date cell on the calendar recieves focus, set the active date
to that cell. This ensures that the active date matches the date with
browser focus.

Previously, we set the active date on keydown and click, but that was
problematic for screenreaders. That's because many screenreaders trigger
a focus event instead of a keydown event when using screenreader
specific navigation (VoiceOver, Chromevox, NVDA).

Note that this is the second attempt at this. First attempt was angular#24279,
which was reverted in angular#24380 due to an internal issue.

Fixes angular#23483
@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 Mar 10, 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 area: material/datepicker dev-app preview When applied, previews of the dev-app are deployed to Firebase target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants