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

Commit

Permalink
fix(select): improve focus/blur handling on iOS (#11739)
Browse files Browse the repository at this point in the history
also fix focus jumping back to md-select after tapping another input

Fixes #11345
  • Loading branch information
Splaktar authored and mmalerba committed Aug 12, 2019
1 parent bc7833b commit 0284b13
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,27 +362,27 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
};

if (!isReadonly) {
element
.on('focus', function(ev) {
// Always focus the container (if we have one) so floating labels and other styles are
// applied properly
containerCtrl && containerCtrl.setFocused(true);
});

// Attach before ngModel's blur listener to stop propagation of blur event
// to prevent from setting $touched.
element.on('blur', function(event) {
var handleBlur = function(event) {
// Attach before ngModel's blur listener to stop propagation of blur event
// and prevent setting $touched.
if (untouched) {
untouched = false;
if (selectScope._mdSelectIsOpen) {
event.stopImmediatePropagation();
}
}

if (selectScope._mdSelectIsOpen) return;
containerCtrl && containerCtrl.setFocused(false);
inputCheckValue();
});
};
var handleFocus = function(ev) {
// Always focus the container (if we have one) so floating labels and other styles are
// applied properly
containerCtrl && containerCtrl.setFocused(true);
};

element.on('focus', handleFocus);
element.on('blur', handleBlur);
}

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



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

0 comments on commit 0284b13

Please sign in to comment.