2016-07-26 11:03:44 +08:00
---
category: Components
2022-11-09 12:28:04 +08:00
group: Data Entry
2016-07-26 11:03:44 +08:00
title: TimePicker
2022-11-30 20:14:41 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*kGmGSLk_1fwAAAAAAAAAAAAADrJ8AQ/original
2023-02-09 22:17:31 +08:00
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*1hDmQJIDFJQAAAAAAAAAAAAADrJ8AQ/original
2022-11-09 12:28:04 +08:00
demo:
cols: 2
2016-07-26 11:03:44 +08:00
---
To select/input a time.
2016-09-10 13:43:30 +08:00
## When To Use
2017-10-25 10:25:44 +08:00
2016-07-26 11:03:44 +08:00
By clicking the input box, you can select a time from a popup panel.
2022-11-09 12:28:04 +08:00
## Examples
2022-11-17 17:31:26 +08:00
<!-- prettier - ignore -->
2022-11-09 12:28:04 +08:00
< code src = "./demo/basic.tsx" > Basic< / code >
< code src = "./demo/value.tsx" > Under Control< / code >
< code src = "./demo/size.tsx" > Three Sizes< / code >
< code src = "./demo/disabled.tsx" > disabled< / code >
< code src = "./demo/hide-column.tsx" > Hour and minute< / code >
< code src = "./demo/interval-options.tsx" > interval option< / code >
< code src = "./demo/addon.tsx" > Addon< / code >
< code src = "./demo/12hours.tsx" > 12 hours< / code >
< code src = "./demo/colored-popup.tsx" debug > Colored Popup< / code >
< code src = "./demo/range-picker.tsx" > Time Range Picker< / code >
< code src = "./demo/bordered.tsx" > Bordered-less< / code >
< code src = "./demo/status.tsx" > Status< / code >
< code src = "./demo/suffix.tsx" debug > Suffix< / code >
< code src = "./demo/render-panel.tsx" debug > _InternalPanelDoNotUseOrYouWillBeFired< / code >
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
---
2016-07-26 11:03:44 +08:00
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2016-09-09 13:55:21 +08:00
```jsx
2022-02-14 14:40:40 +08:00
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat'
2020-04-28 14:09:54 +08:00
2022-02-14 14:40:40 +08:00
dayjs.extend(customParseFormat)
< TimePicker defaultValue = {dayjs('13:30:56', ' HH:mm:ss ' ) } / > ;
2016-07-26 11:03:44 +08:00
```
2019-07-11 14:14:33 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2023-07-27 14:20:18 +08:00
| allowClear | Customize clear icon | boolean \| { clearIcon?: ReactNode } | true | 5.8.0: Support object type |
2020-07-01 20:18:48 +08:00
| autoFocus | If get focus when component mounted | boolean | false | |
| bordered | Whether has border style | boolean | true | |
2023-06-28 10:34:25 +08:00
| cellRender | Custom rendering function for picker cells | (current: number, info: { originNode: React.ReactElement, today: dayjs, range?: 'start' \| 'end', subType: 'hour' \| 'minute' \| 'second' \| 'meridiem' }) => React.ReactNode | - | 5.4.0 |
2023-05-09 18:00:44 +08:00
| changeOnBlur | Trigger `change` when blur. e.g. datetime picker no need click confirm button | boolean | false | 5.5.0 |
2020-07-01 20:18:48 +08:00
| className | The className of picker | string | - | |
2022-02-14 14:40:40 +08:00
| defaultValue | To set default time | [dayjs ](http://day.js.org/ ) | - | |
2020-07-01 20:18:48 +08:00
| disabled | Determine whether the TimePicker is disabled | boolean | false | |
2022-12-22 14:12:26 +08:00
| disabledTime | To specify the time that cannot be selected | [DisabledTime ](#disabledtime ) | - | 4.19.0 |
2020-07-01 20:18:48 +08:00
| format | To set the time format | string | `HH:mm:ss` | |
| getPopupContainer | To set the container of the floating layer, while the default is to create a div element in body | function(trigger) | - | |
| hideDisabledOptions | Whether hide the options that can not be selected | boolean | false | |
| hourStep | Interval between hours in picker | number | 1 | |
2019-11-20 14:55:34 +08:00
| inputReadOnly | Set the `readonly` attribute of the input tag (avoids virtual keyboard on touch devices) | boolean | false | |
2020-07-01 20:18:48 +08:00
| minuteStep | Interval between minutes in picker | number | 1 | |
| open | Whether to popup panel | boolean | false | |
| placeholder | Display when there's no value | string \| \[string, string] | `Select a time` | |
2022-01-20 16:54:47 +08:00
| placement | The position where the selection box pops up | `bottomLeft` `bottomRight` `topLeft` `topRight` | bottomLeft | |
2020-07-01 20:18:48 +08:00
| popupClassName | The className of panel | string | - | |
| popupStyle | The style of panel | CSSProperties | - | |
2020-10-21 10:33:43 +08:00
| renderExtraFooter | Called from time picker panel to render some addon to its bottom | () => ReactNode | - | |
2020-07-01 20:18:48 +08:00
| secondStep | Interval between seconds in picker | number | 1 | |
2020-10-21 10:33:43 +08:00
| showNow | Whether to show `Now` button on panel | boolean | - | 4.4.0 |
2023-03-13 17:01:12 +08:00
| size | To determine the size of the input box, the height of `large` and `small` , are 40px and 24px respectively, while default size is 32px | `large` \| `middle` \| `small` | - | |
2022-02-16 21:14:51 +08:00
| status | Set validation status | 'error' \| 'warning' \| 'success' \| 'validating' | - | 4.19.0 |
2019-11-20 14:55:34 +08:00
| suffixIcon | The custom suffix icon | ReactNode | - | |
2020-07-01 20:18:48 +08:00
| use12Hours | Display as 12 hours format, with default format `h:mm:ss a` | boolean | false | |
2022-02-14 14:40:40 +08:00
| value | To set time | [dayjs ](http://day.js.org/ ) | - | |
| onChange | A callback function, can be executed when the selected time is changing | function(time: dayjs, timeString: string): void | - | |
2020-07-01 20:18:48 +08:00
| onOpenChange | A callback function which will be called while panel opening/closing | (open: boolean) => void | - | |
2022-02-14 14:40:40 +08:00
| onSelect | A callback function, executes when a value is selected | function(time: dayjs): void | - | |
2016-07-26 11:03:44 +08:00
2021-12-31 11:28:02 +08:00
#### DisabledTime
```typescript
2022-06-13 14:03:43 +08:00
type DisabledTime = (now: Dayjs) => {
2021-12-31 11:28:02 +08:00
disabledHours?: () => number[];
disabledMinutes?: (selectedHour: number) => number[];
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
};
```
2017-12-01 19:28:41 +08:00
## Methods
2022-02-14 14:40:40 +08:00
| Name | Description | Version |
| ------- | ------------ | ------- |
| blur() | Remove focus | |
| focus() | Get focus | |
2017-12-01 19:28:41 +08:00
2020-03-06 20:19:24 +08:00
### RangePicker
2022-12-22 14:12:26 +08:00
Same props from [RangePicker ](/components/date-picker/#rangepicker ) of DatePicker. And includes additional props:
2020-03-06 20:19:24 +08:00
2021-03-01 19:20:48 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2022-12-22 14:12:26 +08:00
| disabledTime | To specify the time that cannot be selected | [RangeDisabledTime ](#rangedisabledtime ) | - | 4.19.0 |
2021-03-01 19:20:48 +08:00
| order | Order start and end time | boolean | true | 4.1.0 |
2020-03-06 20:19:24 +08:00
2021-12-31 11:28:02 +08:00
### RangeDisabledTime
```typescript
type RangeDisabledTime = (
2022-06-13 14:03:43 +08:00
now: Dayjs,
2021-12-31 11:28:02 +08:00
type = 'start' | 'end',
) => {
disabledHours?: () => number[];
disabledMinutes?: (selectedHour: number) => number[];
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
};
```
2020-03-06 20:19:24 +08:00
2023-04-11 10:25:24 +08:00
## Design Token
< ComponentTokenTable component = "DatePicker" > < / ComponentTokenTable >
2020-01-02 16:05:59 +08:00
## FAQ
2022-12-22 14:12:26 +08:00
- [How to use TimePicker with customize date library like dayjs ](/docs/react/use-custom-date-library#timepicker )