Skip to content

Commit 622959b

Browse files
mukulhasescottgonzalez
authored andcommitted
Slider: Fixed max value miscalculation
Fixes #12852 Closes gh-1664 (cherry picked from commit a1905e2)
1 parent eb6d623 commit 622959b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

tests/unit/slider/slider_options.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test( "disabled", function(){
4040
});
4141

4242
test( "max", function() {
43-
expect( 5 );
43+
expect( 7 );
4444
element = $( "<div></div>" );
4545

4646
options = {
@@ -54,7 +54,7 @@ test( "max", function() {
5454
element.slider( options );
5555
ok( element.slider( "option", "value" ) === options.value, "value option is not contained by max" );
5656
ok( element.slider( "value" ) === options.max, "value method is contained by max" );
57-
57+
5858
options = {
5959
max: 9,
6060
min: 1,
@@ -65,7 +65,7 @@ test( "max", function() {
6565

6666
element.slider( options );
6767
ok( element.slider( "value" ) === 7, "value method is within max, edge Case" );
68-
68+
6969
options.step = 2;
7070

7171
element.slider( options );
@@ -84,7 +84,24 @@ test( "max", function() {
8484
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
8585
element.slider( "destroy" );
8686

87-
});
87+
options = {
88+
max: 10.75,
89+
min: 1.22,
90+
orientation: "horizontal",
91+
step: 0.01,
92+
value: 10.75
93+
};
94+
95+
element.slider( options );
96+
ok( element.slider( "value" ) === options.max, "value method will max, step is changed, step is float and max is float" );
97+
element.slider( "destroy" );
98+
99+
options.max = 10.749999999;
100+
101+
element.slider( options );
102+
ok( element.slider( "value" ) === 10.74, "value method will max, step is changed, step is float, max is float and not divisible" );
103+
element.slider( "destroy" );
104+
} );
88105

89106
test( "min", function() {
90107
expect( 2 );

ui/slider.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
552552
var max = this.options.max,
553553
min = this._valueMin(),
554554
step = this.options.step,
555-
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
555+
aboveMin = Math.round( ( max - min ) / step ) * step;
556556
max = aboveMin + min;
557+
if ( max > this.options.max ) {
558+
559+
//If max is not divisible by step, rounding off may increase its value
560+
max -= step;
561+
}
557562
this.max = parseFloat( max.toFixed( this._precision() ) );
558563
},
559564

0 commit comments

Comments
 (0)