Dialog Focus on Input
Bug, feature request, or proposal:
When opening a dialog with an embedded input, focus cannot be assigned to to the embedded input.
What is the expected behavior?
Should be able to assign focus to embedded input either using a directive or the @ViewChild annotation.
What is the current behavior?
Using a directive that assigns focus in the parent, results in no behavior at all. Using the @ViewChild, an exception is thrown.
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
What are the steps to reproduce?
Create a md-dialog with an embedded component that implements AfterInitView that contains an <input #firstInput>. Assign focus using @ViewChild in the dialog component and assign focus in afterViewInit of dialog component. Plunker : https://plnkr.co/edit/tWaoUj?p=info **Note this is the first time I have used plunker. I might have messed up the config, but the components are all there. Also, please note that the template you guys have above doesn't load anything either. It just gets stuck on "Loading the Angular Material App..."
What is the use-case or motivation for changing an existing behavior?
I am rewriting an old As400 application for bulk data entry. I need to be able to automatically focus on the input field once the dialog opens. The operators aren't use to and don't like mice.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
I have tried in Firefox and Chrome. They both exhibit similar behavior.
Is there anything else we should know?
When I step debug in Chrome dev tools, the input actually gets focus, but the exception gets thrown. If remove the breakpoint the input doesn't get focus and the exception is thrown.
I wasn't preventing the default behavior of F6; F6 apparently is a browser hot key that moves the focus to the browser url.
`switch (event.keyCode) {
case 117:
event.preventDefault();
this.openAddAveragesDialog();
break;
default:
return;
}`
This resolved the issue.
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.