Skip to content

Commit d4125b9

Browse files
committed
Select initial view of datetime via property quasarframework#1303
1 parent 973ce60 commit d4125b9

File tree

7 files changed

+63
-16
lines changed

7 files changed

+63
-16
lines changed

dev/components/form/color-picker.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export default {
8080
return `rgb${color.a !== void 0 ? 'a' : ''}(${color.r},${color.g},${color.b}${color.a !== void 0 ? `,${color.a / 100}` : ''})`
8181
},
8282
setToYellow () {
83-
this.modelHex = '#ffff00'
84-
this.modelHexa = '#ffff00FF'
83+
this.modelHex = '#FFFF00'
84+
this.modelHexa = '#FFFF00FF'
8585
this.modelRgb = {r: 255, g: 255, b: 0}
8686
this.modelRgba = {r: 255, g: 255, b: 0, a: 100}
8787
}

dev/components/form/datetime.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<q-datetime float-label="Float Label" v-model="model" type="date" />
4444
<q-datetime hide-underline float-label="Float Label (hide underline)" v-model="model" type="date" />
4545

46+
<q-datetime default-view="month" v-model="model" type="date" float-label="Default view" />
4647
<q-datetime inverted v-model="model" type="date" />
4748
<q-datetime inverted color="secondary" stack-label="Stack Label" v-model="model" type="date" />
4849
<q-datetime inverted color="amber" float-label="Float Label" v-model="model" type="date" />
@@ -134,6 +135,8 @@
134135
</small>
135136
</p>
136137
<q-inline-datetime v-model="model" type="date" />
138+
<br><br>
139+
<q-inline-datetime default-view="year" v-model="model" type="date" />
137140

138141
<p class="caption">
139142
Time

src/components/color/color.ios.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
z-index -1
4949

5050
.q-color-hue .q-slider-track
51+
border-radius 2px
5152
background linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%) // @stylint ignore
5253
opacity 1
5354
height $dot-size * .8

src/components/color/color.mat.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
z-index -1
4949

5050
.q-color-hue .q-slider-track
51+
border-radius 2px
5152
background linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%) // @stylint ignore
5253
opacity 1
5354
height $dot-size * .8

src/components/datetime/QDatetime.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
:format24h="format24h"
4747
:first-day-of-week="firstDayOfWeek"
4848
:color="color"
49+
:default-view="defaultView"
4950
class="no-border"
5051
>
5152
<div class="row q-datetime-controls modal-buttons-top">
@@ -77,6 +78,7 @@
7778
:max="max"
7879
:format24h="format24h"
7980
:first-day-of-week="firstDayOfWeek"
81+
:default-view="defaultView"
8082
:color="color"
8183
class="no-border"
8284
:class="{'full-width': $q.theme === 'ios'}"
@@ -199,6 +201,15 @@ export default {
199201
},
200202
201203
__onFocus () {
204+
const target = this.$refs.target
205+
if (this.defaultView) {
206+
if (target.view !== this.defaultView) {
207+
target.setView(this.defaultView)
208+
}
209+
else {
210+
target.__scrollView()
211+
}
212+
}
202213
this.focused = true
203214
this.$emit('focus')
204215
},

src/components/datetime/QInlineDatetime.mat.vue

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,17 @@ export default {
262262
263263
switch (this.type) {
264264
case 'time':
265-
view = 'hour'
265+
view = this.defaultView && ['hour', 'minute'].includes(this.defaultView)
266+
? this.defaultView
267+
: 'hour'
266268
break
267269
case 'date':
270+
view = this.defaultView && ['year', 'month', 'day'].includes(this.defaultView)
271+
? this.defaultView
272+
: 'day'
273+
break
268274
default:
269-
view = 'day'
275+
view = this.defaultView || 'day'
270276
break
271277
}
272278
@@ -282,18 +288,8 @@ export default {
282288
this.view = ['date', 'datetime'].includes(this.type) ? 'day' : 'hour'
283289
}
284290
},
285-
view (value) {
286-
if (value !== 'year' && value !== 'month') {
287-
return
288-
}
289-
290-
let
291-
view = this.$refs.selector,
292-
rows = value === 'year' ? this.year - this.yearMin : this.month - this.monthMin
293-
294-
this.$nextTick(() => {
295-
view.scrollTop = rows * height(view.children[0].children[0]) - height(view) / 2.5
296-
})
291+
view () {
292+
this.__scrollView()
297293
}
298294
},
299295
computed: {
@@ -441,9 +437,37 @@ export default {
441437
},
442438
443439
/* helpers */
440+
setView (view) {
441+
if (this.type === 'time') {
442+
if (['hour', 'minute'].includes(view)) {
443+
this.view = view
444+
}
445+
}
446+
else if (this.type === 'date') {
447+
if (['year', 'month', 'day'].includes(view)) {
448+
this.view = view
449+
}
450+
}
451+
else {
452+
this.view = view
453+
}
454+
},
444455
__pad (unit, filler) {
445456
return (unit < 10 ? filler || '0' : '') + unit
446457
},
458+
__scrollView () {
459+
if (this.view !== 'year' && this.view !== 'month') {
460+
return
461+
}
462+
463+
let
464+
el = this.$refs.selector,
465+
rows = this.view === 'year' ? this.year - this.yearMin : this.month - this.monthMin
466+
467+
this.$nextTick(() => {
468+
el.scrollTop = rows * height(el.children[0].children[0]) - height(el) / 2.5
469+
})
470+
},
447471
__dragStart (ev) {
448472
stopAndPrevent(ev)
449473
@@ -498,6 +522,9 @@ export default {
498522
__getRepeatEasing (from = 300, step = 10, to = 100) {
499523
return cnt => cnt ? Math.max(to, from - cnt * cnt * step) : 100
500524
}
525+
},
526+
mounted () {
527+
this.__scrollView()
501528
}
502529
}
503530
</script>

src/components/datetime/datetime-props.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export const inline = {
3838
type: [Boolean, Number],
3939
default: 0,
4040
validator: v => [true, false, 0].includes(v)
41+
},
42+
defaultView: {
43+
type: String,
44+
validator: v => ['year', 'month', 'day', 'hour', 'minute'].includes(v)
4145
}
4246
}
4347

0 commit comments

Comments
 (0)