Skip to content

Commit

Permalink
Slider: Modified to allow value to reach max value with float step
Browse files Browse the repository at this point in the history
Fixes #11286
Closes gh-1465
(cherry picked from commit 60c00cd)
  • Loading branch information
atomiomi authored and scottgonzalez committed Mar 10, 2015
1 parent 31e7099 commit 0f99e9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion tests/unit/slider/slider_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test( "disable", function() {
});

test( "value", function() {
expect( 17 );
expect( 18 );
$( [ false, "min", "max" ] ).each(function() {
var element = $( "<div></div>" ).slider({
range: this,
Expand All @@ -88,6 +88,16 @@ test( "value", function() {
equal( element.slider( "value" ), 1, "value method get respects max" );
equal( element.slider( "value", 2 ), element, "value method is chainable" );
equal( element.slider( "option", "value" ), 1, "value method set respects max" );

// set max value with step 0.01
element.slider( "option", {
min: 2,
value: 2,
max: 2.4,
step: 0.01
});
element.slider( "option", "value", 2.4 );
equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" );
});

//test( "values", function() {
Expand Down
2 changes: 1 addition & 1 deletion ui/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
var max = this.options.max,
min = this._valueMin(),
step = this.options.step,
aboveMin = Math.floor( ( max - min ) / step ) * step;
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
max = aboveMin + min;
this.max = parseFloat( max.toFixed( this._precision() ) );
},
Expand Down

0 comments on commit 0f99e9c

Please sign in to comment.