Skip to content

Commit 8035f44

Browse files
pdanpdanrstoenescu
authored andcommitted
Tweaks related to controls (quasarframework#1518)
* Add tests for rating. Add dark, disable and readonly * Lots of tweaks for controls
1 parent 8eef01e commit 8035f44

File tree

17 files changed

+449
-329
lines changed

17 files changed

+449
-329
lines changed

dev/components/form/all.vue

Lines changed: 327 additions & 229 deletions
Large diffs are not rendered by default.

src/components/color/QColor.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ export default {
4444
},
4545
displayValue: String,
4646
placeholder: String,
47-
clearable: Boolean,
4847
okLabel: String,
49-
cancelLabel: String,
50-
disable: Boolean,
51-
readonly: Boolean
48+
cancelLabel: String
5249
},
5350
data () {
5451
let data = this.isPopover ? {} : {
@@ -104,7 +101,7 @@ export default {
104101
}
105102
},
106103
__onFocus () {
107-
if (this.focused) {
104+
if (this.disable || this.focused) {
108105
return
109106
}
110107
this.__setModel(this.value || this.defaultSelection)

src/components/color/QColorPicker.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export default {
1515
TouchPan
1616
},
1717
props: {
18-
value: {
18+
value: [String, Object],
19+
defaultSelection: {
1920
type: [String, Object],
20-
required: true
21+
default: '#000'
2122
},
2223
type: {
2324
type: String,
@@ -30,7 +31,7 @@ export default {
3031
data () {
3132
return {
3233
view: !this.value || typeof this.value === 'string' ? 'hex' : 'rgb',
33-
model: this.__parseModel(this.value),
34+
model: this.__parseModel(this.value || this.defaultSelection),
3435
inputError: {
3536
hex: false,
3637
r: false,
@@ -42,7 +43,7 @@ export default {
4243
watch: {
4344
value: {
4445
handler (v) {
45-
const model = this.__parseModel(v)
46+
const model = this.__parseModel(v || this.defaultSelection)
4647
if (model.hex !== this.model.hex) {
4748
this.model = model
4849
}
@@ -78,7 +79,7 @@ export default {
7879
}
7980
return this.isHex
8081
? this.value.length > 7
81-
: this.value.a !== void 0
82+
: this.value && this.value.a !== void 0
8283
},
8384
swatchStyle () {
8485
return {
@@ -203,19 +204,16 @@ export default {
203204
type: 'number',
204205
min: 0,
205206
max,
206-
readonly: !this.editable
207+
readonly: !this.editable,
208+
tabindex: this.disable ? 0 : -1
207209
},
208210
staticClass: 'full-width text-center q-no-input-spinner',
209211
domProps: {
210212
value: Math.round(this.model[type])
211213
},
212214
on: {
213-
input: evt => {
214-
this.__onNumericChange(evt, type, max)
215-
},
216-
blur: evt => {
217-
this.__onNumericChange(evt, type, max, true)
218-
}
215+
input: evt => this.__onNumericChange(evt, type, max),
216+
blur: evt => this.editable && this.__onNumericChange(evt, type, max, true)
219217
}
220218
}),
221219
h('div', { staticClass: 'q-color-label text-center uppercase' }, [
@@ -232,11 +230,11 @@ export default {
232230
domProps: { value: this.model.hex },
233231
attrs: {
234232
readonly: !this.editable,
235-
tabindex: this.editable ? 0 : -1
233+
tabindex: this.disable ? 0 : -1
236234
},
237235
on: {
238236
input: this.__onHexChange,
239-
blur: evt => this.__onHexChange(evt, true)
237+
blur: evt => this.editable && this.__onHexChange(evt, true)
240238
},
241239
staticClass: 'full-width text-center uppercase'
242240
}),
@@ -255,7 +253,8 @@ export default {
255253
h(QBtn, {
256254
props: {
257255
flat: true,
258-
color: 'grey-7'
256+
color: 'grey-7',
257+
disable: this.disable
259258
},
260259
on: {
261260
click: this.__nextInputView

src/components/datetime/QDatetime.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export default {
9595
}
9696
},
9797
__onFocus () {
98+
if (this.disable || this.focused) {
99+
return
100+
}
98101
if (this.defaultView) {
99102
const target = this.$refs.target
100103
if (target.view !== this.defaultView) {
@@ -104,9 +107,6 @@ export default {
104107
target.__scrollView()
105108
}
106109
}
107-
if (this.focused) {
108-
return
109-
}
110110
this.__setModel(isValid(this.value) ? this.value : this.defaultSelection)
111111
this.focused = true
112112
this.$emit('focus')
@@ -219,6 +219,7 @@ export default {
219219
error: this.error,
220220
warning: this.warning,
221221
disable: this.disable,
222+
readonly: this.readonly,
222223
inverted: this.inverted,
223224
dark: this.dark,
224225
hideUnderline: this.hideUnderline,

src/components/datetime/QDatetimePicker.mat.vue

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
<span
88
:class="{active: view === 'month'}"
99
class="q-datetime-link small col-auto col-md-12"
10-
@click="view = 'month'"
10+
@click="!disable && (view = 'month')"
1111
>
1212
{{ monthString }}
1313
</span>
1414
<span
1515
:class="{active: view === 'day'}"
1616
class="q-datetime-link col-auto col-md-12"
17-
@click="view = 'day'"
17+
@click="!disable && (view = 'day')"
1818
>
1919
{{ day }}
2020
</span>
2121
<span
2222
:class="{active: view === 'year'}"
2323
class="q-datetime-link small col-auto col-md-12"
24-
@click="view = 'year'"
24+
@click="!disable && (view = 'year')"
2525
>
2626
{{ year }}
2727
</span>
@@ -35,15 +35,15 @@
3535
<span
3636
:class="{active: view === 'hour'}"
3737
class="q-datetime-link col-auto col-md-12"
38-
@click="view = 'hour'"
38+
@click="!disable && (view = 'hour')"
3939
>
4040
{{ __pad(hour, '&nbsp;&nbsp;') }}
4141
</span>
4242
<span style="opacity: 0.6">:</span>
4343
<span
4444
:class="{active: view === 'minute'}"
4545
class="q-datetime-link col-auto col-md-12"
46-
@click="view = 'minute'"
46+
@click="!disable && (view = 'minute')"
4747
>
4848
{{ __pad(minute) }}
4949
</span>
@@ -74,6 +74,8 @@
7474
flat
7575
class="q-datetime-btn full-width"
7676
:class="{active: n + yearMin === year}"
77+
:color="dark ? 'light' : 'dark'"
78+
:disable="!editable"
7779
@click="setYear(n + yearMin)"
7880
>
7981
{{ n + yearMin }}
@@ -90,6 +92,8 @@
9092
flat
9193
class="q-datetime-btn full-width"
9294
:class="{active: month === index + monthMin}"
95+
:color="dark ? 'light' : 'dark'"
96+
:disable="!editable"
9397
@click="setMonth(index + monthMin, true)"
9498
>
9599
{{ $q.i18n.date.months[index + monthMin - 1] }}
@@ -106,29 +110,29 @@
106110
dense
107111
flat
108112
:color="color"
109-
@click="setMonth(month - 1)"
110-
:disabled="beforeMinDays"
111113
:icon="$q.icon.datetime.arrowLeft"
112114
:repeatTimeout="__getRepeatEasing()"
115+
:disable="beforeMinDays || disable || readonly"
116+
@click="setMonth(month - 1)"
113117
></q-btn>
114-
<div class="col q-datetime-dark">
118+
<div class="col" :class="classDark">
115119
{{ monthStamp }}
116120
</div>
117121
<q-btn
118122
round
119123
dense
120124
flat
121125
:color="color"
122-
@click="setMonth(month + 1)"
123-
:disabled="afterMaxDays"
124126
:icon="$q.icon.datetime.arrowRight"
125127
:repeatTimeout="__getRepeatEasing()"
128+
:disable="afterMaxDays || disable || readonly"
129+
@click="setMonth(month + 1)"
126130
></q-btn>
127131
</div>
128-
<div class="q-datetime-weekdays row items-center justify-start">
132+
<div class="q-datetime-weekdays row items-center justify-start" :class="classDark">
129133
<div v-for="day in headerDayNames" :key="`dh${day}`">{{day}}</div>
130134
</div>
131-
<div class="q-datetime-days row wrap items-center justify-start content-center">
135+
<div class="q-datetime-days row wrap items-center justify-start content-center" :class="classDark">
132136
<div v-for="fillerDay in fillerDays" :key="`fd${fillerDay}`" class="q-datetime-fillerday"></div>
133137
<template v-if="min">
134138
<div v-for="fillerDay in beforeMinDays" :key="`fb${fillerDay}`" class="row items-center content-center justify-center disabled">
@@ -139,10 +143,11 @@
139143
v-for="monthDay in daysInterval"
140144
:key="`md${monthDay}`"
141145
class="row items-center content-center justify-center cursor-pointer"
142-
:class="{
146+
:class="[color && monthDay === day ? `text-${color}` : null, {
143147
'q-datetime-day-active': monthDay === day,
144-
'q-datetime-day-today': monthDay === today
145-
}"
148+
'q-datetime-day-today': monthDay === today,
149+
'disabled': !editable
150+
}]"
146151
@click="setDay(monthDay)"
147152
>
148153
<span>{{ monthDay }}</span>
@@ -276,6 +281,9 @@ export default {
276281
}
277282
},
278283
computed: {
284+
classDark () {
285+
return this.dark ? 'q-datetime-light' : 'q-datetime-dark'
286+
},
279287
classes () {
280288
const cls = []
281289
if (this.disable) {

src/components/datetime/datetime-props.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export const inline = {
1414
validator: modelValidator,
1515
required: true
1616
},
17+
defaultSelection: {
18+
type: [String, Number, Date],
19+
default: null
20+
},
1721
type: {
1822
type: String,
1923
default: 'date',
@@ -23,6 +27,7 @@ export const inline = {
2327
type: String,
2428
default: 'primary'
2529
},
30+
dark: Boolean,
2631
min: {
2732
validator: modelValidator,
2833
default: null
@@ -51,14 +56,7 @@ export const inline = {
5156
export const input = {
5257
format: String,
5358
placeholder: String,
54-
clearable: Boolean,
5559
okLabel: String,
5660
cancelLabel: String,
57-
defaultSelection: {
58-
type: [String, Number, Date],
59-
default: null
60-
},
61-
displayValue: String,
62-
disable: Boolean,
63-
readonly: Boolean
61+
displayValue: String
6462
}

src/components/datetime/datetime.mat.styl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
.q-datetime-dark
1414
color black
1515

16+
.q-datetime-light
17+
color white
18+
1619
.q-datetime-header
1720
background currentColor
1821
> div
@@ -55,7 +58,6 @@ div + .q-datetime-time
5558
height 300px
5659

5760
.q-datetime-weekdays
58-
color rgba(0, 0, 0, .87)
5961
font-size .75rem
6062
margin-top 10px
6163
margin-bottom 5px
@@ -77,8 +79,6 @@ div + .q-datetime-time
7779
height 35px
7880
border-radius 50%
7981

80-
&:not(.q-datetime-day-active)
81-
color black
8282
&.q-datetime-day-active
8383
background currentColor
8484
> span
@@ -92,8 +92,6 @@ div + .q-datetime-time
9292

9393
.q-datetime-btn
9494
font-weight normal
95-
&:not(.active)
96-
color black !important
9795
&.active
9896
font-size 1.5rem
9997
padding-top 1rem

src/components/input/QInput.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
/>
7979

8080
<q-icon
81-
v-if="isPassword && !noPassToggle && length"
81+
v-if="!disable && isPassword && !noPassToggle && length"
8282
slot="after"
8383
:name="$q.icon.input[showPass ? 'showPass' : 'hidePass']"
8484
class="q-if-control"
@@ -88,7 +88,7 @@
8888
></q-icon>
8989

9090
<q-icon
91-
v-if="keyboardToggle"
91+
v-if="editable && keyboardToggle"
9292
slot="after"
9393
:name="$q.icon.input[showNumber ? 'showNumber' : 'hideNumber']"
9494
class="q-if-control"
@@ -221,10 +221,10 @@ export default {
221221
},
222222
inputType () {
223223
if (this.isPassword) {
224-
return this.showPass ? 'text' : 'password'
224+
return this.showPass && this.editable ? 'text' : 'password'
225225
}
226226
return this.isNumber
227-
? (this.showNumber ? 'number' : 'text')
227+
? (this.showNumber || !this.editable ? 'number' : 'text')
228228
: this.type
229229
},
230230
length () {

src/components/knob/QKnob.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export default {
99
TouchPan
1010
},
1111
props: {
12-
value: {
13-
type: Number,
14-
required: true
15-
},
12+
value: Number,
1613
min: {
1714
type: Number,
1815
default: 0
@@ -97,7 +94,7 @@ export default {
9794
})
9895
}
9996
else {
100-
this.model = this.computedDecimals
97+
this.model = this.computedDecimals && typeof value === 'number'
10198
? parseFloat(value.toFixed(this.computedDecimals))
10299
: value
103100
}

src/components/range/QRange.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export default {
2020
props: {
2121
value: {
2222
type: Object,
23-
required: true,
23+
default: () => ({
24+
min: 0,
25+
max: 0
26+
}),
2427
validator (value) {
25-
return typeof value.min !== 'undefined' && typeof value.max !== 'undefined'
28+
return value.hasOwnProperty('min') && value.hasOwnProperty('max')
2629
}
2730
},
2831
dragRange: Boolean,

0 commit comments

Comments
 (0)