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

Commit

Permalink
fix(md-slider): set step property relative to min
Browse files Browse the repository at this point in the history
Closes #4403. Fixes #4385.
  • Loading branch information
karolkochan authored and ThomasBurleson committed Oct 17, 2015
1 parent 23a7f02 commit 441cbf1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
}
function stepValidator(value) {
if (angular.isNumber(value)) {
var formattedValue = (Math.round(value / step) * step);
var formattedValue = (Math.round((value - min) / step) * step + min);
// Format to 3 digits after the decimal point - fixes #2015.
return (Math.round(formattedValue * 1000) / 1000);
}
Expand Down
17 changes: 10 additions & 7 deletions src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('md-slider', function() {

it('should disable via the `disabled` attribute', function() {
var slider = setup('disabled');

// Check for disabled state by triggering the pressdown handler and asserting that
// the slider is not active.
slider.triggerHandler({
Expand Down Expand Up @@ -242,20 +242,23 @@ describe('md-slider', function() {

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

buildSlider(0.1, 1).drag({x:70});
buildSlider(0.1, 0, 1).drag({x:70});
expect(pageScope.value).toBe(0.7);

buildSlider(0.25, 1).drag({x:45});
buildSlider(0.25, 0, 1).drag({x:45});
expect(pageScope.value).toBe(0.5);

buildSlider(0.25, 1).drag({x:35});
buildSlider(0.25, 0, 1).drag({x:35});
expect(pageScope.value).toBe(0.25);

buildSlider(1, 100).drag({x:90});
buildSlider(1, 0, 100).drag({x:90});
expect(pageScope.value).toBe(90);

function buildSlider(step, max) {
var slider = setup('ng-model="value" min="0" max="' + max + '" step="' + step + '"');
buildSlider(20, 5, 45).drag({x:50});
expect(pageScope.value).toBe(25);

function buildSlider(step, min, max) {
var slider = setup('ng-model="value" min="' + min + '" max="' + max + '" step="' + step + '"');
pageScope.$apply('value = 0.5');

return {
Expand Down

0 comments on commit 441cbf1

Please sign in to comment.