Skip to content

Slider: Fixed max value miscalculation #1664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
19 changes: 18 additions & 1 deletion tests/unit/slider/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test( "disabled", function( assert ) {
} );

test( "max", function() {
expect( 5 );
expect( 7 );
element = $( "<div></div>" );

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

options = {
max: 10.75,
min: 1.22,
orientation: "horizontal",
step: 0.01,
value: 10.75
};

element.slider( options );
ok( element.slider( "value" ) === options.max, "value method will max, step is changed, step is float and max is float" );
element.slider( "destroy" );

options.max = 10.749999999;

element.slider( options );
ok( element.slider( "value" ) === 10.74, "value method will max, step is changed, step is float, max is float and not divisible" );
element.slider( "destroy" );
} );

test( "min", function() {
Expand Down
7 changes: 6 additions & 1 deletion ui/widgets/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,13 @@ return $.widget( "ui.slider", $.ui.mouse, {
var max = this.options.max,
min = this._valueMin(),
step = this.options.step,
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
aboveMin = Math.round( ( max - min ) / step ) * step;
max = aboveMin + min;
if ( max > this.options.max ) {

//If max is not divisible by step, rounding off may increase its value
max -= step;
}
this.max = parseFloat( max.toFixed( this._precision() ) );
},

Expand Down