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

fix(select): improve focus/blur handling on iOS #11739

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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