Time Picker时间选择器
输入或从列表选择时间,支持 12 / 24 小时制、步进、时间限制和连续滑动的选中背景。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add time-picker安装
在项目根目录运行,安装源码。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add time-picker使用
React
"use client";
import { useState } from "react";import { KalosTimePicker } from "@/components/ui/kalos-time-picker";
export default function Example() { const [time, setTime] = useState<string | null>("09:30"); return <KalosTimePicker label="发送时间" value={time} onChange={setTime} step={15} min="09:00" max="18:00" hourCycle={24} name="sendAt" hint="可选 09:00–18:00" />;}API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
value / defaultValue | string | null | — / null | 24 小时制 HH:mm 或空值;输入的展示格式与提交格式分离 |
onChange | (value: string | null) => void | — | 选取或确认有效输入后返回 HH:mm;清空返回 null,无效输入恢复原值 |
step | number | 15 | 候选时间的分钟间隔,从 min 开始;手动输入可使用其他有效分钟 |
min / max | string | 00:00 / 23:59 | HH:mm 时间边界;max 早于 min 时忽略 max |
hourCycle / locale | 12 | 24 / string | 24 / zh-CN | 展示使用 12 或 24 小时制;提交始终为 HH:mm,支持 930、9:30 pm、21.30 等输入 |
label / placeholder / optional | ReactNode / string / boolean | — / 09:00 / false | 标签、占位和可选标记;点击标签不聚焦或打开 |
hint / error / disabled / readOnly / required | 字段属性 | — | 错误优先展示;禁用与只读时不能修改 |
name | string | — | 通过 Base UI Combobox 原生表单字段提交 HH:mm |
open / defaultOpen / onOpenChange | boolean / boolean / (open: boolean) => void | — / false / — | 受控或非受控列表状态,焦点保留在文本输入框 |
id / className / aria-label / ref | HTML 属性 | — | 字段标识、容器布局、无标签名称与输入框引用 |
键盘操作
- ↑ / ↓
- 打开列表并在候选时间间移动
- Enter
- 选择当前候选,或确认手动输入的时间
- Escape
- 关闭列表,再次按下恢复未确认的输入
- Tab
- 确认有效输入并移动到下一控件