Skip to content

Commit a1905e2

Browse files
mukulhasescottgonzalez
authored andcommitted
Slider: Fixed max value miscalculation
Fixes #12852 Closes gh-1664
1 parent bff8277 commit a1905e2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tests/unit/slider/options.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test( "disabled", function( assert ) {
4343
} );
4444

4545
test( "max", function() {
46-
expect( 5 );
46+
expect( 7 );
4747
element = $( "<div></div>" );
4848

4949
options = {
@@ -87,6 +87,23 @@ test( "max", function() {
8787
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
8888
element.slider( "destroy" );
8989

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

92109
test( "min", function() {

ui/widgets/slider.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
544544
var max = this.options.max,
545545
min = this._valueMin(),
546546
step = this.options.step,
547-
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
547+
aboveMin = Math.round( ( max - min ) / step ) * step;
548548
max = aboveMin + min;
549+
if ( max > this.options.max ) {
550+
551+
//If max is not divisible by step, rounding off may increase its value
552+
max -= step;
553+
}
549554
this.max = parseFloat( max.toFixed( this._precision() ) );
550555
},
551556

0 commit comments

Comments
 (0)