Skip to content

Commit c8571eb

Browse files
committed
QSlider and QRange custom values for labels
1 parent 6d3604f commit c8571eb

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

dev/components/form/range.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
</p>
6060
<q-range v-model="label" :min="-20" :max="20" :step="4" label-always></q-range>
6161

62+
<p class="caption">
63+
With custom values for labels
64+
<span class="label inline bg-secondary text-white">
65+
Model <span class="right-detail"><em>{{label.min}} to {{label.max}}</em> &nbsp;&nbsp;(-20 to 20, step 4)</span>
66+
</span>
67+
</p>
68+
<q-range v-model="label" :min="-20" :max="20" :step="4" label-always :left-label-value="`${label.min}px`" :right-label-value="`${label.max}px`"></q-range>
69+
6270
<p class="caption">
6371
Drag Range
6472
<span class="label inline bg-secondary text-white">

dev/components/form/slider.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
</p>
5959
<q-slider v-model="label" :min="-20" :max="20" :step="4" label-always></q-slider>
6060

61+
<p class="caption">
62+
With custom value for Label
63+
<span class="label inline bg-secondary text-white">
64+
Model <span class="right-detail"><em>{{label}}</em> &nbsp;&nbsp;(-20 to 20, step 4)</span>
65+
</span>
66+
</p>
67+
<q-slider v-model="label" :min="-20" :max="20" :step="4" label :label-value="`${label}px`" label-always />
68+
6169
<p class="caption">Disabled State</p>
6270
<q-slider v-model="standalone" :min="0" :max="50" disable></q-slider>
6371

src/components/range/QRange.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
:class="{'label-always': labelAlways}"
3434
v-if="label || labelAlways"
3535
>
36-
{{ value.min }}
36+
{{ leftDisplayValue }}
3737
</q-chip>
3838

3939
<div v-if="$q.theme !== 'ios'" class="q-slider-ring"></div>
@@ -51,7 +51,7 @@
5151
:class="{'label-always': labelAlways}"
5252
v-if="label || labelAlways"
5353
>
54-
{{ value.max }}
54+
{{ rightDisplayValue }}
5555
</q-chip>
5656

5757
<div v-if="$q.theme !== 'ios'" class="q-slider-ring"></div>
@@ -92,7 +92,9 @@ export default {
9292
}
9393
},
9494
dragRange: Boolean,
95-
dragOnlyRange: Boolean
95+
dragOnlyRange: Boolean,
96+
leftLabelValue: String,
97+
rightLabelValue: String
9698
},
9799
data () {
98100
return {
@@ -110,6 +112,16 @@ export default {
110112
},
111113
activeTrackWidth () {
112114
return 100 * (this.percentageMax - this.percentageMin) + '%'
115+
},
116+
leftDisplayValue () {
117+
return this.leftLabelValue !== void 0
118+
? this.leftLabelValue
119+
: this.value.min
120+
},
121+
rightDisplayValue () {
122+
return this.rightLabelValue !== void 0
123+
? this.rightLabelValue
124+
: this.value.max
113125
}
114126
},
115127
watch: {

src/components/slider/QSlider.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
:class="{'label-always': labelAlways}"
3232
v-if="label || labelAlways"
3333
>
34-
{{ value }}
34+
{{ displayValue }}
3535
</q-chip>
3636

3737
<div v-if="$q.theme !== 'ios'" class="q-slider-ring"></div>
@@ -59,7 +59,8 @@ export default {
5959
value: {
6060
type: Number,
6161
required: true
62-
}
62+
},
63+
labelValue: String
6364
},
6465
data () {
6566
return {
@@ -73,6 +74,11 @@ export default {
7374
return (this.value - this.min) / (this.max - this.min) * 100 + '%'
7475
}
7576
return 100 * this.currentPercentage + '%'
77+
},
78+
displayValue () {
79+
return this.labelValue !== void 0
80+
? this.labelValue
81+
: this.value
7682
}
7783
},
7884
watch: {

0 commit comments

Comments
 (0)