Calendar
A popup calendar with a separate draft. Cancellation preserves the model; confirmation commits after its guard passes.
The trigger supports Tab focus and Enter or Space to open. A range containing only its start shows a prompt and disables confirmation. When same-day ranges are disallowed, truncation at disabled dates or span limits cannot commit equal endpoints. Escape and system back report close('back'); overlay dismissal reports close('overlay').
Import
With uni-app easycom, use hui-calendar。 Standalone Vue imports @nscode/handy-uni/web HuiCalendar 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'
const result = ref('')
const value = ref(null)
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, arg1: unknown) {
result.value = 'select' + ': ' + JSON.stringify([arg0, arg1])
}
function event3(arg0: unknown) {
result.value = 'update:month' + ': ' + JSON.stringify([arg0])
}
function event4(arg0: unknown) {
result.value = 'over-range' + ': ' + JSON.stringify([arg0])
}
function event5() {
result.value = 'clear' + ': ' + JSON.stringify([])
}
function event6(arg0: unknown) {
result.value = 'update:visible' + ': ' + JSON.stringify([arg0])
}
function event7() {
result.value = 'open' + ': ' + JSON.stringify([])
}
function event8() {
result.value = 'opened' + ': ' + JSON.stringify([])
}
function event9(arg0: unknown) {
result.value = 'close' + ': ' + JSON.stringify([arg0])
}
function event10() {
result.value = 'closed' + ': ' + JSON.stringify([])
}
</script>
<template>
<view>
<hui-calendar
v-model="value"
select-mode="range"
title="选择日期 / Select dates"
:max-range="7"
clearable
@update:model-value="event0"
@change="event1"
@select="event2"
@update:month="event3"
@over-range="event4"
@clear="event5"
@update:visible="event6"
@open="event7"
@opened="event8"
@close="event9"
@closed="event10"
></hui-calendar>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
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 { CalendarExpose } from '@nscode/handy-uni'
const control = ref<CalendarExpose>()
const value = ref<string | null>('2026-11-25')
</script>
<template>
<view>
<hui-calendar ref="control" v-model="value" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
format | string | undefined | — | Trigger display format. |
show-confirm | boolean | undefined | true | Control show-confirm. |
before-confirm | ((value: CalendarModelValue, context: { dates: Date[]; }) => 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. |
model-value | CalendarModelValue | undefined | undefined | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | CalendarModelValue | undefined | null | Initial uncontrolled value. |
select-mode | CalendarSelectMode | undefined | 'single' | single, multiple or range selection. |
value-format | string | undefined | 'YYYY-MM-DD' | Model format string, timestamp or date. |
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. |
month | string | undefined | — | Controlled displayed month, YYYY-MM. |
default-month | string | undefined | — | Initial displayed month, YYYY-MM. |
first-day-of-week | number | undefined | 7 | First weekday: 1 for Monday through 7 for Sunday. |
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. |
max-count | number | undefined | — | Maximum selected date count. |
formatter | ((day: CalendarDay) => Partial<Pick<CalendarDay, "disabled" | "topText" | "bottomText" | "className">>) | undefined | — | Format calendar cells using the latest callback when dates recalculate or reset is called. |
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: CalendarModelValue) | Requests a controlled value update. |
change | (value: CalendarModelValue, context: { dates: Date[]; }) | Reports change with the arguments shown in the example. |
select | (value: CalendarModelValue, context: { dates: Date[]; }) | Reports select with the arguments shown in the example. |
update:month | (month: string) | Requests a controlled value update. |
over-range | (info: { reason: "max-range" | "max-count"; }) | 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}. |
header | Month header scope: {month,prev,next,canPrev,canNext}. |
footer | Confirmation and cancellation area. |
Methods
| Method | Signature |
|---|---|
open | () => void |
close | () => void |
clear | () => void |
Types
CalendarProps、CalendarEmits、CalendarExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Combines the shared calendar view with Popup. Selection and confirmation rules are consistent across targets. |
| Device checks pending | Check month scrolling inside the popup, disabled dates, confirm/cancel and leaving layers. This is not a system calendar. |
See examples/uni-demo/smoke/Calendar.md for the checklist. Unit tests do not replace device acceptance.