Skip to content

Commit 8d32ea9

Browse files
fix: allow single-date selection in timeline date range picker (#767)
When selecting a date range, previously both start and end dates were required. Now only the start date is required — if the end date is omitted, the range defaults to that single day (start to start+1day). Also adds min/max constraints between the date inputs to prevent selecting an end date before the start date. Fixes #596
1 parent 0c0368c commit 8d32ea9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/InputTimeInterval.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ div
4646
tr(v-if="mode == 'range'")
4747
th.pr-2 Range:
4848
td
49-
input(type="date", v-model="start")
50-
input(type="date", v-model="end")
49+
input(type="date", v-model="start", :max="end || undefined")
50+
input(type="date", v-model="end", :min="start || undefined", placeholder="(optional)")
5151
button(
5252
class="btn btn-outline-dark btn-sm",
5353
type="button",
@@ -115,20 +115,27 @@ export default {
115115
computed: {
116116
value: {
117117
get() {
118-
if (this.mode == 'range' && this.start && this.end) {
119-
return [moment(this.start), moment(this.end).add(1, 'day')];
118+
if (this.mode == 'range' && this.start) {
119+
const startDate = moment(this.start);
120+
// If only start date is set, show that single day
121+
const endDate = this.end
122+
? moment(this.end).add(1, 'day')
123+
: startDate.clone().add(1, 'day');
124+
return [startDate, endDate];
120125
} else {
121126
return [moment().subtract(this.duration, 'seconds'), moment()];
122127
}
123128
},
124129
},
125130
emptyDaterange() {
126-
return !(this.start && this.end);
131+
return !this.start;
127132
},
128133
invalidDaterange() {
134+
if (!this.end) return false;
129135
return moment(this.start) > moment(this.end);
130136
},
131137
daterangeTooLong() {
138+
if (!this.end) return false;
132139
return moment(this.start).add(this.maxDuration, 'seconds').isBefore(moment(this.end));
133140
},
134141
},

0 commit comments

Comments
 (0)