Date Picker
由 Popover 与 Calendar 组合而成的日期选择器,支持单选、多选与日期范围选择。
将 Popover 与 Calendar 组合而成的日期选择器,支持单选、多选与日期范围选择,并保留独立的弹层开关、选中值与展示月份受控能力。本页示例采用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<proto-ui-shadcn-date-picker-root id="dp-shadcn">
<proto-ui-shadcn-date-picker-trigger class="w-56">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn');
setElementProps(root, {
defaultMonth: '2026-10',
today: '2026-10-15',
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'Pick a date' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>将于 0.3.0-rc.1 及后续版本中提供。Date Picker 由 Popover 与 Calendar 组合构成,直接从工作区导入对应部件即可使用。
import { ShadcnDatePickerRoot, ShadcnDatePickerTrigger, ShadcnDatePickerValue, ShadcnDatePickerContent, ShadcnDatePickerDay, ShadcnCalendarCaption, ShadcnCalendarPrevious, ShadcnCalendarHeading, ShadcnCalendarNext, ShadcnCalendarGrid, ShadcnCalendarWeekdays, ShadcnCalendarWeekday, ShadcnCalendarRow,} from '../proto-ui/components/react';
export function DatePickerExample() { return ( <ShadcnDatePickerRoot defaultMonth="2026-10" styleProfile="rhea"> <ShadcnDatePickerTrigger className="w-56"> <ShadcnDatePickerValue placeholder="Pick a date" /> <span aria-hidden="true">▾</span> </ShadcnDatePickerTrigger> <ShadcnDatePickerContent side="bottom" align="start" sideOffset={6}> <ShadcnCalendarCaption> <ShadcnCalendarPrevious a11yLabel="Previous month">‹</ShadcnCalendarPrevious> <ShadcnCalendarHeading /> <ShadcnCalendarNext a11yLabel="Next month">›</ShadcnCalendarNext> </ShadcnCalendarCaption> <ShadcnCalendarGrid> <ShadcnCalendarWeekdays> {[0, 1, 2, 3, 4, 5, 6].map((offset) => ( <ShadcnCalendarWeekday key={offset} offset={offset} /> ))} </ShadcnCalendarWeekdays> {[0, 1, 2, 3, 4, 5].map((row) => ( <ShadcnCalendarRow key={row} index={row}> {[0, 1, 2, 3, 4, 5, 6].map((col) => ( <ShadcnDatePickerDay key={col} offset={row * 7 + col} /> ))} </ShadcnCalendarRow> ))} </ShadcnCalendarGrid> </ShadcnDatePickerContent> </ShadcnDatePickerRoot> );}DatePickerRoot├── DatePickerTrigger│ └── DatePickerValue└── DatePickerContent ├── CalendarCaption │ ├── CalendarPrevious │ ├── CalendarHeading │ └── CalendarNext └── CalendarGrid ├── CalendarWeekdays -> CalendarWeekday (0..6) └── CalendarRow (0..5) -> DatePickerDay (0..41)选择模式与关闭时机
Section titled “选择模式与关闭时机”- 单选与范围模式:
mode="single"在接受选中日期后请求关闭弹层;mode="range"在选中起点时保持弹层打开,选中第二个端点并形成完整范围后自动请求关闭。受控模式下若本次选择被拒绝或尚未采纳,弹层保持打开。 - 多选模式:
mode="multiple"每次切换日期后保持弹层打开,方便连续选择,完成后通过点击外部或按Escape关闭。 - 显示值(
Value):空值时显示placeholder并自动套用 muted 占位色;单选显示YYYY-MM-DD,多选显示按日期排序的逗号列表,范围未完成时显示from …,完成后显示from – to。 - 键盘与无障碍:弹层焦点恢复与外部关闭由
Popover管理,网格方向键导航、不可用日期跳过与本地化朗读由 Calendar 管理。
带标签与起止日期范围限制的单日选择器。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<span class="text-sm font-medium">Date</span>
<proto-ui-shadcn-date-picker-root id="dp-shadcn-basic">
<proto-ui-shadcn-date-picker-trigger class="w-56">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn-basic');
setElementProps(root, {
defaultMonth: '2026-10',
defaultValue: '2026-10-15',
min: '2026-10-01',
max: '2026-11-30',
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'Pick a date' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>通过 mode="range" 搭配 defaultRange、minNights、maxNights 与 unavailable 选择起止日期范围。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<span class="text-sm font-medium">Date Picker Range</span>
<proto-ui-shadcn-date-picker-root id="dp-shadcn-range">
<proto-ui-shadcn-date-picker-trigger class="w-64">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn-range');
setElementProps(root, {
mode: 'range',
defaultMonth: '2026-10',
defaultRange: { from: '2026-10-10', to: '2026-10-16' },
unavailable: ['2026-10-18'],
minNights: 1,
maxNights: 14,
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'Pick a date range' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>多选与禁用状态
Section titled “多选与禁用状态”mode="multiple" 支持连续勾选多个日期并限制上限(maxSelected),右侧展示 disabled 禁用态触发器。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<span class="text-sm font-medium">Multiple Dates</span>
<proto-ui-shadcn-date-picker-root id="dp-shadcn-multiple">
<proto-ui-shadcn-date-picker-trigger class="w-64">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn-multiple');
setElementProps(root, {
mode: 'multiple',
defaultMonth: '2026-10',
defaultValues: ['2026-10-05', '2026-10-12'],
maxSelected: 4,
unavailable: ['2026-10-18', '2026-10-19'],
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'Pick dates' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>范围与多选对比
Section titled “范围与多选对比”同时对比 mode="range" 与 mode="multiple" 在同一日期约束下的交互与关闭时机。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<span class="text-sm font-medium">
Date Range & Multiple Dates
</span>
<proto-ui-shadcn-date-picker-root id="dp-shadcn-selection">
<proto-ui-shadcn-date-picker-trigger class="w-64">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn-selection');
setElementProps(root, {
mode: 'range',
defaultMonth: '2026-10',
defaultRange: { from: '2026-10-10', to: '2026-10-14' },
unavailable: ['2026-10-18'],
minNights: 1,
maxNights: 14,
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'Pick dates' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>RTL 与本地化
Section titled “RTL 与本地化”通过 direction="rtl" 与 locale="ar-SA" 切换从右到左的布局方向与本地化月份/星期文案。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-col items-start gap-2">
<span class="text-sm font-medium">
تاريخ الموعد (RTL · ar-SA)
</span>
<proto-ui-shadcn-date-picker-root id="dp-shadcn-rtl">
<proto-ui-shadcn-date-picker-trigger class="w-56">
<proto-ui-shadcn-date-picker-value></proto-ui-shadcn-date-picker-value>
<span aria-hidden="true">▾</span>
</proto-ui-shadcn-date-picker-trigger>
<proto-ui-shadcn-date-picker-content>
<proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-previous>
‹
</proto-ui-shadcn-calendar-previous>
<proto-ui-shadcn-calendar-heading></proto-ui-shadcn-calendar-heading>
<proto-ui-shadcn-calendar-next>
›
</proto-ui-shadcn-calendar-next>
</proto-ui-shadcn-calendar-caption>
<proto-ui-shadcn-calendar-grid>
<proto-ui-shadcn-calendar-weekdays></proto-ui-shadcn-calendar-weekdays>
</proto-ui-shadcn-calendar-grid>
</proto-ui-shadcn-date-picker-content>
</proto-ui-shadcn-date-picker-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#dp-shadcn-rtl');
setElementProps(root, {
defaultMonth: '2026-10',
locale: 'ar-SA',
direction: 'rtl',
styleProfile: 'rhea',
});
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-value'),
{ placeholder: 'اختر تاريخًا' }
);
setElementProps(
root.querySelector('proto-ui-shadcn-date-picker-content'),
{ side: 'bottom', align: 'start', sideOffset: 6 }
);
const weekdays = root.querySelector(
'proto-ui-shadcn-calendar-weekdays'
);
for (let offset = 0; offset < 7; offset++) {
const cell = document.createElement(
'proto-ui-shadcn-calendar-weekday'
);
setElementProps(cell, { offset });
weekdays.append(cell);
}
const grid = root.querySelector('proto-ui-shadcn-calendar-grid');
for (let rowIndex = 0; rowIndex < 6; rowIndex++) {
const row = document.createElement(
'proto-ui-shadcn-calendar-row'
);
setElementProps(row, { index: rowIndex });
for (let col = 0; col < 7; col++) {
const day = document.createElement(
'proto-ui-shadcn-date-picker-day'
);
setElementProps(day, { offset: rowIndex * 7 + col });
row.append(day);
}
grid.append(row);
}
</script>Date Picker 由 DatePickerRoot、DatePickerTrigger、DatePickerValue、DatePickerContent 与 DatePickerDay 组成,弹层内复用 Calendar 的标题、月份导航与星期网格部件。
| 属性 | 类型 | 默认值 |
|---|---|---|
mode | 'single' 'multiple' 'range' | 'single' |
open / defaultOpen | boolean | false |
value / defaultValue | string (YYYY-MM-DD) | '' |
values / defaultValues | readonly string[] | [] |
range / defaultRange | { from?: string; to?: string } | {} |
month / defaultMonth | string (YYYY-MM) | 当前月 |
min / max | string (YYYY-MM-DD) | — |
unavailable | readonly string[] | [] |
minSelected / maxSelected | number | — |
minNights / maxNights | number | — |
locale | string | 'en-US' |
direction | 'ltr' 'rtl' | 'ltr' |
disabled / readOnly | boolean | false |
side / align / sideOffset | PopoverContentProps | 'bottom' / 'center' / 4 |
placeholder (Value) | string | 'Pick a date' |
styleProfile | 'vega' 'nova' 'maia' 'lyra' 'mira' 'luma' 'sera' 'rhea' 'new-york-v4' | 'nova' |