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

Commit

Permalink
feat(select): add disabled support
Browse files Browse the repository at this point in the history
  • Loading branch information
rschmukler committed Feb 23, 2015
1 parent b6632e0 commit 0c0f25c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/select/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div ng-app="selectDemoBasic" ng-controller="AppCtrl" layout="column" layout-align="center center" style="min-height: 300px;">
<p>A select can be used to select a single element from a list:</p>
<md-select ng-model="neighborhood" placeholder="Neighborhood">
<md-select disabled ng-model="neighborhood" placeholder="Neighborhood">
<md-option ng-value="opt" ng-repeat="opt in neighborhoods">{{ opt }}</md-option>
</md-select>
<p class="result">{{ neighborhood ? 'You selected ' + neighborhood : 'You haven\'t selected a neighborhood yet' }}</p>
Expand Down
12 changes: 10 additions & 2 deletions src/components/select/select-theme.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
md-select.md-THEME_NAME-theme {
&:focus {
&:not([disabled]):focus {
.md-select-label {
border-bottom-color: '{{primary-color}}';
color: '{{ foreground-1 }}';
Expand All @@ -14,9 +14,17 @@ md-select.md-THEME_NAME-theme {
border-bottom-color: '{{warn-color}}';
}
}
&[disabled] {
.md-select-label {
color: '{{foreground-3}}';
&.md-placeholder {
color: '{{foreground-3}}';
}
}
}
.md-select-label {
&.md-placeholder {
color: '{{foreground-3}}';
color: '{{foreground-2}}';
}
border-bottom-color: '{{foreground-4}}';
}
Expand Down
17 changes: 15 additions & 2 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,22 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming) {
$mdTheming(element);

return function postLink(scope, element, attr, ngModel) {
element.on('click', openSelect);
attr.$observe('disabled', function(disabled) {
if (disabled !== undefined) {
element.attr('tabindex', -1);
element.off('click', openSelect);
element.off('keydown', openOnKeypress);
} else {
element.attr('tabindex', 0);
element.on('click', openSelect);
element.on('keydown', openOnKeypress);
}
});

element.on('keydown', openOnKeypress);
if (attr.disabled === undefined) {
element.on('click', openSelect);
element.on('keydown', openOnKeypress);
}

element.attr({
'role': 'combobox',
Expand Down
17 changes: 11 additions & 6 deletions src/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ $select-max-visible-options: 5;
md-select {
display: inline-block;
margin-top: 2.5 * $baseline-grid;
&:hover {
cursor: pointer
&[disabled]:hover {
cursor: default;
}
&:focus {
.md-select-label {
border-bottom: 2px solid;
padding-bottom: $baseline-grid - 1;
&:not([disabled]) {
&:hover {
cursor: pointer
}
&:focus {
.md-select-label {
border-bottom: 2px solid;
padding-bottom: $baseline-grid - 1;
}
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ describe('<md-select-menu>', function() {
}

function openSelect(el) {
el.triggerHandler('click');
waitForSelectOpen();
inject(function($timeout) {
$timeout.flush();
});
try {
el.triggerHandler('click');
waitForSelectOpen();
inject(function($timeout) {
$timeout.flush();
});
} catch(e) { }
}

function waitForSelectOpen() {
inject(function($rootScope, $animate) {
$rootScope.$digest();
$animate.triggerCallbacks();
});
try {
inject(function($rootScope, $animate) {
$rootScope.$digest();
$animate.triggerCallbacks();
});
} catch(e) { }
}

function pressKey(el, code) {
Expand All @@ -77,6 +81,13 @@ describe('<md-select-menu>', function() {
});
}

it('supports disabled state', inject(function($document) {
var select = setupSelect('disabled="disabled", ng-model="val"');
openSelect(select);
waitForSelectOpen();
expect($document.find('md-select-menu').length).toBe(0);
}));

it('errors for duplicate md-options, non-dynamic value', inject(function($rootScope) {
expect(function() {
setup('ng-model="$root.model"', '<md-option value="a">Hello</md-option>' +
Expand Down

0 comments on commit 0c0f25c

Please sign in to comment.