Skip to content

Slider: Setting values or range slider to max, doesn't lock slider #1502

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 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 47 additions & 0 deletions tests/visual/slider/range_slider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jQuery UI Slider - Range slider</title>
<link rel="stylesheet" href="../../../themes/base/all.css">
<style>
#wrapper {
font-family: Arial;
width: 500px;
margin: 20px auto;
}
</style>
<script src="../../../external/jquery/jquery.js"></script>
<script src="../../../ui/core.js"></script>
<script src="../../../ui/widget.js"></script>
<script src="../../../ui/mouse.js"></script>
<script src="../../../ui/slider.js"></script>
</head>
<body>
<div id="wrapper">
<h1>Range Slider</h1>
<h3>When set both values of range slider to the maximum, slider should not lock</h3>
<div id="slider"></div>
<br>
<button id="set-max-values">set values to max</button>
<button id="set-min-values">set values to min</button>
</div>

<script>
var el = $( "#slider" ).slider({
range: true,
min: 0,
max: 100,
values: [ 0, 50 ]
});

$( "#set-max-values" ).on( "click", function() {
el.slider( "option", { values: [ 100, 100 ] } );
});

$( "#set-min-values" ).on( "click", function() {
el.slider( "option", { values: [ 0, 0 ] } );
});
</script>
</body>
</html>
23 changes: 18 additions & 5 deletions ui/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,24 @@ return $.widget( "ui.slider", $.ui.mouse, {
}
},

_setOption: function( key, value ) {
_changeAllValues: function( valuesLength ) {
var i,
valsLength = 0;
rangeValues = [ this.values( 0 ), this.values( 1 ), this._valueMax() ];

if ( this.options.range === true && $.unique( rangeValues ).length === 1 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check actually necessary? Might be enough to just always do the reverse loop. I tested that locally with the new visual test page and the unit tests, works for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've also tested that, it works well. I thought that setting values with reverse loop to the minimum will lock slider, but didn't check it.

for ( i = valuesLength - 1; i >= 0; i -= 1 ) {
this._change( null, i );
}
return;
}

for ( i = 0; i < valuesLength; i += 1 ) {
this._change( null, i );
}
},

_setOption: function( key, value ) {
var valsLength = 0;

if ( key === "range" && this.options.range === true ) {
if ( value === "min" ) {
Expand Down Expand Up @@ -453,9 +468,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
case "values":
this._animateOff = true;
this._refreshValue();
for ( i = 0; i < valsLength; i += 1 ) {
this._change( null, i );
}
this._changeAllValues( valsLength );
this._animateOff = false;
break;
case "step":
Expand Down