From 79fdc5157ce8ab056ab969243f2ac3cc263c0063 Mon Sep 17 00:00:00 2001 From: "l.gersen@visymo.com" Date: Fri, 15 Mar 2019 08:14:38 +0100 Subject: [PATCH] Fix #960 --- src/nouislider.js | 22 +++++++--------------- tests/slider_keyboard.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/nouislider.js b/src/nouislider.js index 99a311c4..10b39518 100644 --- a/src/nouislider.js +++ b/src/nouislider.js @@ -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 = []; @@ -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; } @@ -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); } @@ -2213,8 +2206,6 @@ // Set value for a single handle function valueSetHandle(handleNumber, value, fireSetEvent) { - var values = []; - // Ensure numeric input handleNumber = Number(handleNumber); @@ -2222,13 +2213,14 @@ 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. diff --git a/tests/slider_keyboard.js b/tests/slider_keyboard.js index d4d28424..f7e7ba8b 100644 --- a/tests/slider_keyboard.js +++ b/tests/slider_keyboard.js @@ -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'); });