DateRange
Two dates and the days between them, picked on two months side by side or one, with the span drawn before it is committed.
Import
import { DateRange } from '@vitral/vue';Two months
The default. Pick a start, then an end; the band between them follows the pointer before you commit. Each calendar stops at its own month — the days either side are left blank rather than repeating the month next door.
One month
The same range in a single calendar, for a form with no room for two. With no neighbour to repeat, the days either side of the month come back.
Month and year
The month and the year in each calendar's title are buttons. The year opens a page of twenty years, a year opens its months, and the month chosen is put in the calendar whose title was pressed, so a range years away is reached without paging there. The range itself is not touched on the way, and Escape goes back to the days.
Without the month or the year grid
Both are on by default and each is a prop. `:year-picker="false"` leaves the year as text, `:month-picker="false"` the month, and with both off the titles are only text and the calendars are paged a month at a time.
With times
`show-time` gives each end a time of day: a field for the start and one for the end, each waiting for its day. Closing the range leaves the calendars open for the times, and each end keeps its time when its day changes. `time-step` sets the minutes between the times listed, and `min-time` and `max-time` bound both ends, here from noon to ten at night. The range can also be typed, each end with its time.
Typing a range
The box takes a range typed into it: two dates with the separator between them, read on Enter or when the box is left, sorted if typed backwards. A `date-format` of fixed width gives the box its shape, `__/__/____ – __/__/____`. `:manual-input="false"` leaves the box for showing the range, and a press on it opens the calendars; `:mask="false"` keeps the typing and drops the shape.
With the spans people ask for by name
The footer is a slot: presets, a count of nights, whatever the form needs.
Inline
Without the text box or the popup.
Showing the neighbouring days anyway
`show-other-months` overrides what the number of calendars decided. Two months with their edges drawn: February’s last days appear again as March’s first, and a range spanning the boundary is painted twice.
The shape of it
API
Read from packages/vue/src/components/DateRange/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| months | number | How many months to show side by side. Two is the default and the reason this component exists: a span that crosses a month boundary is chosen in one gesture rather than by paging. One shows the same range in a single calendar. |
| showOtherMonths | boolean | Whether the days either side of each month are drawn. Left unset, they are on a single calendar and off on several: with two months side by side the last days of one are the first days of the next, so the same date appears twice, a range paints across both copies, and the boundary between the calendars stops meaning anything. The cells stay — the grid keeps its six rows and its height — they are simply left empty. |
| dateFormat | string | A `formatDate` pattern; defaults to the locale's `dateFormat`. |
| separator | string | Between the two dates in the text box. |
| manualInput | boolean | Whether a range can be typed into the text box: two dates with the separator between them, each with its time under `showTime`, read on Enter or when the box is left. On by default; off, the box only shows the range and a press on it opens the calendars. |
| mask | boolean | MaskProp | Whether the text box types into the shape the range is written in. On by default, for a `dateFormat` of fixed width: `99/99/9999 – 99/99/9999`. `false` leaves the box free; a mask of your own, as InputMask takes, replaces the derived one. |
| minDate | Date | null | — |
| maxDate | Date | null | — |
| disabledDates | Date[] | — |
| disabledDays | number[] | Weekdays that cannot be chosen, 0 = Sunday. |
| monthPicker | boolean | Whether the month in each calendar's title opens a grid of the twelve months. On by default; off, the month is only text and is reached by paging. |
| yearPicker | boolean | Whether the year in each calendar's title opens a grid of years. On by default; off, the year is only text. With the month grid off as well, the calendars can only be paged a month at a time. |
| showTime | boolean | Take a time of day with each end. The calendars gain a time field for the start and one for the end, the text box writes each time after its date, and closing the range leaves the calendars open for the times. A time field waits for its end to be chosen. Off by default. |
| timeStep | number | Minutes between the times the time fields offer. Defaults to 30; any minute can still be typed. |
| minTime | number | string | null | The earliest time of day, as minutes past midnight or `'08:00'`. A time chosen or typed before it is moved up to it. |
| maxTime | number | string | null | The latest time of day, likewise. |
| hour12 | boolean | Force twelve- or twenty-four-hour time; defaults to what the locale writes. |
| showClearButton | boolean | A footer button that empties the range. |
| firstDayOfWeek | number | 0 = Sunday; defaults to the locale's `firstDayOfWeek`. |
| placeholder | string | — |
| inline | boolean | Show the calendars in place, without a text box or popup. |
| size | Size | — |
| variant | InputVariant | Defaults to the plugin's `inputVariant`. |
| invalid | boolean | — |
| disabled | boolean | — |
| readonly | boolean | — |
| fluid | boolean | — |
| placement | OverlayPlacement | — |
| appendTo | string | `'body'` (the default), `'self'` to render in place, or a selector. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| rangeSelect | range: DateRangeValue | Both ends are down. Fires once a range is whole, not on the first press; with `showTime`, also when a time changes. |
| clear | — | — |
| show | — | — |
| hide | — | — |
| monthChange | event: { month: number; year: number } | — |
Slots
| Name | Slot props | Description |
|---|---|---|
| date | (props: { date: Date; day: number; today: boolean; inRange: boolean; end: 'start' | 'end' | null; disabled: boolean; otherMonth: boolean }) | A day's content. |
| footer | (props: { range: DateRangeValue; nights: number; clear: () => void }) | Under the calendars: presets, a count of nights, a pair of buttons. |