Date Range Picker
MDateRangePicker edits an inclusive start/end pair using the Date Picker contract. Each endpoint has a labelled editor (ISO by default) and a themed calendar; applications do not need to compose raw inputs or native pickers.
<script setup lang="ts">
import { ref } from 'vue'
import type { DateRange } from '@getcortexlabs/mavis-core'
const dates = ref<DateRange>({ start: null, end: null })
</script>
<template>
<MDateRangePicker v-model="dates" label="Travel dates" locale="en-US"
initialMonth="2026-11" min="2026-11-01" max="2026-12-31"
:unavailableDates="['2026-11-15']" />
</template>Both endpoints are included. Equal endpoints describe one day and are accepted. { start: null, end: null } is empty; either endpoint may remain null while editing, and a valid partial pair is emitted with complete: false. The component does not invent a missing endpoint or silently reorder a reversed pair.
Each raw draft remains visible. An incomplete/invalid endpoint, start > end, or an unavailable day anywhere in the inclusive interval blocks the model proposal while preserving both drafts. Fixing the other endpoint can make the pair valid. A partial pair checks its existing endpoint. The clear action clears both drafts and proposes both endpoints as null; manually clearing just one editor proposes a partial pair. A changed external model replaces both drafts. Rejected valid proposals return to the parent's pair. Application validation remains authoritative.
All Date Picker options and lifecycle rules apply except name. Range-specific props are:
| Prop | Type | Default | Meaning |
|---|---|---|---|
modelValue / v-model | DateRange | { start: null, end: null } | Two CivilDate | null endpoints. |
startLabel / endLabel | string | localized Start / End | Endpoint labels; the visible field label is included. |
startName / endName | string | unset | Separate Web HTML names; submit each visible draft. |
update:modelValue emits a DateRange; update:draft emits { start: string, end: string }. validityChange uses the same DateValidation, adding partial, reversed and unavailable-range reasons. Empty and partial ranges are valid but incomplete; an app can require both dates. focus() focuses the start editor and blur() dismisses either editor. The component also emits focus and blur from its text editors.
Calendar shading displays an ordered draft interval; it does not imply that a host accepted a pending draft. Calendar selection changes the endpoint whose calendar was opened, runs the same range validation as typing, and closes that calendar. If selecting an end before the start, both drafts stay visible with an error and the prior accepted model is preserved. While you choose the end on the Web, hovering or moving focus across days previews the band from the start. A refused endpoint shakes its own field once.
This component stores civil dates, not nights, durations, appointments or instants. Any conversion to instants or business interpretation of inclusive endpoints belongs to the host application. The built-in Gregorian locales are en-US and pt-BR; default parsing remains YYYY-MM-DD for both.
View source
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import type { DateRange } from '@getcortexlabs/mavis-core'
const { t, locale } = useCatalogLocale(() => props.lang)
const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const range = ref<DateRange>({ start: '2026-11-12', end: '2026-11-14' })
</script>
<template>
<m-column gap="lg">
<m-text variant="heading">{{ t(pt ? 'Tempo para explorar' : 'Time to explore') }}</m-text>
<m-date-range-picker
v-model="range"
:label="t(pt ? 'Período da viagem' : 'Travel dates')"
:locale="pt ? 'pt-BR' : 'en-US'"
min="2026-11-01"
max="2026-12-31"
initialMonth="2026-11"
today="2026-11-06"
:helperText="
t(
pt
? 'As duas datas fazem parte do intervalo. Um único dia também vale.'
: 'Both endpoints are included. A single day is also a valid range.',
)
"
/>
<m-text :text="t(`${range.start ?? '—'} → ${range.end ?? '—'}`)" />
<m-text variant="caption" tone="muted">{{
t(
pt
? 'Datas civis: o app decide como associar um horário ou fuso.'
: 'Civil dates: your app decides how to associate a time or time zone.',
)
}}</m-text>
</m-column>
</template>Restore an unfinished edit
draft controls the visible text independently of the valid modelValue. Use v-model:draft with a string for DatePicker or { start: string, end: string } for DateRangePicker. An incomplete value such as 2026-11- can be saved and restored without inventing a valid date. Calendar selection/clear propose both draft and model updates; bind both when the app owns both. If a draft update is rejected, the editor returns to the supplied draft on the next render. Omitting draft preserves the uncontrolled editing behavior.
<m-date-picker v-model="date" v-model:draft="draft" label="Date" />Web SSR renders the text editor immediately, with calendar/clear actions disabled until mounting. Hydration enables those actions. The calendar trigger takes focus on primary mousedown before opening, so closing the calendar returns focus consistently, including Safari. No consumer DOM directive or mount-only button wrapper is needed.
Alpha.9 supports dateFormat on both editors, with calendar actions embedded in each input. See localized editing and timezone helpers. Range models remain canonical civil dates; drafts retain their displayed format.
Desktop
Each end of the range is its own field and opens the calendar just under itself; while the end is chosen, the band from the start follows the pointer or the selected day. startName and endName have no effect outside the browser. See Desktop components.