From 0284b132c4b4b8245e0c847b08ec62ddc4b49084 Mon Sep 17 00:00:00 2001 From: Michael Prentice Date: Mon, 12 Aug 2019 17:55:42 -0400 Subject: [PATCH] fix(select): improve focus/blur handling on iOS (#11739) also fix focus jumping back to md-select after tapping another input Fixes #11345 --- src/components/select/select.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/select/select.js b/src/components/select/select.js index 8d587a65c34..1675cd6c9bf 100755 --- a/src/components/select/select.js +++ b/src/components/select/select.js @@ -362,16 +362,9 @@ 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) { @@ -379,10 +372,17 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $ } } - 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() { @@ -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) @@ -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(); });