Skip to content

Slider: trim value even if it is the min/max. Fixed #9376 - Slider value... #1030

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
15 changes: 14 additions & 1 deletion tests/unit/slider/slider_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test( "orientation", function() {
// value option/method: the value option is not restricted by min/max/step.
// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple)
test( "step", function() {
expect( 9 );
expect( 11 );
element = $( "<div></div>" ).slider({
min: 0,
value: 0,
Expand Down Expand Up @@ -161,6 +161,19 @@ test( "step", function() {
equal( element.slider( "value" ), 20 );

element.slider( "destroy" );


element = $( "<div></div>" ).slider({
min: 0,
value: 10,
step: 3,
max: 10
});
equal(element.slider( "value" ), 9, "starting value is corrected to 9" );

element.slider( "option", "value", 0 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal(element.slider( "value" ), 9 );
});

//test( "value", function() {
Expand Down
8 changes: 4 additions & 4 deletions ui/jquery.ui.slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ $.widget( "ui.slider", $.ui.mouse, {

// returns the step-aligned value that val is closest to, between (inclusive) min and max
_trimAlignValue: function( val ) {
if ( val <= this._valueMin() ) {
return this._valueMin();
if ( val < this._valueMin() ) {
val = this._valueMin();
}
if ( val >= this._valueMax() ) {
return this._valueMax();
if ( val > this._valueMax() ) {
val = this._valueMax();
}
var step = ( this.options.step > 0 ) ? this.options.step : 1,
valModStep = (val - this._valueMin()) % step,
Expand Down