Commit e44d5770 authored by Robert Knight's avatar Robert Knight

Merge pull request #2747 from hypothesis/179-focus-in-username-field-when-sign-in-is-clicked

Keyboard focus the login form when shown
parents 3b2bd157 3bf49a2e
...@@ -109,6 +109,7 @@ module.exports = angular.module('h', [ ...@@ -109,6 +109,7 @@ module.exports = angular.module('h', [
.directive('formInput', require('./directive/form-input')) .directive('formInput', require('./directive/form-input'))
.directive('formValidate', require('./directive/form-validate')) .directive('formValidate', require('./directive/form-validate'))
.directive('groupList', require('./directive/group-list').directive) .directive('groupList', require('./directive/group-list').directive)
.directive('hAutofocus', require('./directive/h-autofocus'))
.directive('markdown', require('./directive/markdown')) .directive('markdown', require('./directive/markdown'))
.directive('simpleSearch', require('./directive/simple-search')) .directive('simpleSearch', require('./directive/simple-search'))
.directive('statusButton', require('./directive/status-button')) .directive('statusButton', require('./directive/status-button'))
......
'use strict';
/** An attribute directive that focuses an <input> when it's linked by Angular.
*
* The HTML5 autofocus attribute automatically puts the keyboard focus in an
* <input> on page load. But this doesn't work for <input>s that are
* rendered by JavaScript/Angular after page load, for example an <input> that
* is shown/hidden by JavaScript when an ng-if condition becomes true.
*
* To automatically put the keyboard focus on such an input when it's linked by
* Angular, attach this directive to it as an attribute:
*
* <input ng-if="..." h-autofocus>
*
*/
module.exports = function() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.focus();
}
};
};
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<input class="form-input" type="text" id="field-login-username" <input class="form-input" type="text" id="field-login-username"
name="username" value="" name="username" value=""
ng-model="model.username" ng-model="model.username"
required autocapitalize="false" /> required autocapitalize="false" h-autofocus />
<ul class="form-error-list"> <ul class="form-error-list">
<li class="form-error" <li class="form-error"
ng-show="login.username.$error.required" ng-show="login.username.$error.required"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment