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

Commit 0284b13

Browse files
Splaktarmmalerba
authored andcommitted
fix(select): improve focus/blur handling on iOS (#11739)
also fix focus jumping back to md-select after tapping another input Fixes #11345
1 parent bc7833b commit 0284b13

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/components/select/select.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,27 +362,27 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
362362
};
363363

364364
if (!isReadonly) {
365-
element
366-
.on('focus', function(ev) {
367-
// Always focus the container (if we have one) so floating labels and other styles are
368-
// applied properly
369-
containerCtrl && containerCtrl.setFocused(true);
370-
});
371-
372-
// Attach before ngModel's blur listener to stop propagation of blur event
373-
// to prevent from setting $touched.
374-
element.on('blur', function(event) {
365+
var handleBlur = function(event) {
366+
// Attach before ngModel's blur listener to stop propagation of blur event
367+
// and prevent setting $touched.
375368
if (untouched) {
376369
untouched = false;
377370
if (selectScope._mdSelectIsOpen) {
378371
event.stopImmediatePropagation();
379372
}
380373
}
381374

382-
if (selectScope._mdSelectIsOpen) return;
383375
containerCtrl && containerCtrl.setFocused(false);
384376
inputCheckValue();
385-
});
377+
};
378+
var handleFocus = function(ev) {
379+
// Always focus the container (if we have one) so floating labels and other styles are
380+
// applied properly
381+
containerCtrl && containerCtrl.setFocused(true);
382+
};
383+
384+
element.on('focus', handleFocus);
385+
element.on('blur', handleBlur);
386386
}
387387

388388
mdSelectCtrl.triggerClose = function() {
@@ -510,7 +510,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
510510
});
511511

512512

513-
514513
function inputCheckValue() {
515514
// The select counts as having a value if one or more options are selected,
516515
// or if the input's validity state says it has bad input (eg string in a number input)
@@ -573,7 +572,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
573572
loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
574573
}).finally(function() {
575574
selectScope._mdSelectIsOpen = false;
576-
element.focus();
577575
element.attr('aria-expanded', 'false');
578576
ngModelCtrl.$setTouched();
579577
});

0 commit comments

Comments
 (0)