From 4cfedab8058b583067136075c36c19204d09f1f5 Mon Sep 17 00:00:00 2001 From: Elad Bezalel Date: Mon, 9 Nov 2015 02:05:08 +0200 Subject: [PATCH] fix(select): disabled option no longer reacting to hover and closing on click Added a not disabled check before closing menu, Now when clicking the menu anywhere but a valid option the menu closing will be prevented fixes #4967 --- src/components/select/select-theme.scss | 2 +- src/components/select/select.js | 14 ++++++++------ src/components/select/select.spec.js | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/select/select-theme.scss b/src/components/select/select-theme.scss index e45fbe236a6..136a937e8d0 100644 --- a/src/components/select/select-theme.scss +++ b/src/components/select/select-theme.scss @@ -64,7 +64,7 @@ md-select-menu.md-THEME_NAME-theme { } } } - md-option:focus:not([selected]) { + md-option:focus:not([disabled]):not([selected]) { background: '{{background-200}}'; } diff --git a/src/components/select/select.js b/src/components/select/select.js index 76f8f183110..9d4deb6426c 100755 --- a/src/components/select/select.js +++ b/src/components/select/select.js @@ -1199,14 +1199,16 @@ function SelectProvider($$interimElementProvider) { if (ev && ( ev.type == 'mouseup') && (ev.currentTarget != dropDown[0])) return; if ( mouseOnScrollbar() ) return; - if (!selectCtrl.isMultiple) { - opts.restoreFocus = true; + var option = $mdUtil.getClosest(ev.target, 'md-option'); + if (option && option.hasAttribute && !option.hasAttribute('disabled')) { + if (!selectCtrl.isMultiple) { + opts.restoreFocus = true; - $mdUtil.nextTick(function() { - $mdSelect.hide(selectCtrl.ngModel.$viewValue); - }, true); + $mdUtil.nextTick(function () { + $mdSelect.hide(selectCtrl.ngModel.$viewValue); + }, true); + } } - /** * check if the mouseup event was on a scrollbar */ diff --git a/src/components/select/select.spec.js b/src/components/select/select.spec.js index a4c676df4f9..fbc73ad7b30 100755 --- a/src/components/select/select.spec.js +++ b/src/components/select/select.spec.js @@ -843,7 +843,7 @@ describe('', function() { if (angular.isArray(options)) { $rootScope.$$values = options; var renderValueAs = compileOpts ? compileOpts.renderValueAs || 'value' : 'value'; - optionsTpl = '{{' + renderValueAs + '}}'; + optionsTpl = '
{{' + renderValueAs + '}}
'; } else if (angular.isString(options)) { optionsTpl = options; } @@ -898,7 +898,7 @@ describe('', function() { function clickOption(index) { inject(function($rootScope, $document) { var openMenu = $document.find('md-select-menu'); - var opt = $document.find('md-option')[index]; + var opt = angular.element($document.find('md-option')[index]).find('div')[0]; if (!openMenu.length) throw Error('No select menu currently open'); if (!opt) throw Error('Could not find option at index: ' + index); @@ -909,6 +909,7 @@ describe('', function() { }); angular.element(openMenu).triggerHandler({ type: 'mouseup', + target: target, currentTarget: openMenu[0] }); });