Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(select): focus should behave as same as normal inputs
Browse files Browse the repository at this point in the history
Fixes #6122 Fixes #6185 Closes #6132 Fixes #6274
  • Loading branch information
devversion authored and rschmukler committed Dec 14, 2015
1 parent 1d71928 commit dc8f388
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
return function postLink(scope, element, attr, ctrls) {
var isDisabled, ariaLabelBase;

// Remove event ngModel's blur listener for touched and untouched
// we will do it ourself.
$mdUtil.nextTick(function() {
element.off('blur');
});

var containerCtrl = ctrls[0];
var mdSelectCtrl = ctrls[1];
var ngModelCtrl = ctrls[2];
Expand Down Expand Up @@ -283,7 +277,8 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
containerCtrl.setFocused(true);
}
})
.on('blur', function(ev) {
.on('blur', function() {
if (selectScope.isOpen) return;
containerCtrl && containerCtrl.setFocused(false);
inputCheckValue();
});
Expand Down Expand Up @@ -466,6 +461,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
}).finally(function() {
selectScope.isOpen = false;
element.focus();
element.attr('aria-expanded', 'false');
ngModelCtrl.$setTouched();
});
Expand Down
19 changes: 18 additions & 1 deletion src/components/select/select.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('<md-select>', function() {
fdescribe('<md-select>', function() {
var attachedElements = [],
body;

Expand Down Expand Up @@ -150,6 +150,23 @@ describe('<md-select>', function() {
//expect($document[0].activeElement).toBe(select[0]);
}));

it('should remove the input-container focus state', inject(function($rootScope) {
$rootScope.val = 0;
var element = setupSelect('ng-model="val"', [1, 2, 3]);
var select = element.find('md-select');
var controller = element.controller('mdInputContainer');
controller.setHasValue(true);

select.triggerHandler('focus');

expect(element.hasClass('md-input-focused')).toBe(true);

select.triggerHandler('blur');

expect(element.hasClass('md-input-focused')).toBe(false);

}));

describe('input container', function() {
it('should set has-value class on container for non-ng-model input', inject(function($rootScope, $document) {
var el = setupSelect('ng-model="$root.model"', [1, 2, 3]);
Expand Down

0 comments on commit dc8f388

Please sign in to comment.