-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
help(matMenu): Auto focusing text box after clicking on a menu item #18750
Comments
Hi, there's any easy soulution for your problem. This is not a bug, it works as intended. MatMenu restores the focus by default, this is why you lost focus after focusing your input synchronously. There's an option to disable this beahaviour => matMenuTriggerRestoreFocus. With that your code works without setTimeout. StackBlitz |
I see. That solves my problem. Thanks @Totati ! Then there is actually a solution to #11696. Just nobody can post it under that issue. Then I have one last question: is it a valid feature request to add another option to "move focus back to trigger button only when the focus is not inside the menu before menu closes"? I think that would be of great help for my scenario, without any extra code to take care of accessibility. |
If I understand this PR correctly, while it enables consumer to move focus to elsewhere in However, that makes it possible for consumer to manually restore focus after the menu closes, without accessibility implications, so it helps anyway 😃 |
Closing this since I think the combination of |
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. |
What are you trying to do?
click
callback.matMenu
to stop moving focus to the triggering button when closing the menu, if user's focus is not insidematMenu
at the time just before the menu closes? (something like Option for menu not to return focus to the assoicated button #11696, but with a pre-condition)What troubleshooting steps have you tried?
I need to use
setTimeout(..., 0)
to defer moving focus to text box, so the focus will be moved to the menu-triggering button, then moved to the text box at last. However, this looks flaky to me and I'm not sure if it's the best practice.Reproduction
https://stackblitz.com/edit/angular-component-mat-menu-focus?file=src%2Fapp%2Ftext-editor%2Ftext-editor.component.ts
Steps to reproduce:
text-editor.component.ts
.In the app, you can edit the text with "Edit" menu item. That's expected behavior.
Remove
setTimeout
, callingfocus
directly insteadEnvironment
The text was updated successfully, but these errors were encountered: