-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
mat-menu trigger button is highlighted after closing menu #9292
Comments
This is not a bug, it's working as expected: #9252 (comment) You can set the focus in other element on |
Well, the actual issue isn't the keyboard focus itself, but that the button has the focus style after clicking, whereas other buttons does not, unless you use the keyboard (where it makes sense). That a menu is attached should be irrelevant to how the button is styled after clicking. I'll edit the issue to reflect that. But thanks for the workaround (though I hope to remove the styling, not the actual keyboard focus)! |
It seems like the wrong class is applied when closing the menu, here's my workaround (attached to the close handler of the menu, not the trigger, as the trigger event does not specify the source): menuClosed(event: void | 'click' | 'keydown') {
if (event !== 'keydown') { // void is clicking on the backdrop
window.setTimeout(() => {
this.favoriteMenuTrigger.nativeElement.classList.remove('cdk-program-focused');
this.favoriteMenuTrigger.nativeElement.classList.add('cdk-mouse-focused');
}, 0);
}
} Not entirely sure why the timeout is needed, but without it, |
Nice to hear that you managed to do it, @LosD! But what you did is exactly what I would do. Other approach (if you don't wanna rely on classes names and don't wanna keep focus), is create another focusable component out of the end user sight: <input style="position: fixed; top: -2000; left; -2000" #elToFocus> and, in code do something like (inside of your this._elToFocus.nativeElement.focus(); The |
@julianobrasil The problem with changing the actual focus is that it messes with the user's tab position, so going back to the keyboard can be confusing. I understand what |
Sets the correct focus origin depending on the way a menu has been opened. Fixes angular#9292.
Sets the correct focus origin depending on the way a menu has been opened. Fixes angular#9292.
Sets the correct focus origin depending on the way a menu has been opened. Fixes angular#9292.
Sets the correct focus origin depending on the way a menu has been opened. Fixes #9292.
Sets the correct focus origin depending on the way a menu has been opened. Fixes #9292.
Sets the correct focus origin depending on the way a menu has been opened. Fixes angular#9292.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
Trigger button acts like other buttons: When action has completed, button returns to the neutral state.

... Actual keyboard focus stays, but the styling is back to neutral, when using the mouse to click (for keyboard navigation it stays lit... Which makes sense).
What is the current behavior?
Trigger button stay focused, and keeps the focused style.

What are the steps to reproduce?
What is the use-case or motivation for changing an existing behavior?
Consistency. Other buttons does not keep the focus styling, menu triggers shouldn't either.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Seen on:
Angular 5.0.0, 5.1.3
Material 5.0.2, 5.0.3
Linux, Windows
TypeScript 2.5.3 + whatever TypeScript is running on StackBlitz
Internet Explorer 11, Chrome 63.0.3239.84, FireFox 57.0.3, EdgeHTML 16.16299
Is there anything else we should know?
May be related to fix in #8348 (don't really think so, though, I think I've seen this behavior for a long time. It used to have the same problem when expanding sidebars using a button)
The text was updated successfully, but these errors were encountered: