From 782c0cc4f6211f64bb170368c15c64832cacd631 Mon Sep 17 00:00:00 2001 From: Veselin Nikolov Date: Sat, 25 Aug 2018 22:33:39 +0200 Subject: [PATCH] Use pull request #11409 from veselinn/fix/slider-handle-negative-data-start for v6.5.0 81fc284e9 fix: slider handle negative data-start values da0b014de fix: remove unnecessary if from slider 9851a17ff test: add tests for Slider._adjustValue Signed-off-by: Nicolas Coden --- js/foundation.slider.js | 6 +++++- test/javascript/components/slider.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/js/foundation.slider.js b/js/foundation.slider.js index e7d4e1870..6f29fbe21 100644 --- a/js/foundation.slider.js +++ b/js/foundation.slider.js @@ -426,7 +426,11 @@ class Slider extends Plugin { else { val = value; } - left = val % step; + if (val >= 0) { + left = val % step; + } else { + left = step + (val % step); + } prev_val = val - left; next_val = prev_val + step; if (left === 0) { diff --git a/test/javascript/components/slider.js b/test/javascript/components/slider.js index 364919af2..9c1480aca 100644 --- a/test/javascript/components/slider.js +++ b/test/javascript/components/slider.js @@ -153,6 +153,30 @@ describe('Slider', function() { }); }); + describe('adjustValue()', function() { + it('handles positive values', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Slider($html, {}); + + plugin._adjustValue(null, 1).should.equal(1); + plugin._adjustValue(null, 2).should.equal(2); + plugin._adjustValue(null, 1.2).should.equal(1); + plugin._adjustValue(null, 1.9).should.equal(2); + plugin._adjustValue(null, 1.5).should.equal(2); + }); + + it('handles negative values', function() { + $html = $(template).appendTo('body'); + plugin = new Foundation.Slider($html, {}); + + plugin._adjustValue(null, -1).should.equal(-1); + plugin._adjustValue(null, -2).should.equal(-2); + plugin._adjustValue(null, -1.2).should.equal(-1); + plugin._adjustValue(null, -1.9).should.equal(-2); + plugin._adjustValue(null, -1.5).should.equal(-1); + }); + }); + describe('keyboard events', function() { it('sets value to minimum using HOME', function() { $html = $(template).appendTo('body'); -- 2.47.2