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

Commit

Permalink
fix(mdSelect): fix flickering of ngMessages on mdSelect opening
Browse files Browse the repository at this point in the history
To properly prevent ngMessages from showing up on select opening,
we have to stop blur event propagation to ngModel listener.
To be close to mdInput behaviour, we do it only, when mdSelect was opened.

closes #7636

Closes #7646
  • Loading branch information
montgomery1944 authored and ThomasBurleson committed Apr 1, 2016
1 parent a543def commit b54f7ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,19 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
}
});

// Wait until postDigest so that we attach after ngModel's
// blur listener so we can set untouched.
$mdUtil.nextTick(function () {
element.on('blur', function() {
if (untouched) {
untouched = false;
ngModelCtrl.$setUntouched();
// Attach before ngModel's blur listener to stop propagation of blur event
// to prevent from setting $touched.
element.on('blur', function(event) {
if (untouched) {
untouched = false;
if (selectScope.isOpen) {
event.stopImmediatePropagation();
}
}

if (selectScope.isOpen) return;
containerCtrl && containerCtrl.setFocused(false);
inputCheckValue();
});
if (selectScope.isOpen) return;
containerCtrl && containerCtrl.setFocused(false);
inputCheckValue();
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ describe('<md-select>', function() {
expect($rootScope.myForm.select.$touched).toBe(true);
}));

it('should remain untouched during opening', inject(function($compile, $rootScope) {
var form = $compile('<form name="myForm">' +
'<md-select name="select" ng-model="val">' +
'<md-option>1</md-option>' +
'</md-select>' +
'</form>')($rootScope);
var unwatch = $rootScope.$watch('myForm.select.$touched',
function(touched) {
expect(touched).toBe(false);
});
var select = form.find('md-select');
openSelect(select);
unwatch();
closeSelect();
expect($rootScope.myForm.select.$touched).toBe(true);
}));

it('restores focus to select when the menu is closed', inject(function($document) {
var select = setupSelect('ng-model="val"').find('md-select');
openSelect(select);
Expand Down

0 comments on commit b54f7ed

Please sign in to comment.