Skip to content

Commit

Permalink
Fix #960
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed Mar 15, 2019
1 parent 9921f26 commit 79fdc51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/nouislider.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,6 @@
var scope_Pips;
var scope_Tooltips;

// Override for the 'animate' option
var scope_ShouldAnimate = true;

// Slider state values
var scope_Spectrum = options.spectrum;
var scope_Values = [];
Expand Down Expand Up @@ -1832,12 +1829,8 @@
// Decrement for down steps
step = (isDown ? -1 : 1) * step;

scope_ShouldAnimate = false;

valueSetHandle(handleNumber, scope_Values[handleNumber] + step, true);

scope_ShouldAnimate = true;

return false;
}

Expand Down Expand Up @@ -2180,7 +2173,7 @@

// Animation is optional.
// Make sure the initial values were set before using animated placement.
if (options.animate && !isInit && scope_ShouldAnimate) {
if (options.animate && !isInit) {
addClassFor(scope_Target, options.cssClasses.tap, options.animationDuration);
}

Expand Down Expand Up @@ -2213,22 +2206,21 @@

// Set value for a single handle
function valueSetHandle(handleNumber, value, fireSetEvent) {
var values = [];

// Ensure numeric input
handleNumber = Number(handleNumber);

if (!(handleNumber >= 0 && handleNumber < scope_HandleNumbers.length)) {
throw new Error("noUiSlider (" + VERSION + "): invalid handle number, got: " + handleNumber);
}

for (var i = 0; i < scope_HandleNumbers.length; i++) {
values[i] = null;
}
// Look both backward and forward, since we don't want this handle to "push" other handles (#960);
setHandle(handleNumber, resolveToValue(value, handleNumber), true, true);

values[handleNumber] = value;
fireEvent("update", handleNumber);

valueSet(values, fireSetEvent);
if (fireSetEvent) {
fireEvent("set", handleNumber);
}
}

// Get the slider value.
Expand Down
24 changes: 24 additions & 0 deletions tests/slider_keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,28 @@ QUnit.test("Keyboard support", function (assert) {

down(handle0);
assert.equal(slider.noUiSlider.get(), '50.00');

slider.noUiSlider.destroy();

noUiSlider.create(slider, {
start: [1, 6],
step: 3,
range: {
'min': 0,
'max': 10
}
});

assert.deepEqual(slider.noUiSlider.get(), ['0.00', '6.00']);

handle0 = slider.querySelector('[data-handle="0"]');

up(handle0);
assert.deepEqual(slider.noUiSlider.get(), ['3.00', '6.00']);

up(handle0);
assert.deepEqual(slider.noUiSlider.get(), ['6.00', '6.00']);

up(handle0);
assert.deepEqual(slider.noUiSlider.get(), ['6.00', '6.00'], 'Handle 0 cannot push past handle 1');
});

0 comments on commit 79fdc51

Please sign in to comment.