-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Report] add keyboard controls to v-datepicker #5629
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I've changed this issue to refer only to datepicker and created a separate issue for time picker |
Meanwhile, I've wrapped it in a custom component and implemented basic keyboard navigation. Note: This implementation uses moment to simplify date manipulation. DateField.vue<template>
<div ref="container">
<v-menu
:attach="$refs.container"
transition="scale-transition"
full-width
min-width="290px"
:close-on-content-click="false"
v-model="showMenu"
>
<template #activator="{on}">
<v-text-field
ref="textField"
prepend-icon="mdi-calendar"
label="Date"
readonly
:value="value"
v-on="on"
@keydown.up="up"
@keydown.down="down"
@keydown.left="left"
@keydown.right="right"
@keydown.enter="dateSelected"
@focus="$emit('focus')"
></v-text-field>
</template>
<v-date-picker
ref="datePicker"
no-title
scrollable
:value="value"
@click:date="dateSelected"
@change="$emit('input', $event)"
></v-date-picker>
</v-menu>
</div>
</template> <script>
import moment from 'moment'
export default {
props: {
value: {
type: String,
required: true
},
show: {
type: Boolean,
default: false
}
},
data() {
return {
showMenu: false
}
},
watch: {
show: {
immediate: true,
handler(show) {
show = show === true || show === false ? show : false
this.toggleMenu(show, false)
}
}
},
methods: {
toggleMenu(show = null, emit = true) {
show = show !== null ? show : !this.showMenu
if (show === this.showMenu) {
return
}
this.showMenu = show
if (emit) {
this.$emit('update:show', show)
}
},
dateSelected() {
this.toggleMenu(false)
this.$emit('date-selected')
},
// keyboard navigation
pickModified(modifier) {
this.$refs.datePicker.dateClick(
modifier(moment(this.$refs.datePicker.inputDate)).format('YYYY-MM-DD')
)
},
up() {
this.pickModified(m => m.subtract(1, 'weeks'))
},
down() {
this.pickModified(m => m.add(1, 'weeks'))
},
left(e) {
this.pickModified(m =>
e.shiftKey ? m.subtract(1, 'month') : m.subtract(1, 'days')
)
},
right(e) {
this.pickModified(m =>
e.shiftKey ? m.add(1, 'month') : m.add(1, 'days')
)
}
}
}
</script> |
This comment has been minimized.
This comment has been minimized.
I now feel like keyboard support may be a separate functionality. In my case, I made
|
This comment has been minimized.
This comment has been minimized.
Yes, planned for 3.0, nothing set in stone though |
Note also that formatting together with reasonable label / message cues and an editable |
Saving this for reference to the native date picker: https://codepen.io/johnjleider/pen/wvWbmdj?editors=101 |
Problem to solve
Currently user's need to use the mouse to select date. Which is not very quick and efficient.
Proposed solution
Use the arrow keys to move around the calendar when it is open. Press enter to select the date the user has currently selected.
The text was updated successfully, but these errors were encountered: