DateTimePicker Date and time picker
Choose date or time values and commit a formatted value on confirmation.
Import
Use <hui-date-time-picker> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
<template>
<view>
<hui-date-time-picker
ref="control"
v-model="value"
type="date"
:min="minimum"
:max="maximum"
title="日期 / Date"
@update:model-value="event0"
@change="event1"
@pick="event2"
@cancel="event3"
@clear="event4"
@update:visible="event5"
@open="event6"
@opened="event7"
@close="event8"
@closed="event9"
/>
<text>{{ value }}</text>
<hui-button @click="() => control?.open()">open()</hui-button>
<hui-button @click="() => control?.close('api')">close()</hui-button>
<hui-button @click="() => control?.confirm()">confirm()</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { type DateTimeValue } from '@nscode/handy-uni'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const control = ref()
const value = ref<DateTimeValue>('2026-11-25')
const minimum = new Date(2026, 0, 1)
const maximum = new Date(2027, 11, 31)
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:modelValue' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown, arg1: unknown) => {
lastEvent.value = 'change' + ': ' + [describe(arg0), describe(arg1)].join(', ')
}
const event2 = (arg0: unknown, arg1: unknown) => {
lastEvent.value = 'pick' + ': ' + [describe(arg0), describe(arg1)].join(', ')
}
const event3 = () => {
lastEvent.value = 'cancel'
}
const event4 = () => {
lastEvent.value = 'clear'
}
const event5 = (arg0: unknown) => {
lastEvent.value = 'update:visible' + ': ' + [describe(arg0)].join(', ')
}
const event6 = () => {
lastEvent.value = 'open'
}
const event7 = () => {
lastEvent.value = 'opened'
}
const event8 = (arg0: unknown) => {
lastEvent.value = 'close' + ': ' + [describe(arg0)].join(', ')
}
const event9 = () => {
lastEvent.value = 'closed'
}
</script>
Construct local-date boundaries rather than slicing UTC strings. Month and year changes clamp invalid days, including leap-day and month-end cases.
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 { DateTimePickerExpose } from '@nscode/handy-uni'
const control = ref<DateTimePickerExpose>()
const value = ref<string | null>('2026-11-25')
</script>
<template>
<view>
<hui-date-time-picker ref="control" v-model="value" value-format="YYYY-MM-DD" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
visible | boolean | undefined | Controlled visibility; undefined is omitted and explicit false stays closed. |
defaultVisible | boolean | false | Initial uncontrolled visibility. |
title | string | — | Title. |
confirmText | string | — | Confirmation action text. |
cancelText | string | — | Cancel action text; an empty string remains an explicit override. |
placeholder | string | — | Placeholder when no value is selected or entered. |
trigger | boolean | true | Render the picker trigger. |
clearable | boolean | false | Show the clear action. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
beforeConfirm | ((value: DateTimeValue, ctx: { date: Date; }) => unknown) | — | Confirmation guard; false or rejection retains the current content. |
closeOnClickOverlay | boolean | true | Request guarded closing when the overlay is clicked. |
native | boolean | false | Try a native picker; unsupported modes fall back to custom wheels. |
zIndex | number | — | Layer z-index; allocated from the current page stack when omitted. |
rootPortal | boolean | false | Try to mount at the page root; support varies by platform. |
safeAreaInsetBottom | boolean | true | Reserve the bottom safe area. |
modelValue | DateTimeValue | undefined | Controlled value; undefined means omitted. |
defaultValue | DateTimeValue | null | Initial uncontrolled value; ignored in controlled mode. |
type | DateTimePickerType | 'date' | Semantic type or input mode; see the type definition. |
showSeconds | boolean | false | Include seconds in time-related wheels. |
valueFormat | string | — | Committed format; date returns a Date, timestamp returns milliseconds, and other formats return strings. |
format | string | — | Display format used by the trigger. |
min | string | number | Date | — | Minimum selection count or numeric value. |
max | string | number | Date | — | Maximum selection count, numeric value or displayed count. |
minuteStep | number | 1 | Minute step; invalid values fall back to 1. |
disabledDate | ((date: Date) => boolean) | — | disabled Date; see the value type. |
formatter | ((type: DateTimeColumnType, option: { value: number; label: string; }) => string) | — | Format option text in wheel columns. |
itemHeight | number | 44 | Height of each wheel item in px. |
visibleItemCount | number | 5 | Number of visible wheel items. |
loading | boolean | false | Loading state. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: DateTimeValue) | Request a controlled value update. |
change | (value: DateTimeValue, ctx: { date: Date }) | Emitted after the value changes. |
pick | (value: DateTimeValue, ctx: { date: Date; column: number }) | Reports the corresponding interaction result. |
cancel | () | Cancellation action. |
clear | () | Emitted after clearing. |
update:visible | (value: boolean) | Request a visibility update. |
open | () | Opening started. |
opened | () | Enter animation finished. |
close | (reason: PickerCloseReason) | Closing started after guards passed. |
closed | () | Leave animation finished. |
Slots
| Slot | Parameters | Description |
|---|---|---|
trigger | { text, value, open } | Custom trigger region; replaces its fallback content. |
toolbar | — | Custom toolbar region; replaces its fallback content. |
title | — | Custom title region; replaces its fallback content. |
option | { type, option, active } | Custom option region; replaces its fallback content. |
Methods
| Method | Signature | Description |
|---|---|---|
open | (): void | Open the uncontrolled panel or request a controlled update. |
close | (reason?: PickerCloseReason | undefined): void | Request closing through configured guards. |
confirm | (): Promise<void> | Call through the component ref. |
clear | () => void | Request clearing; ignored while disabled, readonly or confirmation-pending. |
Types
DateTimePickerProps、DateTimePickerExpose、DateTimePickerEmits are available from @nscode/handy-uni.
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
| Native mode | Native date/time selection | Depends on picker mode | Depends on native host | Uses native date/month/time inputs; year falls back to custom wheels |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.