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

Commit

Permalink
fix(general): common disabled behavior for switch/slider/select.
Browse files Browse the repository at this point in the history
Fixes #3797. Closes #4654.
  • Loading branch information
jelbourn authored and ThomasBurleson committed Sep 21, 2015
1 parent 11bcdcd commit bc3d4db
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 119 deletions.
11 changes: 8 additions & 3 deletions src/components/select/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<div>
<h1 class="md-title">Enter an address</h1>
<div layout="row">

<md-input-container>
<label>Street Name</label>
<input type="text"/>
<input>
</md-input-container>

<md-input-container>
<label>City</label>
<input type="text"/>
<input>
</md-input-container>

<md-input-container>
<label>State</label>
<md-select ng-model="ctrl.userState">
<md-option ng-repeat="state in ctrl.states" value="{{state.abbrev}}">{{state.abbrev}}</md-option>
<md-option ng-repeat="state in ctrl.states" value="{{state.abbrev}}">
{{state.abbrev}}
</md-option>
</md-select>
</md-input-container>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ angular.module('material.components.select', [
* </md-input-container>
* </hljs>
*/
function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $rootElement, $compile, $parse) {
function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $parse) {
return {
restrict: 'E',
require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'],
Expand Down Expand Up @@ -281,7 +281,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $rootElement,
});

attr.$observe('disabled', function(disabled) {
if (typeof disabled == "string") {
if (angular.isString(disabled)) {
disabled = true;
}
// Prevent click event being registered twice
Expand Down
19 changes: 11 additions & 8 deletions src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
$viewChangeListeners: []
};

var isDisabledParsed = attr.ngDisabled && $parse(attr.ngDisabled);
var isDisabledGetter = isDisabledParsed ?
function() { return isDisabledParsed(scope.$parent); } :
angular.noop;
var isDisabledGetter = angular.noop;
if (attr.disabled != null) {
isDisabledGetter = function() { return true; };
} else if (attr.ngDisabled) {
isDisabledGetter = angular.bind(null, $parse(attr.ngDisabled), scope.$parent);
}

var thumb = angular.element(element[0].querySelector('.md-thumb'));
var thumbText = angular.element(element[0].querySelector('.md-thumb-text'));
var thumbContainer = thumb.parent();
Expand Down Expand Up @@ -139,7 +142,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
ngModelRender();
redrawTicks();
}
setTimeout(updateAll);
setTimeout(updateAll, 0);

var debouncedUpdateAll = $$rAF.throttle(updateAll);
angular.element($window).on('resize', debouncedUpdateAll);
Expand Down Expand Up @@ -306,7 +309,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
function onPressDown(ev) {
if (isDisabledGetter()) return;

element.addClass('active');
element.addClass('md-active');
element[0].focus();
refreshSliderDimensions();

Expand All @@ -320,7 +323,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
function onPressUp(ev) {
if (isDisabledGetter()) return;

element.removeClass('dragging active');
element.removeClass('md-dragging md-active');

var exactVal = percentToValue( positionToPercent( ev.pointer.x ));
var closestVal = minMaxValidator( stepValidator(exactVal) );
Expand All @@ -334,7 +337,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
isDragging = true;
ev.stopPropagation();

element.addClass('dragging');
element.addClass('md-dragging');
setSliderFromEvent(ev);
}
function onDrag(ev) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/slider/slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ md-slider {
}

/* Don't animate left/right while panning */
&.dragging {
&.md-dragging {
.md-thumb-container,
.md-track-fill {
transition: none;
Expand All @@ -236,7 +236,7 @@ md-slider {
}

&:focus,
&.active {
&.md-active {
.md-focus-thumb {
display: block;
}
Expand All @@ -259,7 +259,7 @@ md-slider {

&:not([disabled]) {
&:focus,
&.active {
&.md-active {
.md-sign,
.md-sign:after {
opacity: 1;
Expand Down
Loading

0 comments on commit bc3d4db

Please sign in to comment.