DatePickerPanel Date selection panel
An inline, compact date, month or year selector. Use DatePicker for a popup selector. Calendar is a larger month calendar with content inside its cells; DatePickerPanel focuses on selecting one value.
Import
import { HuiDatePickerPanel } from '@nscode/handy-ui'
import type { DatePickerPanelProps, DatePickerPanelExpose } from '@nscode/handy-ui'
Examples
Selection and change
Use v-model to accept a selection. change fires when the selected day changes; choosing the same day still emits update:modelValue.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const value = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
const changes = ref(0)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiDatePickerPanel v-model="value" @change="changes++" />
<span>Selected:{{ value instanceof Date ? value.toLocaleDateString() : value }}</span>
<span>change:{{ changes }}</span>
</HuiSpace>
</template>
Date, month and year
date, month and year compare selections at their corresponding precision. Month and year selections emit the first day of that month or year.
<script setup lang="ts">
import { reactive } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelType, DatePickerPanelValue } from '@nscode/handy-ui'
const cases = reactive<{ type: DatePickerPanelType; value: DatePickerPanelValue }[]>(
(['date', 'month', 'year'] as const).map((type) => ({ type, value: new Date(2024, 0, 15) }))
)
</script>
<template>
<HuiSpace wrap align="start">
<HuiSpace v-for="item in cases" :key="item.type" direction="vertical" align="start">
<strong>{{ item.type }}</strong>
<HuiDatePickerPanel v-model="item.value" :type="item.type" />
<span>{{ item.value instanceof Date ? item.value.toLocaleDateString() : item.value }}</span>
</HuiSpace>
</HuiSpace>
</template>
String output and timestamp input
value-format follows DatePicker formatting rules. Without a format, selections emit Date; x emits millisecond numbers, X emits second numbers, and other formats emit strings. Numeric input uses seconds with X and milliseconds otherwise. x/X must be the complete format, without other tokens; x/X inside square brackets remain literal text.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const text = ref<DatePickerPanelValue>('15/01/2024')
const timestamp = ref<DatePickerPanelValue>(new Date(2024, 1, 10).getTime())
const milliseconds = ref<DatePickerPanelValue>(new Date(2024, 1, 10).getTime())
const seconds = ref<DatePickerPanelValue>(Math.floor(new Date(2024, 1, 10).getTime() / 1000))
</script>
<template>
<HuiSpace wrap align="start">
<HuiSpace direction="vertical" align="start">
<span>valueFormat = DD/MM/YYYY</span>
<HuiDatePickerPanel v-model="text" value-format="DD/MM/YYYY" />
<code>{{ text }}</code>
</HuiSpace>
<HuiSpace direction="vertical" align="start">
<span>Millisecond input, Date output</span>
<HuiDatePickerPanel v-model="timestamp" />
<code
>{{ typeof timestamp }}:{{
timestamp instanceof Date ? timestamp.toLocaleDateString() : timestamp
}}</code
>
</HuiSpace>
<HuiSpace direction="vertical" align="start">
<span>x: millisecond input and output</span>
<HuiDatePickerPanel v-model="milliseconds" value-format="x" />
<code>{{ typeof milliseconds }}: {{ milliseconds }}</code>
</HuiSpace>
<HuiSpace direction="vertical" align="start">
<span>X: second input and output</span>
<HuiDatePickerPanel v-model="seconds" value-format="X" />
<code>{{ typeof seconds }}: {{ seconds }}</code>
</HuiSpace>
</HuiSpace>
</template>
Bound values with offsets
Z uses ±HH:mm and ZZ uses ±HHmm. Both formats also accept UTC input ending in Z. Bound strings must match the offset format strictly: invalid dates and missing or mismatched offsets do not fall back to loose parsing. Initial values are converted from the explicit offset into a local calendar date. Selecting a date emits local midnight with its local offset, without retaining the input offset. [Z] / [ZZ] remain literal text. This panel selects dates and has no IANA timezone selector. defaultViewDate can still use a plain date to initialize the viewed month without selecting or submitting that date.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const colon = ref<DatePickerPanelValue>('2024-01-01T00:15:00+05:45')
const compact = ref<DatePickerPanelValue>('2023-12-31T15:00:00-0330')
</script>
<template>
<HuiSpace wrap align="start">
<HuiSpace direction="vertical" align="start">
<span>Z: ±HH:mm</span>
<HuiDatePickerPanel v-model="colon" value-format="YYYY-MM-DDTHH:mm:ssZ" />
<code>{{ colon }}</code>
</HuiSpace>
<HuiSpace direction="vertical" align="start">
<span>ZZ: ±HHmm</span>
<HuiDatePickerPanel v-model="compact" value-format="YYYY-MM-DDTHH:mm:ssZZ" />
<code>{{ compact }}</code>
</HuiSpace>
</HuiSpace>
</template>
Initial view and external values
default-view-date is an initial fallback when no valid value is selected. A changed external value moves the view to its month; an empty value preserves the current view.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const value = ref<DatePickerPanelValue>(null)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiButton @click="value = new Date(2025, 7, 20)">Select August 20, 2025</HuiButton>
<HuiDatePickerPanel v-model="value" default-view-date="2024-06-01" />
<span>Initial view: June 2024; no initial selection</span>
</HuiSpace>
</template>
Disabled weekends and custom cells
disabled-date prevents selection. cell-class-name adds classes to date cells; this example marks the first day of each month.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const value = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
const disabledDate = (date: Date) => [0, 6].includes(date.getDay())
const cellClassName = (date: Date) => (date.getDate() === 1 ? 'date-panel-mark' : '')
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiDatePickerPanel
v-model="value"
:disabled-date="disabledDate"
:cell-class-name="cellClassName"
/>
<span>Weekends cannot be selected; underlined cells mark the first day</span>
</HuiSpace>
</template>
<style scoped>
:deep(.date-panel-mark) {
text-decoration: underline;
text-decoration-color: var(--hui-color-warning);
text-decoration-thickness: 3px;
text-underline-offset: 4px;
}
</style>
First day of the week
Values 1–7 represent Monday through Sunday; 0 also means Sunday. Invalid values use Sunday. Changing this updates both weekday labels and leading date cells.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSelect, HuiSpace } from '@nscode/handy-ui'
const firstDay = ref(7)
const options = [1, 2, 3, 4, 5, 6, 7].map((value) => ({ value, label: 'First day = ' + value }))
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSelect v-model="firstDay" :options="options" style="width: 180px" />
<HuiDatePickerPanel :first-day-of-week="firstDay" default-view-date="2024-01-01" />
</HuiSpace>
</template>
Today button
show-today applies to date mode. Today emits the start of the current local day; the button is disabled when today cannot be selected.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const shown = ref<DatePickerPanelValue>(null)
const hidden = ref<DatePickerPanelValue>(null)
</script>
<template>
<HuiSpace wrap align="start">
<HuiSpace direction="vertical" align="start">
<span>showToday = true</span>
<HuiDatePickerPanel v-model="shown" />
</HuiSpace>
<HuiSpace direction="vertical" align="start">
<span>showToday = false</span>
<HuiDatePickerPanel v-model="hidden" :show-today="false" />
</HuiSpace>
</HuiSpace>
</template>
Disabled selection with navigation
disabled prevents only final-granularity selections and hides Today. In date mode, open the month or year view from the header and use its cells to return to the date grid. Month mode still allows choosing a year for navigation, while its final month cells remain disabled. disabled-date rules remain effective. Keyboard view changes focus a cell in the new view, or a header navigation button when no final cell is focusable.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const disabled = ref(true)
const value = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace
><HuiSwitch v-model="disabled" /><span>disabled = {{ disabled }}</span></HuiSpace
>
<HuiDatePickerPanel v-model="value" :disabled="disabled" />
</HuiSpace>
</template>
Borders and a record card
The border is enabled by default. Use border=false inside a card to avoid an extra frame; the adjacent content follows the selected day.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiCard, HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const bordered = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
const value = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
const day = computed(() => (value.value instanceof Date ? value.value.toLocaleDateString() : ''))
</script>
<template>
<HuiSpace wrap align="start">
<HuiSpace direction="vertical" align="start">
<span>border = true</span>
<HuiDatePickerPanel v-model="bordered" />
</HuiSpace>
<HuiCard header="Daily records" style="max-width: 100%">
<HuiSpace wrap align="start">
<HuiDatePickerPanel v-model="value" :border="false" />
<HuiSpace direction="vertical" align="start">
<strong>{{ day }}</strong>
<span>09:00 Project check-in</span>
<span>14:00 Review selected records</span>
</HuiSpace>
</HuiSpace>
</HuiCard>
</HuiSpace>
</template>
Focus method and view events
focus() focuses the current view’s tab stop. Arrow keys move between cells; Enter or Space selects. The page displays all three panelChange arguments.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiDatePickerPanel, HuiSpace } from '@nscode/handy-ui'
import type {
DatePickerPanelExpose,
DatePickerPanelValue,
DatePickerPanelView
} from '@nscode/handy-ui'
const panel = ref<DatePickerPanelExpose>()
const value = ref<DatePickerPanelValue>(new Date(2024, 0, 15))
const event = ref('No view event yet')
const onPanelChange = (date: Date, mode: 'year' | 'month', view: DatePickerPanelView) => {
event.value = date.toLocaleDateString() + ' / ' + mode + ' / ' + view
}
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiButton @click="panel?.focus()">Focus a date cell</HuiButton>
<HuiDatePickerPanel ref="panel" v-model="value" @panel-change="onPanelChange" />
<output>{{ event }}</output>
</HuiSpace>
</template>
Form readonly and disabled input groups
Disabled state follows Form and InputGroup. A readonly Form prevents selection; FormItem readonly=false allows an individual field, while Form disabled remains effective. FormItem labels and errors are linked through ARIA, and actual model changes trigger change validation.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import {
HuiDatePickerPanel,
HuiForm,
HuiFormItem,
HuiInputGroup,
HuiSpace,
HuiSwitch
} from '@nscode/handy-ui'
import type { DatePickerPanelValue } from '@nscode/handy-ui'
const readonly = ref(true)
const groupDisabled = ref(true)
const model = reactive({
day: null as DatePickerPanelValue,
editable: null as DatePickerPanelValue
})
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace
><HuiSwitch v-model="readonly" /><span>Form readonly = {{ readonly }}</span></HuiSpace
>
<HuiForm :model="model" :readonly="readonly" label-position="top">
<HuiFormItem
label="Inherited readonly"
prop="day"
:rules="[{ required: true, message: 'Select a date', trigger: 'change' }]"
>
<HuiDatePickerPanel v-model="model.day" />
</HuiFormItem>
<HuiFormItem label="FormItem readonly=false" prop="editable" :readonly="false">
<HuiDatePickerPanel v-model="model.editable" />
</HuiFormItem>
</HuiForm>
<HuiSpace
><HuiSwitch v-model="groupDisabled" /><span
>InputGroup disabled = {{ groupDisabled }}</span
></HuiSpace
>
<HuiInputGroup :disabled="groupDisabled">
<HuiDatePickerPanel aria-label="Date in an input group" />
</HuiInputGroup>
</HuiSpace>
</template>
Validation on leaving the panel
Moving between cells and header controls stays inside one field. Blur validation runs only when focus leaves the whole panel. validate-event=false disables automatic change and blur validation; manual Form validation remains available.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import {
HuiButton,
HuiDatePickerPanel,
HuiForm,
HuiFormItem,
HuiSpace,
HuiSwitch
} from '@nscode/handy-ui'
import type { DatePickerPanelExpose, DatePickerPanelValue } from '@nscode/handy-ui'
const model = reactive({ day: null as DatePickerPanelValue })
const validateEvent = ref(true)
const panel = ref<DatePickerPanelExpose>()
const result = ref('Focus the panel, then move to the outside button.')
const onValidate = (prop: string, valid: boolean) => {
result.value = prop + ': ' + (valid ? 'Valid' : 'Choose a date')
}
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<HuiSwitch v-model="validateEvent" /><span>validateEvent = {{ validateEvent }}</span>
<HuiButton @click="panel?.focus()">Focus panel</HuiButton>
</HuiSpace>
<HuiForm :model="model" label-position="top" @validate="onValidate">
<HuiFormItem
label="Date"
prop="day"
:rules="[{ required: true, message: 'Choose a date', trigger: 'blur' }]"
>
<HuiDatePickerPanel
ref="panel"
v-model="model.day"
:validate-event="validateEvent"
default-view-date="2024-01-01"
/>
</HuiFormItem>
</HuiForm>
<HuiButton>Move focus outside the panel</HuiButton>
<output>{{ result }}</output>
</HuiSpace>
</template>
Internal state and controlled updates
Omitting modelValue stores the selection from null, including listener-only usage. A supplied prop, even undefined or null, stays controlled. Rejected requests preserve the parent selection. Date, month and year modes, highlighting, ARIA and form validation use the actual value. Removing the prop restores internal state; mode changes warn in development. Existing same-value, navigation and format rules still apply.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiDatePickerPanel, HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { DatePickerPanelType, DatePickerPanelValue } from '@nscode/handy-ui'
const q1Redraw = ref(0)
const q1Last = ref('No request')
const q1Type = ref<DatePickerPanelType>('date')
const q1Types: DatePickerPanelType[] = ['date', 'month', 'year']
const q1Model = ref<DatePickerPanelValue>(null)
const q1ChangeType = (type: DatePickerPanelType) => {
q1Type.value = type
q1Model.value = null
}
</script>
<template>
<HuiSpace class="date-picker-panel-q1-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiButton
v-for="kind in q1Types"
:key="kind"
:class="'q1-mode-' + kind"
@click="q1ChangeType(kind)"
>{{ kind }}</HuiButton
>
<HuiButton class="q1-redraw" @click="q1Redraw++">Parent render {{ q1Redraw }}</HuiButton>
</HuiSpace>
<div
style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 16px;
"
>
<div class="q1-local">
<p>Omitted prop</p>
<HuiDatePickerPanel
:type="q1Type"
default-view-date="2024-01-01"
value-format="YYYY-MM-DD"
/>
</div>
<div class="q1-listener">
<p>Update listener only</p>
<HuiDatePickerPanel
:type="q1Type"
default-view-date="2024-01-01"
value-format="YYYY-MM-DD"
@update:model-value="q1Last = String($event)"
/>
</div>
<div class="q1-empty">
<p>Explicit undefined remains empty</p>
<HuiDatePickerPanel
:type="q1Type"
default-view-date="2024-01-01"
value-format="YYYY-MM-DD"
:model-value="undefined"
/>
</div>
<div class="q1-fixed">
<p>Parent rejects updates</p>
<HuiDatePickerPanel
:type="q1Type"
default-view-date="2024-01-01"
value-format="YYYY-MM-DD"
model-value="2024-01-15"
/>
</div>
<div class="q1-bound">
<p>Two-way binding</p>
<HuiDatePickerPanel
:type="q1Type"
default-view-date="2024-01-01"
value-format="YYYY-MM-DD"
v-model="q1Model"
/>
</div>
</div>
<p class="q1-notification">Bound value: {{ q1Model }};Latest request: {{ q1Last }}</p>
</HuiSpace>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| modelValue / v-model | DatePickerPanelValue | undefined | Supplied props are controlled, including undefined/null; omitted props save a selection from null |
| type | DatePickerPanelType | 'date' | date, month or year |
| valueFormat | string | — | Emit Date without a format; x emits millisecond numbers, X emits second numbers, and other formats emit strings |
| disabledDate | (date: Date) => boolean | — | Return true to disable a date |
| cellClassName | (date: Date) => string | — | Custom class for a date cell |
| firstDayOfWeek | number | 7 | 1–7 mean Monday–Sunday; 0 also means Sunday |
| showToday | boolean | true | Show Today in date mode; hidden when disabled |
| defaultViewDate | Date | string | — | Initial month: selected value, then this fallback, then current month |
| disabled | boolean | false | Prevent selection but allow navigation; inherit disabled and form readonly state |
| border | boolean | true | Show an outer border |
| validateEvent | boolean | true | Run automatic form-item validation on value changes and when focus leaves the whole panel |
Events
| Event | Payload | Description |
|---|---|---|
| update:modelValue | (value: DatePickerPanelValue) | On every valid selection, including the current value |
| change | (value: DatePickerPanelValue) | When the value changes at date/month/year precision |
| panelChange | (date: Date, mode: 'year' | 'month', view: DatePickerPanelView) | After navigation or selecting a year/month to change the view |
The public navigation event is declared and emitted as panelChange. Vue templates can still use @panel-change; render functions use onPanelChange. Only the new declared event is emitted. Its Date, mode and view arguments are forwarded unchanged, including when valueFormat formats the selected value; navigating does not select a date.
Slots
No public slots. Use cellClassName to mark date cells.
Methods
| Method | Signature | Description |
|---|---|---|
| focus | () => void | Focus the current view’s cell tab stop; when selection is disabled and no cell is focusable, focus header navigation |
Types
Public method refs use DatePickerPanelExpose. The old DatePickerPanelInstance name remains a deprecated direct alias until 1.0; methods, arguments, and return values are unchanged.
import type {
DatePickerPanelProps,
DatePickerPanelEmits,
DatePickerPanelType,
DatePickerPanelValue,
DatePickerPanelView,
DatePickerPanelExpose
} from '@nscode/handy-ui'
type DatePickerPanelType = 'date' | 'month' | 'year'
type DatePickerPanelValue = Date | string | number | null
type DatePickerPanelView = 'year' | 'month' | 'date'
interface DatePickerPanelExpose {
focus: () => void
}
/** @deprecated 请使用DatePickerPanelExpose,将在1.0移除。 */
type DatePickerPanelInstance = DatePickerPanelExpose