Autofocus input elements
Is there a solution to set autofocus for input elements which use the md-input-container?
The following example is not working:
<md-input-container>
<label>Username</label>
<input ng-model="user.name" type="text" autofocus>
</md-input-container>
My current workaround is adding focus to the input and the class md-input-focused to md-input-container myself.
I also ran into this and like you ended up setting focus manually, with $timeout, but in my experience calling .focus() was sufficient, I didn't manually add md-input-focused class. If autofocus was supported, would be a nice addition.
When I just call .focus() then the focus is set for the input field, but it doesn't have the angular material design (colored bottom border).
Hmm that's strange, because in my case it does get the colored bottom border. As far as I understand, calling focus() should have the same result as for instance tabbing to the input, the focus event should trigger the class change.
Isn't this what md-autofocus does? If I am not misunderstanding this the issue should be closed.
<md-input-container>
<label>Username</label>
<input ng-model="user.name" type="text" md-autofocus>
</md-input-container>
@SnakeME did you got your answer from @adrianandreias? (thanks!)
md-autofocus is not working for me (using v1.0.1).
http://codepen.io/anon/pen/zrdmaW
@SnakeME are you trying to use dialog/autocomplete/bottomsheet/sidenav?
maybe we should add support for just input container
My case has nothing to do with dialog/autocomplete/bottomsheet/sidenav. I just want to set autofocus for a standart input container. Like this attribute: http://www.w3schools.com/tags/att_input_autofocus.asp
But wether the HTML attribute nor md-autofocus are working.
<form name="userForm">
<md-input-container class="md-block">
<label>Input-autofocus</label>
<input ng-model="user.firstName" type="text" autofocus>
</md-input-container>
<md-input-container class="md-block">
<label>Input-md-autofocus</label>
<input ng-model="user.title" type="text" md-autofocus>
</md-input-container>
</form>
Both attributes seem to be ignored.
I've updated the codepen http://codepen.io/anon/pen/zrdmaW
I can confirm that md-autofocus is not working in a simple page, but only in dialogs (as described in #6680).
(Initially you asked if there is a solution: there's is one, just that not working due to a bug :) ).
The fix for this bug is probably related to #6679 as well
:+1:
I just ran into this issue and was able to get it to work correctly until a proper fix can be implemented by using md-autofocus="autofocus" instead of md-autofocus alone.
Running into an issue here as well. In my case, I tried md-autofocus and md-autofocus="autofocus" on both the input itself and the md-input-container. None of the combinations worked.
Currently I have autofocus on the input. If the site is loaded on the sign-in page (for example), it works as intended. If the home page is loaded and I navigate to the sign-in page, it looks like it focuses then immediately blurs, triggering the validation on the field.
[EDIT] I just realized that the focus-blur thing is only happening when the side nav is hidden (md or smaller). If the browser window is large and the side nav is locked open (gt-md), autofocus works just fine.
I'm using v1.0.5 with Angular v1.5.0.
I want my input field to be focused when i change "md-tab" or md-tab-selected
I tried also md-autofocus and md-autofocus="autofocus" on both the input itself and the md-input-container. None of the combinations worked.
@EladBezalel - I'm having this problem too. I'm trying to focus an input when loading a simple form, and as @Kizmar, I tried all the combinations without success. I updated @SnakeME's codepen to show that neither autofocus or md-autofocus are working on text inputs or textareas (using Angular 1.4.8 and Angular Material 1.1.0-rc2).
So we are trying to implement a whole form using Angular Material and we keep running into this issues with basic functionality, like we did with https://github.com/angular/material/issues/4233.
It's very frustrating that these basic behaviors aren't working and are not even considered important. I don't get what needs to be discussed on this issue and how a P1 issue is still in the backlog.
+1
Having the same issue!
+1
having the same issue that by calling .focus() the coloured bottom border doesn't appear. It does set the cursor inside the input and works for typing but no material bottom border.
I should mention that this happens on Chrome Version 49.0.2623.110 (64-bit). Works fine when I try it on Safari.
I am neither able to set or remove focus from mddialog input element on mobile browsers. When the dialog is shown it randomly focuses on any one element, during which time the keyboard tries to come up and the dialog repositions,but then the focus goes away and the keyboard disappears and the dialog stays without focus.
So the whole interaction is very jerky currently. is there a fix for either forcing focus on one element so the keyboard stays either open or close?
@srinivasmangipudi - I'm using this workaround for setting the focus upon activation. I haven't tested on mobile browsers though.
function setDefaultFocus() {
if (scope.activated) {
angular.element('textarea[name=name]').focus();
} else {
$timeout(function () {
setDefaultFocus();
}, 300);
}
}
I'm having an issue using ng-repeat and md-bottomsheet. I'm repeating a series of cards and each card has a bottom sheet. When I activate the bottomsheet on one card, it only ever pulls open the bottomsheet on the first card.
I believe the error has to do with my mis-use of md-autofocus. Let me know if I should open a new thread. Thanks