Calendar
从月份网格中选择一个日期、多个日期或一个范围。
Calendar 直接在页面上显示日期。它适合预订流程、日程,或任何需要让日期始终可见的地方。对于会打开日历的文本字段,请使用 Date Picker。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar defaultValue="2026-10-16">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }安装
npm install @ui-sdk/react @ui-sdk/core组合
用下面的组合构建 Calendar:
Calendar
├── CalendarPrevious
├── CalendarHeading
├── CalendarNext
└── CalendarGrid
├── CalendarWeekdays
│ └── CalendarWeekday
└── CalendarWeeks
└── CalendarDay标题为显示的月份命名。Previous 和 Next 切换它,网格容纳星期表头和日期。星期和周辅助函数渲染表格结构,而每个表头和日期由你渲染。
空的 Calendar 渲染默认结构,空的 CalendarGrid 渲染它的表头和周。写出各个部件,以添加你的类名和内容。每个网格以它的月份命名,并带有 grid 角色。
用法
导入部件并把它们组合起来:
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
function Example() {
return (
<Calendar defaultValue="2026-10-16">
<CalendarPrevious />
<CalendarHeading />
<CalendarNext />
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }值
日期是 "2026-10-16" 这样的 ISO 字符串,不带时间和时区。不需要日期库。日期辅助函数负责运算;Intl 负责格式化名称和标签。
| 模式 | 值 |
|---|---|
"single"(默认) | 一个日期字符串或 null。 |
"multiple" | 排好序的日期字符串数组。 |
"range" | [start, end] 或 null。 |
值的形状与它的模式不符时,会被当作没有选择。
范围
mode="range" 先选择开始,再选择结束。移动指针或焦点会预览这个范围;两端都选好后值才会改变。早于开始的日期也会结束它,并成为新的开始。Escape 取消未完成的范围。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar
mode="range"
months={2}
monthFormat="short"
defaultValue={["2026-10-12", "2026-10-16"]}
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<div data-slot="row">
<CalendarGrid offset={0}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
<CalendarGrid offset={1}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</div>
</Calendar>
)
}
export { Example }多选
mode="multiple" 独立切换每个日期。它的值是排好序的数组,即使日期是按其他顺序选择的。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
import * as React from "react"
function Example() {
const [dates, setDates] = React.useState<string[]>([
"2026-10-07",
"2026-10-16",
"2026-10-26",
])
return (
<div>
<Calendar
mode="multiple"
value={dates}
onValueChange={(value) => setDates(value as string[])}
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
</div>
)
}
export { Example }不可用的日期
unavailable 接受一个日期、{ from, to }、表示周末的 { weekday: [0, 6] }、{ before }、{ after }、一个判定函数,或这些匹配器的数组。星期零是周日。
不可用的日期不能被选择,但保持可聚焦,让键盘和屏幕阅读器用户可以发现它们。它们暴露 aria-disabled 和 data-unavailable。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
const unavailable = [
"2026-10-08",
{ from: "2026-10-20", to: "2026-10-23" },
{ weekday: [0, 6] },
]
function Example() {
return (
<Calendar unavailable={unavailable}>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }取消选择
deselectable 在单选模式下允许再次按压选中的日期来清除它。不设置时,再次按压会保持该日期选中。
最小与最大
min 和 max 设置最早和最晚的可选日期。超出这些边界的日期无法获得焦点。方向键在边界处停下,Previous 和 Next 在各自的月份停下。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar defaultValue="2026-10-16" min="2026-10-05" max="2026-11-20">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }禁用与只读
disabled 阻止焦点、选择和月份导航。readOnly 允许导航,以便查看日期,但保持选中的值不变。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar disabled defaultValue="2026-10-16">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar readOnly defaultValue="2026-10-16">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }两个月
把 months 设为 2,并渲染偏移为 0 和 1 的网格。方向键在各个网格之间移动,不会翻页。另一个可见月份已经显示的日期会留下空单元格,所以每个日期只出现一次。
pageBy="page" 让 Previous、Next 以及超出可见网格的导航按完整的月份数移动。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar
months={2}
pageBy="page"
monthFormat="short"
defaultValue="2026-10-16"
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<div data-slot="row">
<CalendarGrid offset={0}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
<CalendarGrid offset={1}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</div>
</Calendar>
)
}
export { Example }固定周数
fixedWeeks 让每个月都渲染六行周。把 showOutsideDays 设为 false,相邻月份的日期会留空。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar fixedWeeks showOutsideDays={false} defaultMonth="2026-02">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }月份与年份选择器
CalendarMonthSelect 和 CalendarYearSelect 是原生选择器,用于直接跳到某个日期,比如生日。年份选项从 min 到 max,边界缺失时是当前显示年份前后各十年。超出边界的月份被禁用。
它们用 select-change 原因更新第一个显示的月份。如果你想渲染不同的选择器,它们的状态会暴露选项。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarMonthSelect,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
CalendarYearSelect,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar defaultMonth="1990-06" min="1920-01-01" max="2026-10-16">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<div data-slot="row">
<CalendarMonthSelect />
<CalendarYearSelect />
</div>
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }自定义月份与年份选择器
月份和年份选择器是原生 select 元素。要使用自己的选择器,控制日历的 month,并让你的选择器的值驱动它,就像这里的 Select 组件那样。在日历里保留一个 CalendarHeading,如果你想,可以让它视觉隐藏,这样月份变化仍会被播报。每个网格会为自己命名。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import {
Select,
SelectContent,
SelectItem,
SelectItemIndicator,
SelectTrigger,
SelectValue,
} from "@ui-sdk/react/select"
import { CheckIcon, ChevronDownIcon } from "lucide-react"
import * as React from "react"
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
].map((label, index) => ({ value: String(index + 1).padStart(2, "0"), label }))
const years = ["2024", "2025", "2026", "2027", "2028"].map((year) => ({
value: year,
label: year,
}))
function Example() {
const [month, setMonth] = React.useState("2026-10")
const [year, monthOfYear] = month.split("-")
return (
<Calendar
month={month}
onMonthChange={setMonth}
defaultValue="2026-10-16"
min="2024-01-01"
max="2028-12-31"
>
<div data-slot="row">
<CalendarHeading />
<Select
items={months}
value={monthOfYear}
onValueChange={(next) => next && setMonth(`${year}-${next}`)}
>
<SelectTrigger aria-label="Month">
<SelectValue />
<ChevronDownIcon />
</SelectTrigger>
<SelectContent>
{months.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
<SelectItemIndicator>
<CheckIcon />
</SelectItemIndicator>
</SelectItem>
))}
</SelectContent>
</Select>
<Select
items={years}
value={year}
onValueChange={(next) => next && setMonth(`${next}-${monthOfYear}`)}
>
<SelectTrigger aria-label="Year">
<SelectValue />
<ChevronDownIcon />
</SelectTrigger>
<SelectContent>
{years.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
<SelectItemIndicator>
<CheckIcon />
</SelectItemIndicator>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }语言
locale 控制月份名称、星期表头和完整的日期标签。省略它时,Calendar 在挂载后读取周围页面的 lang,并以浏览器语言作为回退。服务端和客户端的初始渲染都使用英文,所以它们总是一致。一周的第一天跟随 locale,因此也会在挂载后变化,除非由 weekStartsOn 指定。weekdayFormat 接受 "narrow"、"short" 或 "long"。
Previous 和 Next 的名称为“Previous month”和“Next month”。传入 aria-label 可以用另一种语言命名它们。日期仍是公历。本地化的年份体系,比如佛历或日本年号,仍然可以出现在标签里。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar
locale="de-DE"
weekStartsOn={1}
weekdayFormat="narrow"
defaultValue="2026-10-16"
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }名称格式
用 weekdayFormat 设置星期表头,用 monthFormat 设置标题和月份选择器。两者都接受 "narrow"、"short" 或 "long",并跟随日历的 locale。屏幕阅读器仍然听到完整名称:网格和每个日期保留它们的长标签。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar
months={2}
pageBy="page"
defaultValue="2026-10-16"
weekdayFormat="narrow"
monthFormat="short"
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<div data-slot="row">
<CalendarGrid offset={0}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
<CalendarGrid offset={1}>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</div>
</Calendar>
)
}
export { Example }自定义日期
日期的 children 接收它的状态,包括日期、标签、选择情况,以及它是否在月份之外。这个示例在每天下面加一个价格。星期表头也可以有自定义内容。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
const priceOf = (date: string) => 80 + ((Number(date.slice(8)) * 7) % 5) * 10
function Example() {
return (
<Calendar today="2026-10-16" defaultValue="2026-10-16">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => (
<CalendarWeekday index={index}>
{(state) => (
<abbr
title={state.name}
data-weekend={
state.weekday === 0 || state.weekday === 6 || undefined
}
>
{state.label}
</abbr>
)}
</CalendarWeekday>
)}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => (
<CalendarDay value={cell.date}>
{(state) => (
<span data-slot="stack">
<span>{state.label}</span>
{!state.outside && !state.disabled && (
<span data-slot="hint">${priceOf(state.date)}</span>
)}
</span>
)}
</CalendarDay>
)}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }范围限制
minDays 和 maxDays 两端都计入。三天的范围包括开始、中间的一天和结束。会破坏限制的按压会保留开始,以便另选一个结束。在那之前,不能作为范围结束的日期被禁用。
除非设置 allowUnavailable,范围不能包含不可用的日期。它会允许两端之间存在不可用的日期;它们仍然不能被选为端点。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<Calendar
mode="range"
minDays={3}
maxDays={8}
unavailable={{ from: "2026-10-17", to: "2026-10-18" }}
allowUnavailable
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
)
}
export { Example }进行中的范围
根部件的状态有 anchor,即正在挑选结束日期时的开始,以及 focused,即拥有 Tab 停靠点的日期。onAnchorChange 和 onFocusedChange 在它们改变之前报告,用于在日历之外显示正在挑选的范围,取消其中任何一个都会让状态保持原样。因为月份翻动而获得焦点的日期不会报告。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
import * as React from "react"
import { useLog } from "./log"
function Example() {
const log = useLog()
return (
<div>
<Calendar
mode="range"
onAnchorChange={(anchor) =>
log(anchor ? `Started on ${anchor}` : "Range finished")
}
onFocusedChange={(focused) => log(`Focus on ${focused}`)}
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
</div>
)
}
export { Example }受控
选择和显示的月份是分开的。value 使用所选模式对应的形状;month 指定第一个显示的月份,比如 "2026-10"。
用 value 配合 onValueChange、month 配合 onMonthChange 来控制它们。用 defaultValue 和 defaultMonth 设置初始状态。变更详情包含原因;details.cancel() 拒绝这次变更。状态与事件介绍了绑定模式,原因表列出了 Calendar 的原因。
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
type CalendarValue,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
import * as React from "react"
import { useLog } from "./log"
export function Example() {
const [value, setValue] = React.useState<CalendarValue>("2026-10-16")
const [month, setMonth] = React.useState("2026-10")
const log = useLog()
return (
<div>
<Calendar
value={value}
onValueChange={(next, details) => {
setValue(next)
log(`Selected ${String(next)} (${details.reason})`)
}}
month={month}
onMonthChange={(next, details) => {
setMonth(next)
log(`Showing ${next} (${details.reason})`)
}}
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
</div>
)
}今天
今天会得到 aria-current="date" 和 data-today。没有选择或起始月份时,日历打开在今天的月份。它在客户端读取今天;设置 today 可以显式固定一个日期。
timeZone 决定哪一天是今天。它不会把选中的日期转换到另一个时区。
"use client"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
return (
<div>
<Calendar timeZone="Pacific/Kiritimati">
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
<p data-slot="hint">
Today is marked as it is in Kiritimati, the first place to see each new
day.
</p>
</div>
)
}
export { Example }从任意位置驱动它
createCalendarController() 实例可以设置值、切换月份,并聚焦一个日期。聚焦另一个月份的日期会先显示那个月份。控制器介绍了设置和生命周期。
"use client"
import { todayDate } from "@ui-sdk/core/date"
import * as React from "react"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
createCalendarController,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function Example() {
const [calendar] = React.useState(() => createCalendarController())
const select = (date: string) => {
calendar.setValue(date)
calendar.focus(date)
}
return (
<div data-slot="stack">
<div data-slot="controls">
<button type="button" onClick={() => select("2026-12-25")}>
Go to Christmas
</button>
<button type="button" onClick={() => select(todayDate())}>
Today
</button>
</div>
<Calendar
controller={calendar}
defaultValue="2026-10-16"
defaultMonth="2026-10"
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
</div>
)
}
export { Example }预设
用按钮驱动范围日历,选择人们最常选的范围。每个预设通过控制器设置值,并把焦点移到它的第一天,运算使用日期辅助函数。
"use client"
import { addDays, endOfMonth, startOfMonth } from "@ui-sdk/core/date"
import * as React from "react"
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
CalendarWeekdays,
CalendarWeeks,
createCalendarController,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
const today = "2026-10-16"
const presets = [
{ label: "Last 7 Days", range: [addDays(today, -6), today] },
{ label: "This Month", range: [startOfMonth(today), endOfMonth(today)] },
{ label: "Next 30 Days", range: [today, addDays(today, 29)] },
] as const
function Example() {
const [calendar] = React.useState(() => createCalendarController())
return (
<div data-slot="stack">
<div data-slot="controls">
{presets.map((preset) => (
<button
key={preset.label}
type="button"
data-size="sm"
onClick={() => {
calendar.setValue([...preset.range])
calendar.focus(preset.range[0])
}}
>
{preset.label}
</button>
))}
</div>
<Calendar
mode="range"
controller={calendar}
today={today}
defaultMonth="2026-10"
>
<div data-slot="row">
<CalendarPrevious data-variant="ghost">
<ChevronLeftIcon aria-hidden="true" />
</CalendarPrevious>
<CalendarHeading />
<CalendarNext data-variant="ghost">
<ChevronRightIcon aria-hidden="true" />
</CalendarNext>
</div>
<CalendarGrid>
<CalendarWeekdays>
{(index) => <CalendarWeekday index={index} />}
</CalendarWeekdays>
<CalendarWeeks>
{(cell) => <CalendarDay value={cell.date} />}
</CalendarWeeks>
</CalendarGrid>
</Calendar>
</div>
)
}
export { Example }自定义渲染
需要自己写表格时,网格的状态会暴露它的月份、标签、星期和各个周。保留标记为 hidden 的空单元格,这样另一个月份显示的日期不会出现两次。部件与组合介绍了如何更换部件的元素而不丢失它的行为。
import {
Calendar,
CalendarDay,
CalendarGrid,
CalendarHeading,
CalendarNext,
CalendarPrevious,
CalendarWeekday,
} from "@ui-sdk/react/calendar"
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
function isoWeek(date: string) {
const day = new Date(`${date}T00:00:00Z`)
day.setUTCDate(day.getUTCDate() + 3 - ((day.getUTCDay() + 6) % 7))
const firstThursday = new Date(Date.UTC(day.getUTCFullYear(), 0, 4))
const days = (day.getTime() - firstThursday.getTime()) / 86400000
return 1 + Math.round((days - 3 + ((firstThursday.getUTCDay() + 6) % 7)) / 7)
}
export function Example() {
return (
<Calendar defaultValue="2026-10-16" weekStartsOn={1}>
<div data-slot="row">
<CalendarPrevious
data-variant="ghost"
render={(props, step) => (
<button {...props} title={`Show ${step.month}`} />
)}
>
<ChevronLeftIcon />
</CalendarPrevious>
<CalendarHeading>{(heading) => heading.label}</CalendarHeading>
<CalendarNext data-variant="ghost">
<ChevronRightIcon />
</CalendarNext>
</div>
<CalendarGrid>
{(grid) => (
<>
<thead>
<tr>
<th scope="col">
<abbr title="Week">Wk</abbr>
</th>
{grid.weekdays.map((weekday, index) => (
<CalendarWeekday key={weekday} index={index} />
))}
</tr>
</thead>
<tbody>
{grid.weeks.map((week) => (
<tr key={week[0]!.date}>
<th scope="row" data-slot="hint">
{isoWeek(week[0]!.date)}
</th>
{week.map((cell) =>
cell.hidden ? (
<td key={cell.date} />
) : (
<CalendarDay key={cell.date} value={cell.date} />
)
)}
</tr>
))}
</tbody>
</>
)}
</CalendarGrid>
</Calendar>
)
}样式
用 data-selected、data-today、data-outside、data-unavailable 和 data-disabled 为日期设置样式。范围还会暴露它的开始、中间、结束和未完成的预览。导航按钮到达边界时也会得到 data-disabled。
每个部件都有一个 data-slot,比如 calendar-day,它的状态属性列在数据属性下。
数据属性
Calendar
[data-slot="calendar"]
| 属性 | 含义 |
|---|---|
data-mode | singlemultiplerangeHow the calendar selects. |
data-readonly | Present when dates can be focused but not picked. |
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarPrevious
[data-slot="calendar-previous"]
| 属性 | 含义 |
|---|---|
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarNext
[data-slot="calendar-next"]
| 属性 | 含义 |
|---|---|
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarMonthSelect
[data-slot="calendar-month-select"]
| 属性 | 含义 |
|---|---|
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarYearSelect
[data-slot="calendar-year-select"]
| 属性 | 含义 |
|---|---|
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarGrid
[data-slot="calendar-grid"]
| 属性 | 含义 |
|---|---|
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
CalendarDay
[data-slot="calendar-day"]
| 属性 | 含义 |
|---|---|
data-value | 2026-10-012026-10-142026-10-162026-10-182026-10-242026-09-30A day's ISO date. |
data-selected | Present on selected days. In a range, every day from start to end. |
data-today | Present on today, beside aria-current="date". |
data-disabled | Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max. |
data-unavailable | Present on a day unavailable names. It stays focusable. |
data-outside | Present on a day of the month before or after its grid's. |
data-range-start | Present on the day a range starts, including one being picked. |
data-range-middle | Present on the days inside a range, between its ends. |
data-range-end | Present on the day a range ends, including one being picked. |
data-preview | Present on the days of a range being picked, from its start to the day under the pointer or focus. |
API 参考
属性和回调与下面相同,都作为 React props。
Calendar
mode?CalendarMode- How many dates it selects: one, any number, or a range from a start to an end.
value?CalendarValue- The selected value: an ISO date for
"single", a list for"multiple",[start, end]for"range", ornull. Pass it to control the calendar. defaultValue?CalendarValue- The value it starts with, when uncontrolled.
onValueChange?((value: CalendarValue, details: ChangeDetails<CalendarValueChangeReason>) => void)- Runs when a date is pressed (
"item-press"), with Enter or Space too, or a controller sets the value ("imperative"). A range changes once both ends are picked.details.cancel()keeps the value. month?string- The first month shown, like
"2026-10". Pass it to control the calendar. defaultMonth?string- The first month it shows, when uncontrolled. Defaults to the selected date's month, else today's.
onMonthChange?((month: ISOMonth, details: ChangeDetails<CalendarMonthChangeReason>) => void)- Runs when the months shown want to change: Previous or Next, a key moving focus to another month, a press on a day of another month, or a controller.
min?string- The earliest date that can be picked. Keys stop there, and Previous stops at its month.
max?string- The latest date that can be picked.
unavailable?DateMatchers- Dates that can't be picked, like booked days, as data: ISO dates,
{ from, to },{ weekday: [0, 6] }for weekends,{ before },{ after }, or a function. They stay focusable, so keyboard users hear them. disabled?boolean- Whether nothing can be picked or focused.
readOnly?boolean- Whether dates can be focused but not picked.
deselectable?boolean- Whether pressing the selected date again clears it, in
"single"mode. onFocusedChange?((date: ISODate, details: ChangeDetails<CalendarFocusedChangeReason>) => void)- Runs before keys, a press or
focus()move focus to another day. Canceling keeps focus where it was. onAnchorChange?((anchor: ISODate | null, details: ChangeDetails<CalendarAnchorChangeReason>) => void)- Runs before a press starts a range, or ends it or Escape drops it, with
null. Canceling keeps the start as it was. months?number- How many months show side by side, each in its own grid.
pageBy?"month" | "page"- Whether Previous, Next and keys turn one month, or all the months shown.
locale?string- The language of the names and labels. Defaults to the page's
lang, then the browser's. weekStartsOn?number- The first day of the week, 0 for Sunday. Defaults to the locale's.
weekdayFormat?"long" | "narrow" | "short"- How weekday headers are written.
monthFormat?"long" | "narrow" | "short"- How month names are written, in the heading and the month select.
fixedWeeks?boolean- Whether every month shows six weeks, so the calendar doesn't change height.
showOutsideDays?boolean- Whether the days of the months before and after show at the edges.
today?string- Today's date, for
aria-currentand the starting month. Defaults to today intimeZone, read on the client. timeZone?string- The time zone that says what day today is, like
"America/New_York". Defaults to the browser's. minDays?number- The fewest days a range can span, counting both ends.
maxDays?number- The most days a range can span, counting both ends.
allowUnavailable?boolean- Whether a range may hold unavailable dates, like a stay over a booked night.
controller?object- Drives it from anywhere. Create one with
createCalendarController(). debug?boolean- Logs every state change with its reason to the console, in development builds.
CalendarPrevious
显示上一月。渲染一个 button,在 min 处禁用。
CalendarHeading
为显示的月份命名,比如“October 2026”。渲染一个 h2,网格以它为标签,屏幕阅读器会听到它的变化。
CalendarNext
显示下一月。渲染一个 button,在 max 处禁用。
CalendarMonthSelect
按 locale 排列月份的原生 select,它更改第一个显示的月份。
CalendarYearSelect
一个原生 select,年份从 min 到 max,或显示年份前后各 10 年。
CalendarGrid
offset?number- Which of the months shown it is, from 0.
CalendarWeekdays
渲染表头行。它的 children 是一个接收每个星期索引的函数。
CalendarWeekday
indexnumber- The column, from 0.
CalendarWeeks
渲染周行。它的 children 是一个接收每个单元格及其 date 的函数。
CalendarDay
valuestring- Its ISO date.
offset?number- The offset of the grid it's in, read from that grid, so you don't pass it.
状态
每个部件的渲染函数、基于状态的类名和 children 函数会收到什么。
Calendar:
valueCalendarValue- The selected value.
monthstring- The first month shown.
modeCalendarMode- How it selects.
disabledboolean- Whether nothing can be picked or focused.
readOnlyboolean- Whether dates can be focused but not picked.
focusedstring | null- The date with the tab stop,
nulluntil days render in the browser. anchorstring | null- A range's start while its end is being picked, else
null.
CalendarHeading:
monthstring- The first month shown, to format the heading yourself.
labelstring- The months shown in
monthFormat, like "October 2026", or "October – November 2026".
CalendarMonthSelect and CalendarYearSelect:
valuenumber- The first month shown's month, 1 to 12, or its year.
optionsCalendarSelectOption[]- Every month, or the years from
mintomax(10 either side of the year shown without them). disabledboolean- Whether the calendar's
disabledoption is on. Inside a Date Picker, a disabled<fieldset>around the picker counts too.
CalendarPrevious and CalendarNext:
monthstring- The first month it shows.
disabledboolean- Whether it can't go further, past
minormax.
CalendarGrid:
monthstring- The month it shows: the first month shown, plus its
offset. labelstring- The month's name and year in
monthFormat, like "October 2026". weekdaysnumber[]- The weekday of each column, 0 for Sunday, in the order they show.
weeksCalendarGridCell[][]- The weeks, each seven cells. Render a day for each cell that isn't hidden.
CalendarWeekday:
weekdaynumber- The weekday, 0 for Sunday.
labelstring- Its name, in
weekdayFormat. namestring- Its full name, which screen readers hear.
CalendarDay:
datestring- Its ISO date.
labelstring- The day of the month in the locale's digits, like "16".
selectedboolean- Whether it's selected. In a range, every date from start to end is.
todayboolean- Whether it's the
todayoption's date, or else today intimeZone, read once the calendar runs in the browser. outsideboolean- Whether it belongs to the month before or after its grid's.
disabledboolean- Whether it can't be picked: outside
minandmax, unavailable, unable to end the range being picked, or the calendar is disabled. unavailableboolean- Whether
unavailablenames it. rangeStartboolean- Whether a range starts here, including one being picked.
rangeEndboolean- Whether a range ends here, including one being picked.
inRangeboolean- Whether it's inside a range, ends included, including one being picked.
原因
details.reason 说明值为什么变化:
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
imperativenone- A controller or
apicall.
以及月份为什么变化:
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
imperativenone- A controller or
apicall. previous-pressMouseEvent | KeyboardEvent- A pagination's or a carousel's Previous part was pressed.
next-pressMouseEvent | KeyboardEvent- A pagination's or a carousel's Next part was pressed.
list-navigationKeyboardEvent- Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or ⌘ with A selected every item of a listbox.
select-change
焦点为什么移到另一个日期:
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
imperativenone- A controller or
apicall. list-navigationKeyboardEvent- Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or ⌘ with A selected every item of a listbox.
focus-inFocusEvent- Keyboard focus moved into the component, which stops a rotating carousel, as the carousel pattern asks, or onto a canvas item, which brought it into view, or onto a calendar's day another way, like a screen reader's.
以及范围的开始为什么变化:
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
escape-keyKeyboardEvent- Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
控制器
用 createCalendarController() 创建一个,并作为 controller 传入。每个写入方法接受一个可选的 { reason, event },在变更被取消、无处可去,或日历被禁用或只读时返回 false。
getValue()() => CalendarValue- The selected value: an ISO date, a list of them, or a
[start, end]range. setValue(value, options?)(value: CalendarValue, options?: CalendarChangeOptions<CalendarValueChangeReason> | undefined) => boolean- Selects a value. Returns false when canceled, unchanged, disabled, read-only, or holding a date people can't pick, like one past
max. getMonth()() => string- The first month shown, like
"2026-10". setMonth(month, options?)(month: string, options?: CalendarChangeOptions<CalendarMonthChangeReason> | undefined) => boolean- Shows a month first. Returns false when canceled or unchanged.
previous(options?)(options?: CalendarChangeOptions<CalendarMonthChangeReason> | undefined) => boolean- Shows the months before, as the Previous part does.
next(options?)(options?: CalendarChangeOptions<CalendarMonthChangeReason> | undefined) => boolean- Shows the months after, as the Next part does.
focus(date?)(date?: string | undefined) => void- Focuses a date, turning the months to show it, or the date with the tab stop.
事件
回调先收到新值,然后收到详情。
| 属性 | 所属 | 收到 |
|---|---|---|
onValueChange | Calendar | (value, details):新值,以及原因 |
onMonthChange | Calendar | (month, details):新的第一个月份,以及原因 |
onFocusedChange | Calendar | (date, details):焦点移到的日期,以及原因 |
onAnchorChange | Calendar | (date, details):范围的开始,结束时为 null,以及原因 |
无障碍
它遵循 WAI-ARIA 日期选择器对话框的网格模式:每个月是一个以月份命名的 grid,星期表头是以完整名称命名的 columnheader,每个日期是一个可聚焦的 gridcell,以完整日期命名,比如“Friday, October 16, 2026”,并带有 aria-selected、aria-disabled 和 aria-current="date"。选择多个日期或一个范围的网格带有 aria-multiselectable。下面的每一行都是一个自动化测试。
键盘
网格只有一个 Tab 停靠点:可见时是选中的日期,否则是今天,再否则是第一个可用日期。移动进入另一个月份会先显示它,然后聚焦那个日期。
| 按键 | 作用 |
|---|---|
| Left / Right Arrow | 移动一天,跟随页面的方向。 |
| Up / Down Arrow | 移动一周。 |
| Home / End | 移动到本周的第一天或最后一天。 |
| Page Up / Page Down | 移动一个月,尽可能保留日。 |
| Shift+Page Up / Shift+Page Down | 移动一年。 |
| Enter / Space | 选中获得焦点的日期。 |
| Escape | 取消未完成的范围。 |
经过测试的行为
- The calendar shows a month as a grid of days under weekday headers.
- The selected date holds the tab stop, else today.
- Tab leaves the grid after one stop.
- Arrow keys move focus by day and week.
- Moving past the month's edge shows the next month and focuses the day there.
- Page Up and Page Down move by month, and with Shift by year.
- The day of the month stays the same, or the month's last, when moving by month.
- Home and End go to the first and last day of the week.
- The week starts on the locale's first day.
- Pressing a day selects it.
- Enter on a focused day selects it.
- Space on a focused day selects it.
- Previous and Next show the month before and after, and the heading announces it.
- Min and max stop keys there, and Previous and Next at their months.
- Unavailable dates can be focused but not selected.
- In multiple mode, presses toggle dates.
- In range mode, two presses pick a range, previewed in between.
- In range mode, keys preview the end and Escape drops the start.
- A range keeps to its fewest and most days, and keeps its start.
- Two months show side by side, and focus moves between them without turning.
- Pressing a day of the next month selects it and shows its month.
- Pressing another month's day before min keeps the month shown.
- Pressing another month's day before min leaves focus on the day that had it.
- A controlled calendar shows what the app passes.
- A controller turns to a date and focuses it.
- A disabled calendar has no tab stop and selects nothing.
- A read-only calendar moves focus but selects nothing.
- They show the first month shown and turn the calendar, with the select-change reason.
- Years run from min to max, and months past them are disabled.
- They follow the page's language.
运行于 React、Vue 和 web components。
基线之外:
- Keys pressed without waiting still land on the right day.
- A day of next month takes focus even when its month renders after the key.
运行于 React、Vue 和 web components。