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

Commit d5ac3bb

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(select): Disallow keyboard selection of disabled options.
Although disabled options are not selectable via the mouse or arrow keys, we currently allow users to select an option by typing the first few letters. This logic did not account for disabled options. Add a quick check to see if the requested option is disabled. Fixes #8626. Closes #8681
1 parent 4e2722c commit d5ac3bb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/components/select/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
517517
if (e.keyCode <= 90 && e.keyCode >= 31) {
518518
e.preventDefault();
519519
var node = selectMenuCtrl.optNodeForKeyboardSearch(e);
520-
if (!node) return;
520+
if (!node || node.hasAttribute('disabled')) return;
521521
var optionCtrl = angular.element(node).controller('mdOption');
522522
if (!selectMenuCtrl.isMultiple) {
523523
selectMenuCtrl.deselect(Object.keys(selectMenuCtrl.selected)[0]);

src/components/select/select.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,16 @@ describe('<md-select>', function() {
10981098
pressKey(el, 50);
10991099
expect($rootScope.someModel).toBe(2);
11001100
}));
1101+
1102+
it('disallows selection of disabled options', inject(function($rootScope) {
1103+
var optsTemplate =
1104+
'<md-option value="1">1</md-option>' +
1105+
'<md-option value="2" ng-disabled="true">2</md-option>';
1106+
var el = setupSelect('ng-model="someModel"', optsTemplate).find('md-select');
1107+
1108+
pressKey(el, 50);
1109+
expect($rootScope.someModel).toBe(undefined);
1110+
}));
11011111
});
11021112

11031113
describe('md-select-menu', function() {

0 commit comments

Comments
 (0)