JGuang

TimePicker

TimePicker · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

TimePicker

To select/input a time.

When To Use

By clicking the input box, you can select a time from a popup panel.

Examples

  • Basic · basic

  • Under Control · value

  • Three Sizes · size

  • Need Confirm · need-confirm

  • disabled · disabled

  • Hour and minute · hide-column

  • interval option · interval-options

  • Addon · addon

  • 12 hours · 12hours

  • Change on scroll · change-on-scroll

  • Time Range Picker · range-picker

  • Variants · variant

  • Status · status

  • Prefix and Suffix · suffix

  • Custom semantic dom styling · style-class

API


Common props ref:Common props

import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat'

dayjs.extend(customParseFormat)

<TimePicker defaultValue={dayjs('13:30:56', 'HH:mm:ss')} />;
PropertyDescriptionTypeDefaultVersionGlobal Config
allowClearCustomize clear iconboolean | { clearIcon?: ReactNode }true5.8.0: Support object type6.4.0
addonCalled from time picker panel to render an addon to its bottom, please use renderExtraFooter instead() => ReactNode--×
cellRenderCustom 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×
changeOnScrollTrigger selection when scroll the columnbooleanfalse5.14.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.25.0
defaultValueTo set default timedayjs-×
disabledDetermine whether the TimePicker is disabledbooleanfalse×
disabledTimeTo specify the time that cannot be selectedDisabledTime-4.19.0×
formatTo set the time formatstringHH:mm:ss×
getPopupContainerTo set the container of the floating layer, while the default is to create a div element in bodyfunction(trigger)-×
hideDisabledOptionsWhether hide the options that can not be selectedbooleanfalse×
hourStepInterval between hours in pickernumber1×
inputReadOnlySet the readonly attribute of the input tag (avoids virtual keyboard on touch devices)booleanfalse×
minuteStepInterval between minutes in pickernumber1×
needConfirmNeed click confirm button to trigger value changeboolean-5.14.0×
openWhether to popup panelbooleanfalse×
placeholderDisplay when there's no valuestring | [string, string]Select a time×
placementThe position where the selection box pops upbottomLeft bottomRight topLeft topRightbottomLeft×
popupClassNameThe className of panel, please use classNames.popup insteadstring-×
popupStyleThe style of panel, please use styles.popup insteadCSSProperties-×
prefixThe custom prefixReactNode-5.22.0×
previewValueWhen the user selects the time hover option, the value of the input field undergoes a temporary changefalse | hoverhover6.0.0×
renderExtraFooterCalled from time picker panel to render some addon to its bottom() => ReactNode-×
secondStepInterval between seconds in pickernumber1×
showNowWhether to show Now button on panelboolean-4.4.0×
sizeTo determine the size of the input box, the height of large and small, are 40px and 24px respectively, while default size is 32pxlarge | medium | small-×
statusSet validation status'error' | 'warning' | 'success' | 'validating'-4.19.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.25.0
suffixIconThe custom suffix iconReactNode-6.3.0
use12HoursDisplay as 12 hours format, with default format h:mm:ss abooleanfalse×
valueTo set timedayjs-×
variantVariants of pickeroutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.05.19.0
onCalendarChangeCallback function, can be executed when the start time or the end time of the range is changing. info argument is added in 4.4.0function(dates: [dayjs, dayjs], dateStrings: [string, string], info: { range:start|end })-×
onChangeA callback function, can be executed when the selected time is changingfunction(time: dayjs, timeString: string): void-×
onClearCallback when click the clear button() => void-6.5.0×
onOpenChangeA callback function which will be called while panel opening/closing(open: boolean) => void-×

DisabledTime

type DisabledTime = (now: Dayjs) => {
  disabledHours?: () => number[];
  disabledMinutes?: (selectedHour: number) => number[];
  disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
  disabledMilliseconds?: (
    selectedHour: number,
    selectedMinute: number,
    selectedSecond: number,
  ) => number[];
};

Note: disabledMilliseconds is added in 5.14.0.

Methods

NameDescriptionVersion
blur()Remove focus
focus()Get focus

RangePicker

Same props from RangePicker of DatePicker. And includes additional props:

PropertyDescriptionTypeDefaultVersion
disabledTimeTo specify the time that cannot be selectedRangeDisabledTime-4.19.0
orderOrder start and end timebooleantrue4.1.0

RangeDisabledTime

