Date Range Picker
Enter a date range by typing or selecting from a calendar.
Demos
Usage
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Typing and calendar selection
Click a date segment to type or use the calendar button to choose a date. Focus and text selection use the neutral secondary fill with its paired foreground. A subtle ring marks the active segment. Slashes have their own spacing. The calendar opens outside the preview frame and follows the same size as the field.
Installation
Complete the shared installation. Copy DateRangePicker.vue and index.ts into app/components/ui/date-range-picker/. Also copy the required components: Calendar, Date Field, Date Range Field.
<script setup lang="ts">
import { DateField as Primitive } from 'akaza-ui'
import { computed, nextTick, useAttrs, useTemplateRef } from 'vue'
import { cn, mergeRecipeSlots } from '../../../utils/ui'
import { calendarVariants } from '../calendar'
import uiConfig from '../ui.config'
import {
dateFieldVariants,
resolveDateFieldVariants,
type DateFieldProps,
type DateFieldSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<DateFieldProps>(), {
id: undefined,
name: undefined,
locale: undefined,
dir: undefined,
placeholder: undefined,
minValue: undefined,
maxValue: undefined,
isDateUnavailable: undefined,
required: undefined,
disabled: undefined,
readOnly: undefined,
invalid: undefined,
selectOnFocus: undefined,
autoAdvance: undefined,
showCalendar: true,
calendarLabel: undefined,
calendarSide: undefined,
calendarAlign: undefined,
calendarSideOffset: undefined,
calendarTeleport: 'body',
ariaLabel: undefined,
ariaLabelledby: undefined,
ariaDescribedby: undefined,
ui: undefined,
modelValue: undefined,
calendarOpen: undefined,
})
defineSlots<DateFieldSlots>()
const attrs = useAttrs()
const resolved = computed(() => resolveDateFieldVariants(props, uiConfig))
const styles = computed(() => dateFieldVariants(resolved.value))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
const flat = Object.fromEntries(
Object.entries(styles.value)
.filter(([part]) => !['calendar'].includes(part))
.map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
return {
...flat,
calendar: mergeRecipeSlots(calendarVariants({ size: resolved.value.size }), {
...props.ui?.calendar,
root: cn(styles.value.calendar(), props.ui?.calendar?.root),
}),
}
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, variant: _variant, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
async function onFieldClick(event: MouseEvent) {
const target = event.target as HTMLElement
if (
props.showCalendar &&
!props.disabled &&
!props.readOnly &&
target.closest('.akaza-date-field-segments')
) {
primitive.value?.openCalendar(event)
// Calendar initial focus belongs to its button; clicking a segment must keep typing focus.
await nextTick()
await nextTick()
target.focus({ preventScroll: true })
}
}
defineExpose({
get validationState() {
return primitive.value!.validationState
},
get clear() {
return primitive.value!.clear
},
get closeCalendar() {
return primitive.value!.closeCalendar
},
get focus() {
return primitive.value!.focus
},
get openCalendar() {
return primitive.value!.openCalendar
},
get setValue() {
return primitive.value!.setValue
},
get toggleCalendar() {
return primitive.value!.toggleCalendar
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
@click="onFieldClick"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof DateFieldSlots" v-bind="scope ?? {}"
/></template>
<template v-if="!$slots['calendar-trigger']" #calendar-trigger
><svg
class="size-4 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
aria-hidden="true"
>
<path
d="M8 2v4m8-4v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"
/></svg
></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | outline, soft, bare | outline |
Models
| Model | Type | Default | Description |
|---|---|---|---|
v-model | CalendarDateRange | {} | Shared typed and calendar-selected range. |
v-model:open | boolean | false | Popup open state. |
v-model:placeholder | CalendarDateValue | selected endpoint or today | First visible calendar month. |
See Range selection for preview fills and primary-colored endpoints.
Props
Date Range Picker accepts Date Range Field props id, name, startName, endName, locale, dir, minValue, maxValue, isDateUnavailable, allowNonContiguousRanges, maximumDays, fixedDate, required, disabled, readOnly, invalid, selectOnFocus, autoAdvance, endpoint labels, and ARIA relationships.
| Prop | Type | Default | Description |
|---|---|---|---|
rangeColor | "secondary" | "accent" | "secondary" | Preview and committed middle fill; endpoints use primary. |
isDateDisabled | (date) => boolean | - | Calendar-only disabled-date rule. |
calendarLabel | string | "Choose date range" | Trigger and popup accessible label. |
closeLabel | string | - | Renders an explicit close button with this label. |
closeOnSelect | boolean | true | Closes after both endpoints are selected. |
weekStartsOn | "sun" | "mon" | ... | locale default | Explicit first weekday. |
weekdayFormat | "narrow" | "short" | "long" | "narrow" | Visible weekday format. |
fixedWeeks | boolean | false | Renders six weeks per month for stable popup height. |
numberOfMonths | number | 1 | Adjacent month grids. |
pagedNavigation | boolean | false | Moves by numberOfMonths. |
disableDaysOutsideCurrentView | boolean | false | Blocks selecting outside days. |
nextPage | (placeholder) => CalendarDateValue | add month(s) | Custom next page calculation. |
prevPage | (placeholder) => CalendarDateValue | subtract month(s) | Custom previous page calculation. |
side | "top" | "right" | "bottom" | "left" | "bottom" | Preferred popup side with collision flipping. |
align | "start" | "center" | "end" | "start" | Popup alignment. |
sideOffset | number | 6 | Trigger-to-popup gap in pixels. |
teleport | string | false | "body" | Teleport target; false keeps popup beside root. |
ui | DateRangePickerUi | - | Classes and nested field/calendar UI maps. |
Slots
| Slot | Props | Description |
|---|---|---|
start-literal | value | Start endpoint locale separator. |
separator | - | Endpoint separator. |
end-literal | value | End endpoint locale separator. |
trigger | isOpen, open, close, toggle | Calendar trigger content. Actions are native event-handler safe. |
calendar | value, close | Replaces built-in Calendar. |
previous | disabled | Built-in Calendar previous control content. |
heading | label, months | Built-in Calendar heading. |
next | disabled | Built-in Calendar next control content. |
weekday | date, label | Built-in weekday content. |
day | Complete CalendarDay state | Built-in day button content. |
footer | value, placeholder | Optional built-in Calendar footer. |
close | close | Explicit close-button content. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | CalendarDateRange | Fires after accepted typed or calendar changes. |
value-change | (range, details) | Fires before value changes. details.cancel() prevents update. |
value-commit | (range, details) | Fires after accepted field or calendar commits. |
update:open | boolean | Fires after accepted popup state changes. |
open-change | (open, details) | Fires before popup changes. Cancelable. |
update:placeholder | CalendarDateValue | Fires after accepted visible-month changes. |
placeholder-change | (date, details) | Fires before visible-month changes. Cancelable. |
Open reasons include trigger, select, escape, outside-click, and programmatic. Value reasons match Date Range Field plus calendar.