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

mat-menu is acting differently when triggered via keyboard vs mouse #9252

Closed
mertdeg2 opened this issue Jan 5, 2018 · 8 comments · Fixed by #9383
Closed

mat-menu is acting differently when triggered via keyboard vs mouse #9252

mertdeg2 opened this issue Jan 5, 2018 · 8 comments · Fixed by #9383
Assignees
Labels
Accessibility This issue is related to accessibility (a11y) G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround

Comments

@mertdeg2
Copy link
Contributor

mertdeg2 commented Jan 5, 2018

Bug, feature request, or proposal:

Bug

What is the expected behavior?

User clicks on the mat-menu trigger button, and first item within menu (or the entire menu) is focused.

What is the current behavior?

User clicks on the mat-menu trigger button, the button stays focused. This creates couple of accessibility issues. Note that if its triggered via keyboard this issue doesn't repro thanks to this logic: https://github.com/angular/material2/blob/3728555c6e37dbeb1756366c797c99655d8ffa1f/src/lib/menu/menu-trigger.ts#L240

What are the steps to reproduce?

  1. Go to https://stackblitz.com/angular/lrpbkepagev?file=app%2Fmenu-overview-example.html
  2. Click on the menu button
  3. Note that focus stays on the button (print document.activeElement)

Note that if you do this via keyboard, the first focusable element within mat-menu is focused.

What is the use-case or motivation for changing an existing behavior?

We have a tooltip component that stays open when a button is focused. When there is a tooltip and a menu attached to a component, click on the menu trigger button will result in both tooltip and menu showing. Once user clicks on menu, the menu component should take away to focus (like it does when its triggered via keyboard). This would also make sure screen readers announce the right content.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

All

@mertdeg2
Copy link
Contributor Author

mertdeg2 commented Jan 5, 2018

@jelbourn

@crisbeto
Copy link
Member

crisbeto commented Jan 5, 2018

If I remember correctly, the reasoning behind only focusing the first item when the menu is opened by keyboard was because there was something explicit about it in the spec, however I'm having a hard time finding it.

As for the case when it's opened by keyboard, focus seems to be moved correctly onto the menu panel (you can check it by throwing this in the console and trying to open by click: setInterval(_ => console.log(document.activeElement), 1000);. Note that focus will be restored to the button once the menu is closed.

@mertdeg2
Copy link
Contributor Author

mertdeg2 commented Jan 5, 2018

Thanks for explanation on this @crisbeto! With current behavior, when the user clicks on the menu screen readers don't announce anything different. I think this will cause accessibility issues for visually impaired users who use mouse.

This would also be inline with HTML <select/> implementation.

@jelbourn jelbourn added G This is is related to a Google internal issue Accessibility This issue is related to accessibility (a11y) P2 The issue is important to a large percentage of users, with a workaround labels Jan 5, 2018
@jelbourn
Copy link
Member

jelbourn commented Jan 5, 2018

There's nothing explicit in the spec, but the implied behavior is that the focus style only shows when the menu is opened by keyboard. This happens because the focus treatment is the same as the hover treatment and most users get confused and think it's a bug.

I think we should make both keyboard and mouse work the same WRT what gets focused but only show the initial focus style when the interaction was through keyboard. I vaguely recall this coming up before for another component- maybe the select?

crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 14, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes angular#9252.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 14, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes angular#9252.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 16, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes angular#9252.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 16, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes angular#9252.
jelbourn pushed a commit that referenced this issue Jan 21, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes #9252.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 22, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes angular#9252.
jelbourn pushed a commit that referenced this issue Jan 23, 2018
* Switches to always focusing the first menu item, even when opening by mouse. The focus styling will only apply when focused by keyboard.
* Adds the ability to set the focus origin through the `FocusKeyManager`.

Fixes #9252.
@alexandermikuta
Copy link

It looks like the problem still (or again) exists as can be seen at: https://material.angular.io/components/menu/examples

@crisbeto
Copy link
Member

I don't see the issue @alexandermikuta. Focus does get moved to the button when you open it using the mouse, we just decide not to change the styling in this particular case.

@alexandermikuta
Copy link

@crisbeto It seems with the latest material-website update the issue is gone. I can not reproduce my error from yesterday anymore.

@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 Sep 8, 2019
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) G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants