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

Commit dc8f388

Browse files
devversionrschmukler
authored andcommitted
fix(select): focus should behave as same as normal inputs
Fixes #6122 Fixes #6185 Closes #6132 Fixes #6274
1 parent 1d71928 commit dc8f388

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/components/select/select.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
187187
return function postLink(scope, element, attr, ctrls) {
188188
var isDisabled, ariaLabelBase;
189189

190-
// Remove event ngModel's blur listener for touched and untouched
191-
// we will do it ourself.
192-
$mdUtil.nextTick(function() {
193-
element.off('blur');
194-
});
195-
196190
var containerCtrl = ctrls[0];
197191
var mdSelectCtrl = ctrls[1];
198192
var ngModelCtrl = ctrls[2];
@@ -283,7 +277,8 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
283277
containerCtrl.setFocused(true);
284278
}
285279
})
286-
.on('blur', function(ev) {
280+
.on('blur', function() {
281+
if (selectScope.isOpen) return;
287282
containerCtrl && containerCtrl.setFocused(false);
288283
inputCheckValue();
289284
});
@@ -466,6 +461,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
466461
loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
467462
}).finally(function() {
468463
selectScope.isOpen = false;
464+
element.focus();
469465
element.attr('aria-expanded', 'false');
470466
ngModelCtrl.$setTouched();
471467
});

src/components/select/select.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('<md-select>', function() {
1+
fdescribe('<md-select>', function() {
22
var attachedElements = [],
33
body;
44

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

153+
it('should remove the input-container focus state', inject(function($rootScope) {
154+
$rootScope.val = 0;
155+
var element = setupSelect('ng-model="val"', [1, 2, 3]);
156+
var select = element.find('md-select');
157+
var controller = element.controller('mdInputContainer');
158+
controller.setHasValue(true);
159+
160+
select.triggerHandler('focus');
161+
162+
expect(element.hasClass('md-input-focused')).toBe(true);
163+
164+
select.triggerHandler('blur');
165+
166+
expect(element.hasClass('md-input-focused')).toBe(false);
167+
168+
}));
169+
153170
describe('input container', function() {
154171
it('should set has-value class on container for non-ng-model input', inject(function($rootScope, $document) {
155172
var el = setupSelect('ng-model="$root.model"', [1, 2, 3]);

0 commit comments

Comments
 (0)