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

Commit ab0ffc4

Browse files
EladBezalelThomasBurleson
authored andcommitted
fix(select): disabled option no longer reacting to hover and closing on click
Check disabled attribute before closing menu. When clicking the menu anywhere but a valid option the menu closing will be prevented fixes #4967. Closes #5619.
1 parent 1a2035b commit ab0ffc4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/components/select/select-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ md-select-menu.md-THEME_NAME-theme {
6464
}
6565
}
6666
}
67-
md-option:focus:not([selected]) {
67+
md-option:focus:not([disabled]):not([selected]) {
6868
background: '{{background-200}}';
6969
}
7070

src/components/select/select.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,14 +1202,16 @@ function SelectProvider($$interimElementProvider) {
12021202
if (ev && ( ev.type == 'mouseup') && (ev.currentTarget != dropDown[0])) return;
12031203
if ( mouseOnScrollbar() ) return;
12041204

1205-
if (!selectCtrl.isMultiple) {
1206-
opts.restoreFocus = true;
1205+
var option = $mdUtil.getClosest(ev.target, 'md-option');
1206+
if (option && option.hasAttribute && !option.hasAttribute('disabled')) {
1207+
if (!selectCtrl.isMultiple) {
1208+
opts.restoreFocus = true;
12071209

1208-
$mdUtil.nextTick(function() {
1209-
$mdSelect.hide(selectCtrl.ngModel.$viewValue);
1210-
}, true);
1210+
$mdUtil.nextTick(function () {
1211+
$mdSelect.hide(selectCtrl.ngModel.$viewValue);
1212+
}, true);
1213+
}
12111214
}
1212-
12131215
/**
12141216
* check if the mouseup event was on a scrollbar
12151217
*/

src/components/select/select.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ describe('<md-select>', function() {
843843
if (angular.isArray(options)) {
844844
$rootScope.$$values = options;
845845
var renderValueAs = compileOpts ? compileOpts.renderValueAs || 'value' : 'value';
846-
optionsTpl = '<md-option ng-repeat="value in $$values" ng-value="value">{{' + renderValueAs + '}}</md-option>';
846+
optionsTpl = '<md-option ng-repeat="value in $$values" ng-value="value"><div class="md-text">{{' + renderValueAs + '}}</div></md-option>';
847847
} else if (angular.isString(options)) {
848848
optionsTpl = options;
849849
}
@@ -898,7 +898,7 @@ describe('<md-select>', function() {
898898
function clickOption(index) {
899899
inject(function($rootScope, $document) {
900900
var openMenu = $document.find('md-select-menu');
901-
var opt = $document.find('md-option')[index];
901+
var opt = angular.element($document.find('md-option')[index]).find('div')[0];
902902

903903
if (!openMenu.length) throw Error('No select menu currently open');
904904
if (!opt) throw Error('Could not find option at index: ' + index);
@@ -909,6 +909,7 @@ describe('<md-select>', function() {
909909
});
910910
angular.element(openMenu).triggerHandler({
911911
type: 'mouseup',
912+
target: target,
912913
currentTarget: openMenu[0]
913914
});
914915
});

0 commit comments

Comments
 (0)