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(material/menu): focus the first item when opening menu on iOS VoiceOver #24733

Merged
merged 1 commit into from
May 6, 2022

Conversation

zarend
Copy link
Contributor

@zarend zarend commented Apr 4, 2022

When opening the menu using the iOS VoiceOver screen reader, focus the first item in the menu.
Previously, the first menu item would focus on other screen readers like desktop VoiceOver but
not with iOS VoiceOver.

Waiting until onStable seems to fix this.

Fixes #24735

@zarend zarend added Accessibility This issue is related to accessibility (a11y) area: material/menu dev-app preview When applied, previews of the dev-app are deployed to Firebase labels Apr 4, 2022
@github-actions
Copy link

github-actions bot commented Apr 4, 2022

@zarend zarend added the target: patch This PR is targeted for the next patch release label Apr 4, 2022
@zarend zarend force-pushed the menu-ios-voiceover branch 2 times, most recently from 06fa24d to 2ce0153 Compare April 4, 2022 23:44
@zarend zarend changed the title fix(material/menu): debugging focusing the first item with iOS Voiceover fix(material/menu): focus the first item when opening menu on iOS VoiceOver Apr 4, 2022
@zarend zarend force-pushed the menu-ios-voiceover branch 4 times, most recently from f1a439c to 4b508e7 Compare April 13, 2022 21:19
@zarend zarend marked this pull request as ready for review April 13, 2022 21:21
@zarend zarend requested a review from crisbeto as a code owner April 13, 2022 21:21
crisbeto
crisbeto previously approved these changes Apr 16, 2022
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Apr 16, 2022
@zarend
Copy link
Contributor Author

zarend commented Apr 19, 2022

Hmm, it seems like this doesn't work since the menu emits the "opened" event before calling .focus() on the first menu item.

I'll look into another solution for this and send out a new PR when I have it working.

@zarend zarend closed this Apr 19, 2022
@zarend zarend reopened this Apr 28, 2022
@zarend
Copy link
Contributor Author

zarend commented Apr 28, 2022

Hmm, it seems like this doesn't work since the menu emits the "opened" event before calling .focus() on the first menu item.

I'll look into another solution for this and send out a new PR when I have it working.

Re-opening because because there is no requirement when focus is called, just that it has to be called some time after openMenu is called.

@@ -1147,6 +1147,7 @@ describe('MatMenu', () => {
fixture.detectChanges();

fixture.componentInstance.trigger.menuOpened.subscribe(() => {
flush();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@crisbeto I'm confused about this test. I understand that for the openMenu method, there is no requirement on when the first element of the list is focused. It has to be focused in some time after calling openMenu.

For the menuOpened event, is there a requirement that the first element must be focused by the time the menuOpened event fires?

To avoid a race condition with the _focusFirstItem method, this test adds a flush. In application code, the developer would have to wait for onStable or do a setTimeout. There is still a way for developers to move focus inside the open event callback, but not at the time the open event is fired.

Does this PR meet the requirements for the behavior of menuOpened?

Copy link
Member

Choose a reason for hiding this comment

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

This is checking that we don't override the consumer's focus, if they moved it into the menu themselves before we tried to focus the first item. That's why I was proposing the if (!menu.contains(document.activeElement) check.

@zarend
Copy link
Contributor Author

zarend commented Apr 28, 2022

Hi @crisbeto , I fixed this PR to use the !menu.contains(document.activeElement), and it's ready for your eyes again.

@zarend zarend removed the action: merge The PR is ready for merge by the caretaker label May 3, 2022
crisbeto
crisbeto previously approved these changes May 3, 2022
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

src/material/menu/menu.ts Outdated Show resolved Hide resolved
…ceOver

When opening the menu using the iOS VoiceOver screen reader, focus the first item in the menu.
Previously, the first menu item would focus on other screen readers like desktop VoiceOver but
not with iOS VoiceOver.

Waiting until `onStable` seems to fix this.

Fixes angular#24735
@zarend zarend added the action: merge The PR is ready for merge by the caretaker label May 4, 2022
@zarend
Copy link
Contributor Author

zarend commented May 6, 2022

caretaker: please approve this again. Since @crisbeto approved it, I made the fix for this comment.

You can get rid of this whole loop with the following:

menuPanel = this._directDescendantItems.first!._getHostElement().closest('[role="menu"]');

@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 May 6, 2022
@zarend zarend merged commit f76103d into angular:main May 6, 2022
zarend added a commit that referenced this pull request May 6, 2022
…ceOver (#24733)

When opening the menu using the iOS VoiceOver screen reader, focus the first item in the menu.
Previously, the first menu item would focus on other screen readers like desktop VoiceOver but
not with iOS VoiceOver.

Waiting until `onStable` seems to fix this.

Fixes #24735

(cherry picked from commit f76103d)
zarend added a commit that referenced this pull request May 6, 2022
…ceOver (#24733)

When opening the menu using the iOS VoiceOver screen reader, focus the first item in the menu.
Previously, the first menu item would focus on other screen readers like desktop VoiceOver but
not with iOS VoiceOver.

Waiting until `onStable` seems to fix this.

Fixes #24735

(cherry picked from commit f76103d)
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request May 13, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`13.3.6` -> `13.3.7`](https://renovatebot.com/diffs/npm/@angular%2fcdk/13.3.6/13.3.7) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`13.3.6` -> `13.3.7`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/13.3.6/13.3.7) |

---

### Release Notes

<details>
<summary>angular/components</summary>

### [`v13.3.7`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1337-chiffon-carambola-2022-05-11)

[Compare Source](angular/components@13.3.6...13.3.7)

##### material

| Commit | Type | Description |
| -- | -- | -- |
| [0bede63d33](angular/components@0bede63) | fix | **datepicker:** add ability to have numeric zero value in input ([#&#8203;24813](angular/components#24813)) |
| [7a122f7f03](angular/components@7a122f7) | fix | **expansion:** inconsistent spacing for anchor buttons ([#&#8203;24882](angular/components#24882)) |
| [e486ed93e4](angular/components@e486ed9) | fix | **menu:** focus the first item when opening menu on iOS VoiceOver ([#&#8203;24733](angular/components#24733)) |

#### Special Thanks

Dmytro Prokhorov, Kristiyan Kostadinov and Zach Arend

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1349
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@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 6, 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/menu dev-app preview When applied, previews of the dev-app are deployed to Firebase merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note 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(menu): does not focus first item when opening with iOS VoiceOver
3 participants