Skip to content

Commit c7d550e

Browse files
select on focus & up/down arrows support
1 parent 8159da4 commit c7d550e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/timepicker/TimePicker.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
pattern="\d*"
2424
class="form-control text-center"
2525
style="width: 50px"
26+
@focus="selectInputValue"
27+
@keyup.up="keyupArrow(1, 1)"
28+
@keyup.down="keyupArrow(1, 0)"
2629
@wheel="hoursWheel"
2730
placeholder="HH"
28-
v-model="hoursText"
31+
v-model.lazy="hoursText"
2932
:readonly="readonly"
3033
maxlength="2"
3134
size="2">
@@ -36,9 +39,12 @@
3639
pattern="\d*"
3740
class="form-control text-center"
3841
style="width: 50px"
42+
@focus="selectInputValue"
43+
@keyup.up="keyupArrow(0, 1)"
44+
@keyup.down="keyupArrow(0, 0)"
3945
@wheel="minutesWheel"
4046
placeholder="MM"
41-
v-model="minutesText"
47+
v-model.lazy="minutesText"
4248
:readonly="readonly"
4349
maxlength="2"
4450
size="2">
@@ -262,6 +268,17 @@
262268
time = time < min ? min : time
263269
}
264270
this.$emit('input', new Date(time))
271+
},
272+
selectInputValue (e) {
273+
setTimeout(function () {
274+
e.target.setSelectionRange(0, e.target.value.length)
275+
}, 0)
276+
},
277+
keyupArrow (isHour, isPlus) {
278+
if (!this.readonly) {
279+
// e.preventDefault()
280+
this.changeTime(isHour, isPlus)
281+
}
265282
}
266283
}
267284
}

0 commit comments

Comments
 (0)