From e49951c6e9aebdb8a9e0fa3068393da460680dfe Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 7 Dec 2015 21:22:27 +0100 Subject: [PATCH] fix(select): set the focus to false if the model is undefined or if the model was added without focus. Fixes #6122 --- src/components/select/select.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/select/select.js b/src/components/select/select.js index 6108031fd24..6461b55397d 100755 --- a/src/components/select/select.js +++ b/src/components/select/select.js @@ -245,6 +245,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par syncLabelText(); syncAriaLabel(); inputCheckValue(); + inputCheckFocus(); }; attr.$observe('placeholder', ngModelCtrl.$render); @@ -344,6 +345,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par syncLabelText(); syncAriaLabel(); inputCheckValue(); + inputCheckFocus(); }; ngModelCtrl.$render(); } @@ -408,6 +410,11 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par containerCtrl && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput); } + function inputCheckFocus() { + // We should set the focus to false if the model is undefined or if the model was added without focus + containerCtrl && containerCtrl.setFocused(!!ngModelCtrl.$modelValue && containerCtrl.element.hasClass('md-input-focused')); + } + function findSelectContainer() { selectContainer = angular.element( element[0].querySelector('.md-select-menu-container')