Component

Date picker

安装 Installation

npx timkit add date-picker --yes --framework react

用法 Usage

import { DatePicker } from "@/components/ui/date-picker"

className 与 variant、size 可以一起用。字段以 timkit agent inspect date-picker --json 的 props 为准。

示例

Examples

一次看一个示例。左侧按名称筛选,预览里可切换源码和框架。

4 / 4

Calendar Date Picker · Pattern 25

Loading preview...

结构化 API

Structured API

与 UCS schema 对齐的 props、逻辑机与多框架运行时。

Component

date-picker

Logic

zag / date-picker

Runtime Frameworks

ReactVueWeappHTML

Supported Platforms

WebWeChat Mini Program

Configuration

PropTypeDefaultDescription
logic.provider*
enum (zag | native | none)
zagState and interaction provider used by this component.
logic.machine
string
date-pickerUnderlying state machine identifier when provider is zag.
platforms*
array
Web, WeChat Mini ProgramPlatforms officially supported by this schema.
frameworks*
array
React, Vue, Weapp, HTMLFramework demos/code currently available in registry files.
dependencies
array
@timui/core, @zag-js/popper, @zag-js/reactRuntime package dependencies required by this registry item.
optionalPeerDependencies
array
@internationalized/dateOptional peer dependencies used by this registry item.
registryDependencies
array
calendar, popover, buttonDependent Timkit registry components/hook entries.

Props

PropTypeDefaultDescription
mode
enum (single | range)
singleThe selection mode.
numberOfMonths
number
1The number of months to display.
value
array
-The controlled selected dates.
placeholder
string
-The button placeholder.
disabled
boolean
falseWhen true, opening and date changes are ignored.
readOnly
boolean
falseWhen true, the calendar can be opened and days can be focused, but selection does not change.
required
boolean
falseWhen true, the date picker is announced as required.
open
boolean
-The controlled open state of the calendar.
defaultOpen
boolean
-The default open state of the calendar when uncontrolled.

Events

PropTypeDefaultDescription
onValueChange
event
-Event handler called when the selected dates change.
onOpenChange
event
-Event handler called when the calendar open state changes.

TypeScript

来自 TypeScript 导出。

PropTypeDefaultDescription
id
string
-A unique identifier for the component.
modelValue
DatePickerVueValue | null
-The controlled value bound via `v-model` (Vue specific).
defaultValue
DatePickerVueValue
-The default value of the component when uncontrolled.
minDate
Date
-The minimum allowed date.
maxDate
Date
-The maximum allowed date.
locale
string
-BCP 47 locale used for parsing/formatting date labels.
name
string
-The name of the hidden input when used in a form.
isDateUnavailable
event
-Callback to determine whether a given date should be marked as unselectable.

Slots

PropTypeDefaultDescription
default
slot
-Default slot content rendered inside the component root.

Parts

PropTypeDefaultDescription
root*
root
-The date picker container
trigger
part
-The toggle button
content
part
-The calendar popover content
This API reference is generated from `/packages/core` component schemas to keep React/Vue/Weapp docs consistent.

该组件尚无扩展说明文档。

键盘与焦点

Keyboard

跨 React、Vue 与小程序共享的交互与可读名称约定。

  • Enter or Space opens the calendar.
  • The trigger is named Open calendar or Close calendar.
  • The selected day is visible as YYYY-MM-DD.
  • Several selected days are separated by to.
  • An empty value has no day status.
  • Escape closes it and returns focus to the trigger.
  • ArrowRight moves the focused day.
  • ArrowDown moves to the same weekday in the next week.
  • ArrowUp moves to the same weekday in the previous week.
  • Home moves to the first day of the visible month.
  • End moves to the last.
  • PageUp moves to the previous month.
  • PageDown moves to the next month.
  • Shift with PageUp moves to the previous year.
  • Shift with PageDown moves to the next year.
  • None of these keys selects a day.
  • Enter selects the focused day.
  • Enter or Space on Switch to previous month and Switch to next month changes the month.
  • The picker stays open after a selection.
  • The trigger controls the popup.
  • The popup is an application.
  • In static HTML, that popup uses tabindex -1.
  • On the mini program, aria-controls is set only while the popup is open.
  • On the mini program, the open popup and the month grid use tabindex -1.
  • On the mini program, the open popup sets aria-disabled and aria-readonly.
  • On the mini program, the month grid inside the popup sets aria-disabled and aria-readonly.
  • On the mini program, that month grid is described as calendar month.
  • A range picker sets aria-multiselectable.
  • Each row sets aria-disabled when the picker is disabled.
  • In static HTML, the trigger is a button.
  • When read-only, the calendar can still be opened and focused, but selection does not change.
  • A disabled calendar ignores those keys.
  • The visible month names the grid.
  • Weekday names are column headers.
  • Each week is a row.
  • Month buttons sit outside the grid.
  • Each day is named with its full date.
  • Each day exposes whether it is selected.
  • The focused day is in the tab order.
  • The other days are not.
  • A disabled calendar leaves the days and the month buttons out of the tab order.
  • A disabled day is not in the tab order.

行为契约

Contract

props、默认值和运行时状态。

  • Single mode keeps one day.
  • Range mode keeps a start and an end, and the trigger shows both.
  • A disabled or read-only picker ignores selection.
  • Month changes stop at startMonth and endMonth.
  • A required picker is announced as required.