Skip to content

Commit

Permalink
Fixed #1285 - Decimal value for Slider
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 21, 2021
1 parent d9b9a91 commit 93c57ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/components/slider/Slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ export default {
newValue = oldValue + Math.floor(newValue / this.step - oldValue / this.step) * this.step;
}
else {
newValue = Math.floor(newValue);
}
this.updateModel(event, newValue);
},
updateModel(event, value) {
let newValue = value;
let newValue = parseFloat(value.toFixed(10));
let modelValue;
if (this.range) {
Expand All @@ -107,15 +111,15 @@ export default {
}
modelValue = [...this.value];
modelValue[this.handleIndex] = Math.floor(newValue);
modelValue[this.handleIndex] = newValue;
}
else {
if (newValue < this.min)
newValue = this.min;
else if (newValue > this.max)
newValue = this.max;
modelValue = Math.floor(newValue);
modelValue = newValue;
}
this.$emit('input', modelValue);
Expand Down
18 changes: 11 additions & 7 deletions src/views/slider/SliderDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="content-section implementation">
<div class="card">
<h5>Basic: {{value1}}</h5>
<Slider v-model="value1" />
<Slider v-model="value1" :step="0.01" :min="1.35" />

<h5>Input: {{value2}}</h5>
<InputText v-model.number="value2" />
Expand All @@ -20,11 +20,14 @@
<h5>Step: {{value3}}</h5>
<Slider v-model="value3" :step="20" />

<h5>Range: {{value4}}</h5>
<Slider v-model="value4" :range="true" />
<h5>Decimal Step: {{value4}}</h5>
<Slider v-model="value4" :step="0.5" />

<h5>Vertical: {{value5}}</h5>
<Slider v-model="value5" orientation="vertical" />
<h5>Range: {{value5}}</h5>
<Slider v-model="value5" :range="true" />

<h5>Vertical: {{value6}}</h5>
<Slider v-model="value6" orientation="vertical" :step="0.01" />
</div>
</div>

Expand All @@ -41,8 +44,9 @@ export default {
value1: null,
value2: 50,
value3: 20,
value4: [20,80],
value5: 50
value4: 30.5,
value5: [20,80],
value6: 50
}
},
components: {
Expand Down

0 comments on commit 93c57ca

Please sign in to comment.