ant-design/components/time-picker/index.zh-CN.md

80 lines
3.2 KiB
Markdown
Raw Normal View History

2016-03-31 14:17:09 +08:00
---
category: Components
2016-09-21 11:28:38 +08:00
subtitle: 时间选择框
type: 数据录入
2016-09-21 11:28:38 +08:00
title: TimePicker
cover: https://gw.alipayobjects.com/zos/alicdn/h04Zsl98I/TimePicker.svg
2016-03-31 14:17:09 +08:00
---
2015-11-16 23:11:41 +08:00
输入或选择时间的控件。
2016-07-26 11:03:44 +08:00
## 何时使用
2017-10-25 10:25:44 +08:00
2019-05-07 14:57:32 +08:00
---
2015-11-16 23:11:41 +08:00
当用户需要输入一个时间,可以点击标准输入框,弹出时间面板进行选择。
2016-07-26 11:03:44 +08:00
## API
2017-10-25 10:25:44 +08:00
2019-05-07 14:57:32 +08:00
---
2015-11-16 23:11:41 +08:00
```jsx
import moment from 'moment';
2019-05-07 14:57:32 +08:00
<TimePicker defaultValue={moment('13:30:56', 'HH:mm:ss')} />;
2015-11-16 23:11:41 +08:00
```
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| allowClear | 是否展示清除按钮 | boolean | true | |
| autoFocus | 自动获取焦点 | boolean | false | |
2020-06-17 17:08:47 +08:00
| bordered | 是否有边框 | boolean | true | |
| className | 选择器类名 | string | '' | |
| clearText | 清除按钮的提示文案 | string | clear | |
| defaultValue | 默认时间 | [moment](http://momentjs.com/) | 无 | |
| disabled | 禁用全部操作 | boolean | false | |
| disabledHours | 禁止选择部分小时选项 | function() | 无 | |
| disabledMinutes | 禁止选择部分分钟选项 | function(selectedHour) | 无 | |
| disabledSeconds | 禁止选择部分秒选项 | function(selectedHour, selectedMinute) | 无 | |
| format | 展示的时间格式 | string | "HH:mm:ss" | |
| getPopupContainer | 定义浮层的容器,默认为 body 上新建 div | function(trigger) | 无 | |
| hideDisabledOptions | 隐藏禁止选择的选项 | boolean | false | |
| hourStep | 小时选项间隔 | number | 1 | |
| inputReadOnly | 设置输入框为只读(避免在移动设备上打开虚拟键盘) | boolean | false | |
| minuteStep | 分钟选项间隔 | number | 1 | |
| open | 面板是否打开 | boolean | false | |
| placeholder | 没有值的时候显示的内容 | string \| \[string, string] | "请选择时间" | |
| popupClassName | 弹出层类名 | string | - | |
| popupStyle | 弹出层样式对象 | object | - | |
| secondStep | 秒选项间隔 | number | 1 | |
| suffixIcon | 自定义的选择框后缀图标 | ReactNode | - | |
| clearIcon | 自定义的清除图标 | ReactNode | - | |
feat: New Picker (#20023) * init generate * basic style * basic panel style * update mode panel style * update style * generate More picker * default clear icon * chore: Update separator type * feat: Add ranged start & end className * update range style * Add transition effect * support size config * adjust range style * chore: Auto fill time by showTime * auto set time by format * update disabled style * update seperator style * ranges style * support extra footer style * remove useless test case part is not usable anymore part is already tested in rc-picker * init calendar * all demos * fix calendar basic test * fix time-picker test case * update snapshot * fix tooltip test case & lint * fix locale & style lint * fix compile * fix style * fix style lint * fix calendar style * update rc-picker version * adjust style * move picker placeholder into locale file * update snapshot * add hover style * update picker version * fix icon position & style * update picker version * update deps for pading * fix: align of suffix * feat: Year & Month support range effect * adjust range style to support up-down placement * update rc-picker * update range picker style * adjust extra footer line style * update snapshot * fix: Locale error * fix: style lint * fix: add missing button style deps * update test case * fix firefox additional white line style issue * rollback demo * fix ff additional blue color * docs: Remove placeholder in demo * rangepicker ranges is tag now * connect start / end background color with picker range * update deps * update deps for fixing blur text issue * hide start-end demo * range hover style update * hover range with ranged value * black magic of inner hover style * hover style of range adjust * fix css select miss hit on DatePicker * remove one eslint rule * fade range hovered color * week should alway not show the cell selection * update style of selection * update snapshot * fix style * add margin back * update rc-picker deps * update date & time picker & form style * fix disabled demo & update form style * update docs about allowEmpty * hide arrow in time range picker * add hover & focused style * fix lint * fix style & update snapshot * raise disabled selector proirity * fix disabled today border color * extra footer provides an bottom line * time picker hover support transition background * add padding style * fix Firefox not correct calculate inline-flex * fix style * fix week picker missing today border color * rm useless padding * Force padding to 0 * test coverage * dedup eslint rule * adjust logic to imporve coverage * fix render cell logic
2019-12-11 23:32:19 +08:00
| renderExtraFooter | 选择框底部显示自定义的内容 | () => ReactNode | 无 | |
| use12Hours | 使用 12 小时制,为 true 时 `format` 默认为 `h:mm:ss a` | boolean | false | |
| value | 当前时间 | [moment](http://momentjs.com/) | 无 | |
| onChange | 时间发生变化的回调 | function(time: moment, timeString: string): void | 无 | |
| onOpenChange | 面板打开/关闭时的回调 | (open: boolean): void | 无 | |
2015-11-16 23:11:41 +08:00
## 方法
| 名称 | 描述 | 版本 |
| ------- | -------- | ---- |
| blur() | 移除焦点 | |
| focus() | 获取焦点 | |
### RangePicker
属性与 DatePicker 的 [RangePicker](/components/date-picker/#RangePicker) 相同。还包含以下属性:
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| ----- | -------------------- | ------- | ------ | ----- |
| order | 始末时间是否自动排序 | boolean | true | 4.1.0 |
2020-05-10 22:11:09 +08:00
<style>
.code-box-demo .ant-picker { margin: 0 8px 12px 0; }
.ant-row-rtl .code-box-demo .ant-picker { margin: 0 0 12px 8px; }
</style>
## FAQ
- [如何在 TimePicker 中使用自定义日期库(如 dayjs ](/docs/react/replace-moment#TimePicker)