Skip to content

Commit e483f0d

Browse files
committed
fix(datepicker): Set typed date to null if zero length
1 parent 1a1d3aa commit e483f0d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/components/DateInput.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export default {
112112
return this.inputClass
113113
},
114114
formattedDate() {
115+
if (!this.selectedDate) {
116+
return null
117+
}
118+
115119
return typeof this.format === 'function'
116120
? this.format(new Date(this.selectedDate))
117121
: this.utils.formatDate(
@@ -205,6 +209,11 @@ export default {
205209
* Parses a typed date and submits it, if valid
206210
*/
207211
handleKeyup() {
212+
if (this.input.value === '') {
213+
this.$emit('typed-date', null)
214+
return
215+
}
216+
208217
this.parsedDate = Date.parse(
209218
this.utils.parseDate(
210219
this.input.value,

src/components/Datepicker.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ export default {
449449
* @param {Date} date
450450
*/
451451
handleTypedDate(date) {
452-
this.selectDate(date.valueOf())
452+
this.selectDate(date ? date.valueOf() : null)
453453
},
454454
/**
455455
* Focus the relevant element when the view changes
@@ -530,6 +530,11 @@ export default {
530530
* @param {Number} timestamp
531531
*/
532532
selectDate(timestamp) {
533+
if (!timestamp) {
534+
this.selectedDate = null
535+
return
536+
}
537+
533538
const date = new Date(timestamp)
534539
this.selectedDate = date
535540
this.setPageDate(date)

0 commit comments

Comments
 (0)