From 75e5b0ecea1bb75e705963fdc4d9f415856c53f8 Mon Sep 17 00:00:00 2001 From: Gabriel Oliveira Date: Mon, 13 Mar 2017 14:40:20 -0300 Subject: [PATCH] Slider: fix step not updating precision --- packages/slider/src/main.vue | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/slider/src/main.vue b/packages/slider/src/main.vue index 644febb2..d0dced23 100644 --- a/packages/slider/src/main.vue +++ b/packages/slider/src/main.vue @@ -119,6 +119,10 @@ this.setValues(); }, + step() { + this.setPrecision(); + }, + dragging(val) { if (!val) { this.setValues(); @@ -210,6 +214,14 @@ if (this.disabled || this.dragging) return; const sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left; this.setPosition((event.clientX - sliderOffsetLeft) / this.$sliderWidth * 100); + }, + + setPrecision() { + let precisions = [this.min, this.max, this.step].map(item => { + let decimal = ('' + item).split('.')[1]; + return decimal ? decimal.length : 0; + }); + this.precision = Math.max.apply(null, precisions); } }, @@ -274,11 +286,7 @@ } this.oldValue = this.firstValue; } - let precisions = [this.min, this.max, this.step].map(item => { - let decimal = ('' + item).split('.')[1]; - return decimal ? decimal.length : 0; - }); - this.precision = Math.max.apply(null, precisions); + this.setPrecision(); } };