I'm having an issue with the cursor placement when using autofocus in IE. The image should display the issue clearly.
Luckily I've been able to reproduce this in a plunker. I've stripped it down to the bare essentials, so it should be easy enough to see what's going on.
How do I make IE behave?
AngularJS (Also available in the plunker)
app.directive('autofocus', [
'$timeout', function($timeout) {
return function(scope, elem, attr) {
scope.$on('autofocus', function(e) {
$timeout(function() {
elem[0].focus();
});
});
};
}
]);
/* http://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs */
app.factory('autofocus', ['$rootScope', '$timeout', function($rootScope, $timeout) {
return function() {
$timeout(function() {
$rootScope.$broadcast('autofocus');
});
};
}]);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('main', {
url: '/main'
});
}]);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('main.modal', {
url: '/modal',
onEnter: ['$state', '$stateParams', '$modal', 'autofocus',
function ($state, $stateParams, $modal, autofocus) {
var instance = $modal.open({
templateUrl: 'modal.html'
});
instance.result.then(function () {
// OK
// GOTO parent state
$state.go('^');
}, function () {
// Cancel
// GOTO parent state
$state.go('^');
});
instance.opened.then(function() {
autofocus();
});
}
]
});
}]);
Markup
<form>
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<input type="text" name="foo" autofocus>
<br>
<input type="text" name="bar">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">OK</button>
<button type="button" class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
</div>
</form>