type RangeDisabledTime = (
  now: Dayjs,
  type = 'start' | 'end',
) => {
  disabledHours?: () => number[];
  disabledMinutes?: (selectedHour: number) => number[];
  disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
};

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with relative positioning, inline-flex layout, padding, border-radius, transition animations and other basic styles for date picker container—
prefixPrefix element with flex layout and margin styles for prefix content layout—
inputInput element with relative positioning, width, color, font, line-height, transition animations and other core interactive styles for input field—
suffixSuffix element with flex layout, color, line-height, pointer events, transition animations and other styles for suffix content—
popup.rootPopup element—
popup.containerContainer element, set background color, padding, border radius, shadow, border and content display styles—
popup.contentPopup content element with width, border, cell and other content display styles for date table—
popup.itemPopup item element with size, background, border-radius, hover state, selected state and other interactive styles for date cells—
popup.footerPopup footer element with layout styles for bottom operation area including confirm/cancel buttons and shortcuts—

Semantic description source: vendor/components/date-picker/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
presetsWidthnumberWidth of preset area
presetsMaxWidthnumberMax width of preset area
zIndexPopupnumberz-index of popup

Declaration source: vendor/components/date-picker/style/token.ts

import { FastColor } from '@ant-design/fast-color';

import type { SharedComponentToken, SharedInputToken } from '../../input/style/token';

import { initComponentToken } from '../../input/style/token';

import type { MultipleSelectorToken, SelectorToken } from '../../select/style/token';

import type { ArrowToken } from '../../style/roundedArrow';

import { getArrowToken } from '../../style/roundedArrow';

import type {
  FullToken,
  GetDefaultToken,
  GlobalToken,
  TokenWithCommonCls,
} from '../../theme/internal';

export interface PanelComponentToken extends MultipleSelectorToken {
  /**
   * @desc 单元格悬浮态背景色
   * @descEN Background color of cell hover state
   */
  cellHoverBg: string;
  /**
   * @desc 选取范围内的单元格背景色
   * @descEN Background color of cell in range
   */
  cellActiveWithRangeBg: string;
  /**
   * @desc 选取范围内的单元格悬浮态背景色
   * @descEN Background color of hovered cell in range
   */
  cellHoverWithRangeBg: string;
  /**
   * @desc 单元格禁用态背景色
   * @descEN Background color of disabled cell
   */
  cellBgDisabled: string;
  /**
   * @desc 选取范围时单元格边框色
   * @descEN Border color of cell in range when picking
   */
  cellRangeBorderColor: string;
  /**
   * @desc 时间列宽度
   * @descEN Width of time column
   */
  timeColumnWidth: number;
  /**
   * @desc 时间列高度
   * @descEN Height of time column
   */
  timeColumnHeight: number;
  /**
   * @desc 时间单元格高度
   * @descEN Height of time cell
   */
  timeCellHeight: number;
  /**
   * @desc 单元格高度
   * @descEN Height of cell
   */
  cellHeight: number;
  /**
   * @desc 单元格宽度
   * @descEN Width of cell
   */
  cellWidth: number;
  /**
   * @desc 单元格文本高度
   * @descEN Height of cell text
   */
  textHeight: number;
  /**
   * @desc 十年/年/季/月/周单元格高度
   * @descEN Height of decade/year/quarter/month/week cell
   */
  withoutTimeCellHeight: number;
}

export interface ComponentToken
  extends Exclude<SharedComponentToken, 'addonBg'>,
    PanelComponentToken,
    ArrowToken {
  /**
   * @desc 预设区域宽度
   * @descEN Width of preset area
   */
  presetsWidth: number;
  /**
   * @desc 预设区域最大宽度
   * @descEN Max width of preset area
   */
  presetsMaxWidth: number;
  /**
   * @desc 弹窗 z-index
   * @descEN z-index of popup
   */
  zIndexPopup: number;
}

export type PickerPanelToken = {
  pickerCellCls: string;
  pickerCellInnerCls: string;
  pickerDatePanelPaddingHorizontal: number | string;
  pickerYearMonthCellWidth: number | string;
  pickerCellPaddingVertical: number | string;
  pickerQuarterPanelContentHeight: number | string;
  pickerCellBorderGap: number;
  pickerControlIconSize: number;
  pickerControlIconMargin: number;
  pickerControlIconBorderWidth: number;
};

export interface PickerToken
  extends FullToken<'DatePicker'>,
    PickerPanelToken,
    SharedInputToken,
    SelectorToken {
  /** @private Used for internal calculation */
  INTERNAL_FIXED_ITEM_MARGIN: number;
}

export type SharedPickerToken = TokenWithCommonCls<GlobalToken> &
  PickerPanelToken &
  PanelComponentToken;

FAQ

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/time-picker/index.tsx

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.