Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
* @param percent 0-1
*/
function setSliderPercent(percent) {

percent = clamp(percent);

var percentStr = (percent * 100) + '%';

activeTrack.css('width', percentStr);
Expand Down Expand Up @@ -380,6 +383,15 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
thumbText.text( closestVal );
}

/**
* Clamps the value to be between 0 and 1.
* @param {number} value The value to clamp.
* @returns {number}
*/
function clamp(value) {
return Math.max(0, Math.min(value || 0, 1));
}

/**
* Convert horizontal position on slider to percentage value of offset from beginning...
* @param x
Expand Down
13 changes: 12 additions & 1 deletion src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('md-slider', function() {
return slider;
}

it('should not set model below the min', function() {
var slider = setup('ng-model="value" min="0" max="100"');
pageScope.$apply('value = -50');
expect(slider.attr('aria-valuenow')).toEqual('0');
});

it('should not set model above the max', function() {
var slider = setup('ng-model="value" min="0" max="100"');
pageScope.$apply('value = 150');
expect(slider.attr('aria-valuenow')).toEqual('100');
});

it('should set model on press', function() {
var slider = setup('ng-model="value" min="0" max="100"');
pageScope.$apply('value = 50');
Expand Down Expand Up @@ -239,7 +251,6 @@ describe('md-slider', function() {
expect(slider).not.toHaveClass('md-max');
});


it('should increment at a predictable step', function() {

buildSlider(0.1, 0, 1).drag({x:70});
Expand Down