DateRangePicker
Date, datetime, month and year ranges with independent endpoints and complete-range confirmation.
Import
With uni-app easycom, use hui-date-range-picker。 Standalone Vue imports @nscode/handy-uni/web HuiDateRangePicker or installs the preview plugin.
Examples
Interaction and event results
Interact with the control. The latest event and its full payload are shown below. Popup selectors commit only after confirmation; cancellation keeps the previous value.
<script setup lang="ts">
import { ref } from 'vue'
import type { DateRangeShortcut } from '@nscode/handy-uni'
const result = ref('')
const value = ref(null)
const shortcuts: DateRangeShortcut[] = [
{ text: '本周 / This week', value: () => [new Date(2026, 10, 23), new Date(2026, 10, 29)] }
]
function event0(arg0: unknown) {
result.value = 'update:modelValue' + ': ' + JSON.stringify([arg0])
}
function event1(arg0: unknown, arg1: unknown) {
result.value = 'change' + ': ' + JSON.stringify([arg0, arg1])
}
function event2(arg0: unknown) {
result.value = 'select' + ': ' + JSON.stringify([arg0])
}
function event3() {
result.value = 'over-range' + ': ' + JSON.stringify([])
}
function event4() {
result.value = 'clear' + ': ' + JSON.stringify([])
}
function event5(arg0: unknown) {
result.value = 'update:visible' + ': ' + JSON.stringify([arg0])
}
function event6() {
result.value = 'open' + ': ' + JSON.stringify([])
}
function event7() {
result.value = 'opened' + ': ' + JSON.stringify([])
}
function event8(arg0: unknown) {
result.value = 'close' + ': ' + JSON.stringify([arg0])
}
function event9() {
result.value = 'closed' + ': ' + JSON.stringify([])
}
</script>
<template>
<view>
<hui-date-range-picker
v-model="value"
:shortcuts="shortcuts"
:max-range="7"
clearable
@update:model-value="event0"
@change="event1"
@select="event2"
@over-range="event3"
@clear="event4"
@update:visible="event5"
@open="event6"
@opened="event7"
@close="event8"
@closed="event9"
></hui-date-range-picker>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Behavior and platform support
native is intended for basic date, month and year selection; standalone Vue falls back to custom year selection. Both endpoints are required. Date spans include both endpoints; month and year spans use calendar units.
Opening the wheel records its displayed start date in the draft. Switching to an empty end tab records the displayed date there too. Moving the start past the previous end clears and marks the end, shows a prompt, and blocks confirmation until the end is filled. Out-of-range or disabled endpoints show a prompt and preserve the draft.
The custom trigger supports Tab focus and Enter or Space to open. Escape and system back report close('back'); overlay dismissal reports close('overlay').
Clear through a component ref
clearable controls the visible clear action; clear() can also be called independently. Disabled, readonly and confirmation-pending controls ignore it. Clearing resets the panel draft and emits update:modelValue, clear, then change. Controlled trigger text waits for the parent update.
<script setup lang="ts">
import { ref } from 'vue'
import type { DateRangePickerExpose } from '@nscode/handy-uni'
const control = ref<DateRangePickerExpose>()
const value = ref<[string, string] | null>(['2026-11-24', '2026-11-25'])
</script>
<template>
<view>
<hui-date-range-picker ref="control" v-model="value" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | DateRangeValue | undefined | undefined | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | DateRangeValue | undefined | null | Initial uncontrolled value. |
type | "date" | "datetime" | "year-month" | "year" | undefined | 'date' | Date granularity: date, datetime, year-month or year. |
panel | "wheel" | "calendar" | undefined | — | date defaults to calendar; other granularities use wheel. |
value-format | string | undefined | — | Model format string, timestamp or date. |
format | string | undefined | — | Trigger display format. |
min | CalendarValue | undefined | — | Lower value bound, or minimum count for multiple selection. |
max | CalendarValue | undefined | — | Upper bound, star count for Rate, or maximum multiple-selection count. |
disabled-date | ((date: Date) => boolean) | undefined | — | Return true to disable a date. |
max-range | number | undefined | — | Maximum inclusive range span, measured in calendar days, months or years. |
allow-same-day | boolean | undefined | true | Allow the same start and end day. |
start-placeholder | string | undefined | — | Empty-start placeholder. |
end-placeholder | string | undefined | — | Empty-end placeholder. |
shortcuts | DateRangeShortcut[] | undefined | — | Shortcuts returning Date endpoints, clamped by min/max. |
native | boolean | undefined | false | Use native date selection, with custom fallback for datetime and standalone Vue year. |
before-confirm | ((value: DateRangeValue, context: { dates: [Date, Date] | null; }) => unknown) | undefined | — | Confirmation guard; false, thrown errors and rejected promises preserve the draft. |
visible | boolean | undefined | undefined | Controlled popup visibility. |
default-visible | boolean | undefined | false | Initial uncontrolled visibility. |
title | string | undefined | — | Popup title. |
confirm-text | string | undefined | — | Localized confirm-button text. |
cancel-text | string | undefined | — | Localized cancel-button text. |
placeholder | string | undefined | — | Placeholder for an empty value. |
trigger | boolean | undefined | true | Render the trigger; false leaves only the popup. |
separator | string | undefined | — | Separator between trigger labels. |
clearable | boolean | undefined | false | Show clear action and emit model/change updates. |
disabled | boolean | undefined | false | Disable user interaction, including inherited form state. |
readonly | boolean | undefined | undefined | Readonly; inherit form context when omitted. |
size | ComponentSize | undefined | — | Size priority: prop → FormItem → Form → ConfigProvider. |
close-on-click-overlay | boolean | undefined | true | Request closing on overlay click. |
z-index | number | undefined | — | Explicit layer index; otherwise assigned by the page layer stack. |
root-portal | boolean | undefined | false | Use platform root-portal support on uni. |
safe-area-inset-bottom | boolean | undefined | true | Add bottom safe-area spacing. |
custom-class | string | undefined | '' | Additional root classes. |
custom-style | string | CSSProperties | undefined | — | Additional root styles. |
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: DateRangeValue) | Requests a controlled value update. |
change | (value: DateRangeValue, context: { dates: [Date, Date] | null; }) | Reports change with the arguments shown in the example. |
select | (draft: [(CalendarValue | undefined)?, (CalendarValue | undefined)?]) | Reports select with the arguments shown in the example. |
over-range | () | Reports over-range with the arguments shown in the example. |
clear | () | Reports clear with the arguments shown in the example. |
update:visible | (visible: boolean) | Requests a controlled value update. |
open | () | Reports open with the arguments shown in the example. |
opened | () | Reports opened with the arguments shown in the example. |
close | (reason: string) | Reports close with the arguments shown in the example. |
closed | () | Reports closed with the arguments shown in the example. |
Slots
| Slot | Description |
|---|---|
trigger | Trigger scope: {text,value,open}. |
title | Title content. |
day | Calendar cell scope: {day}. |
footer | Confirmation and cancellation area. |
Methods
| Method | Signature |
|---|---|
open | () => void |
close | () => void |
clear | () => void |
Types
DateRangePickerProps、DateRangePickerEmits、DateRangePickerExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Maintains start/end drafts and uses the platform wheel wrapper for native interaction. |
| Device checks pending | Check wheel change/pending, date limits and confirmation timing on WeChat and App; verify commits after scrolling settles on Web. |
See examples/uni-demo/smoke/DateRangePicker.md for the checklist. Unit tests do not replace device acceptance.