logoNamu Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
1.0.0
  • Components Overview
  • General
    • Button
    • FloatButtonNew
    • Icon
    • Typography
  • Layout
    • Divider
    • Grid
    • Layout
    • Space
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPickerNew
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCodeNew
    • Segmented
    • Statistic
    • Table
    • Tabs
    • Tag
    • Timeline
    • Tooltip
    • TourNew
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • AppNew
    • ConfigProvider
When To Use
Examples
Basic
Range Picker
Switchable picker
Date Format
Choose Time
Disabled
Disabled Date & Time
Select range dates in 7 days
Preset Ranges
Extra Footer
Three Sizes
Customized Cell Rendering
Status
Bordered-less
Placement
API
Localization
Common API
Common Methods
DatePicker
DatePicker[picker=year]
DatePicker[picker=quarter]
DatePicker[picker=month]
DatePicker[picker=week]
RangePicker
Design Token
FAQ
When set mode to DatePicker/RangePicker, cannot select year or month anymore?
Why does the date picker switch to the date panel after selecting the year instead of the month panel?
How to use DatePicker with customize date library like dayjs?
Why config dayjs.locale globally not work?
How to modify start day of week?
Why origin panel don't switch when using panelRender?

DatePicker

To select or input a date.
  • ColorPickerForm

    Resources

    Namu Design Charts
    Namu Design Pro
    Namu Design Pro Components
    Namu Design Mobile
    Namu Design Mini
    Namu Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    ahooks-React Hooks Library
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Namu Design
    Medium
    Twitter
    yuqueNamu Design in YuQue
    Namu Design in Zhihu
    Experience Cloud Blog
    seeconfSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTechMore Products

    yuqueYuQue-Document Collaboration Platform
    AntVAntV-Data Visualization
    EggEgg-Enterprise Node.js Framework
    kitchenKitchen-Sketch Toolkit
    xtechAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Namu Design Community

    When To Use

    By clicking the input box, you can select a date from a popup calendar.

    Examples

    Basic

    Basic use case. Users can select or input a date in panel.

    expand codeexpand code
    Switchable picker

    Switch in different types of pickers by Select.

    expand codeexpand code
    Choose Time

    This property provide an additional time selection. When showTime is an Object, its properties will be passed on to built-in TimePicker.

    expand codeexpand code
    Disabled Date & Time

    Disabled part of dates and time by disabledDate and disabledTime respectively, and disabledTime only works with showTime.

    expand codeexpand code
    Preset Ranges

    We can set preset ranges to RangePicker to improve user experience. Since 5.8.0, preset value supports callback function.

    expand codeexpand code
    Three Sizes

    The input box comes in three sizes. middle will be used if size is omitted.

    expand codeexpand code
    Status

    Add status to DatePicker with status, which could be error or warning.

    expand codeexpand code
    Placement

    You can manually specify the position of the popup via placement.

    expand codeexpand code
    Range Picker

    Set range picker type by picker prop.

    expand codeexpand code
    Date Format

    We can set the date format by format. When format is an array, the input box can be entered in any of the valid formats of the array.

    expand codeexpand code
    Disabled

    A disabled state of the DatePicker. You can also set as array to disable one of input.

    expand codeexpand code
    Select range dates in 7 days

    Using changeOnBlur work with onCalendarChange and disabledDate to limit date selection.

    expand codeexpand code
    Extra Footer

    Render extra footer in panel for customized requirements.

    expand codeexpand code
    Customized Cell Rendering

    We can customize the rendering of the cells in the calendar by providing a cellRender function to DatePicker.

    expand codeexpand code
    Bordered-less

    Bordered-less style component.

    expand codeexpand code

    API

    Common props ref:Common props

    There are five kinds of picker:

    • DatePicker
    • DatePicker[picker="month"]
    • DatePicker[picker="week"]
    • DatePicker[picker="year"]
    • DatePicker[picker="quarter"] (Added in 4.1.0)
    • RangePicker

    Localization

    The default locale is en-US, if you need to use other languages, recommend to use internationalized components provided by us at the entrance. Look at: ConfigProvider.

    If there are special needs (only modifying single component language), Please use the property: local. Example: default.

    import 'dayjs/locale/zh-cn';
    import locale from 'antd/es/date-picker/locale/zh_CN';
    <DatePicker locale={locale} />;
    // The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
    import dayjs from 'dayjs';
    import 'dayjs/locale/zh-cn';
    import locale from 'antd/locale/zh_CN';
    <ConfigProvider locale={locale}>
    <DatePicker defaultValue={dayjs('2015-01-01', 'YYYY-MM-DD')} />
    </ConfigProvider>;

    Common API

    The following APIs are shared by DatePicker, RangePicker.

    PropertyDescriptionTypeDefaultVersion
    allowClearCustomize clear buttonboolean | { clearIcon?: ReactNode }true5.8.0: Support object type
    autoFocusIf get focus when component mountedbooleanfalse
    borderedWhether has border stylebooleantrue
    classNameThe picker classNamestring-
    dateRenderCustom rendering function for date cells, >= 5.4.0 use cellRender instead.function(currentDate: dayjs, today: dayjs) => React.ReactNode-< 5.4.0
    changeOnBlurTrigger change when blur. e.g. datetime picker no need click confirm buttonbooleanfalse5.5.0
    cellRenderCustom rendering function for picker cells(current: dayjs, info: { originNode: React.ReactElement,today: DateType, range?: 'start' | 'end', type: PanelMode, locale?: Locale, subType?: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode-5.4.0
    disabledDetermine whether the DatePicker is disabledbooleanfalse
    disabledDateSpecify the date that cannot be selected(currentDate: dayjs) => boolean-
    formatTo set the date format, support multi-format matching when it is an array, display the first one shall prevail. refer to dayjs#format. for example: Custom FormatformatTyperc-picker
    popupClassNameTo customize the className of the popup calendarstring-4.23.0
    getPopupContainerTo set the container of the floating layer, while the default is to create a div element in bodyfunction(trigger)-
    inputReadOnlySet the readonly attribute of the input tag (avoids virtual keyboard on touch devices)booleanfalse
    localeLocalization configurationobjectdefault
    modeThe picker panel mode( Cannot select year or month anymore? )time | date | month | year | decade-
    nextIconThe custom next iconReactNode-4.17.0
    openThe open state of pickerboolean-
    panelRenderCustomize panel render(panelNode) => ReactNode-4.5.0
    pickerSet picker typedate | week | month | quarter | yeardatequarter: 4.1.0
    placeholderThe placeholder of date inputstring | [string,string]-
    placementThe position where the selection box pops upbottomLeft bottomRight topLeft topRightbottomLeft
    popupStyleTo customize the style of the popup calendarCSSProperties{}
    presetsThe preset ranges for quick selection, Since 5.8.0, preset value supports callback function.{ label: React.ReactNode, value: Dayjs | (() => Dayjs) }[]-
    prevIconThe custom prev iconReactNode-4.17.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 | middle | small-
    statusSet validation status'error' | 'warning'-4.19.0
    styleTo customize the style of the input boxCSSProperties{}
    suffixIconThe custom suffix iconReactNode-
    superNextIconThe custom super next iconReactNode-4.17.0
    superPrevIconThe custom super prev iconReactNode-4.17.0
    onOpenChangeCallback function, can be executed whether the popup calendar is popped up or closedfunction(open)-
    onPanelChangeCallback when picker panel mode is changedfunction(value, mode)-

    Common Methods

    NameDescriptionVersion
    blur()Remove focus
    focus()Get focus

    DatePicker

    PropertyDescriptionTypeDefaultVersion
    defaultPickerValueTo set default picker datedayjs-
    defaultValueTo set default date, if start time or end time is null or undefined, the date range will be an open intervaldayjs-
    disabledTimeTo specify the time that cannot be selectedfunction(date)-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY-MM-DD
    renderExtraFooterRender extra footer in panel(mode) => React.ReactNode-
    showNowWhether to show 'Now' button on panel when showTime is setboolean-4.4.0
    showTimeTo provide an additional time selectionobject | booleanTimePicker Options
    showTime.defaultValueTo set default time of selected date, demodayjsdayjs()
    showTodayWhether to show Today buttonbooleantrue
    valueTo set datedayjs-
    onChangeCallback function, can be executed when the selected time is changingfunction(date: dayjs, dateString: string)-
    onOkCallback when click ok buttonfunction()-
    onPanelChangeCallback function for panel changingfunction(value, mode)-

    DatePicker[picker=year]

    PropertyDescriptionTypeDefaultVersion
    defaultPickerValueTo set default picker datedayjs-
    defaultValueTo set default datedayjs-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY
    renderExtraFooterRender extra footer in panel() => React.ReactNode-
    valueTo set datedayjs-
    onChangeCallback function, can be executed when the selected time is changingfunction(date: dayjs, dateString: string)-

    DatePicker[picker=quarter]

    Added in 4.1.0.

    PropertyDescriptionTypeDefaultVersion
    defaultPickerValueTo set default picker datedayjs-
    defaultValueTo set default datedayjs-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY-\QQ
    renderExtraFooterRender extra footer in panel() => React.ReactNode-
    valueTo set datedayjs-
    onChangeCallback function, can be executed when the selected time is changingfunction(date: dayjs, dateString: string)-

    DatePicker[picker=month]

    PropertyDescriptionTypeDefaultVersion
    defaultPickerValueTo set default picker datedayjs-
    defaultValueTo set default datedayjs-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY-MM
    renderExtraFooterRender extra footer in panel() => React.ReactNode-
    valueTo set datedayjs-
    onChangeCallback function, can be executed when the selected time is changingfunction(date: dayjs, dateString: string)-

    DatePicker[picker=week]

    PropertyDescriptionTypeDefaultVersion
    defaultPickerValueTo set default picker datedayjs-
    defaultValueTo set default datedayjs-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY-wo
    renderExtraFooterRender extra footer in panel(mode) => React.ReactNode-
    valueTo set datedayjs-
    onChangeCallback function, can be executed when the selected time is changingfunction(date: dayjs, dateString: string)-

    RangePicker

    PropertyDescriptionTypeDefaultVersion
    allowEmptyAllow start or end input leave empty[boolean, boolean][false, false]
    dateRenderCustom rendering function for date cells, >= 5.4.0 use cellRender instead.function(currentDate: dayjs, today: dayjs) => React.ReactNode-< 5.4.0
    cellRenderCustom rendering function for picker cells(current: dayjs, info: { originNode: React.ReactElement,today: DateType, range?: 'start' | 'end', type: PanelMode, locale?: Locale, subType?: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode-5.4.0
    defaultPickerValueTo set default picker date[dayjs, dayjs]-
    defaultValueTo set default date[dayjs, dayjs]-
    disabledIf disable start or end[boolean, boolean]-
    disabledTimeTo specify the time that cannot be selectedfunction(date: dayjs, partial: start | end)-
    formatTo set the date format. refer to dayjs#formatformatTypeYYYY-MM-DD HH:mm:ss
    presetsThe preset ranges for quick selection, Since 5.8.0, preset value supports callback function.{ label: React.ReactNode, value: (Dayjs | (() => Dayjs))[] }[]-
    renderExtraFooterRender extra footer in panel() => React.ReactNode-
    separatorSet separator between inputsReact.ReactNode<SwapRightOutlined />
    showTimeTo provide an additional time selectionobject | booleanTimePicker Options
    showTime.defaultValueTo set default time of selected date, demodayjs[][dayjs(), dayjs()]
    valueTo set date[dayjs, dayjs]-
    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 })-
    onChangeCallback function, can be executed when the selected time is changingfunction(dates: [dayjs, dayjs], dateStrings: [string, string])-

    formatType

    import type { Dayjs } from 'dayjs';
    type Generic = string;
    type GenericFn = (value: Dayjs) => string;
    export type FormatType = Generic | GenericFn | Array<Generic | GenericFn>;

    Design Token

    Component Token

    Global Token

    FAQ

    When set mode to DatePicker/RangePicker, cannot select year or month anymore?

    Please refer FAQ

    Why does the date picker switch to the date panel after selecting the year instead of the month panel?

    After selecting the year, the system directly switches to the date panel instead of month panel. This design is intended to reduce the user's operational burden by allowing them to complete the year modification with just one click, without having to enter the month selection interface again. At the same time, it also avoids additional cognitive burden of remembering the month.

    How to use DatePicker with customize date library like dayjs?

    Please refer Use custom date library

    Why config dayjs.locale globally not work?

    DatePicker default set locale as en in v4. You can config DatePicker locale prop or ConfigProvider locale prop instead.

    Date-related components locale is not working?

    See FAQ Date-related-components-locale-is-not-working?

    How to modify start day of week?

    Please use correct language (#5605), or update dayjs locale config:

    • Example: https://codesandbox.io/s/dayjs-day-of-week-x9tuj2?file=/demo.tsx
    import dayjs from 'dayjs';
    import 'dayjs/locale/zh-cn';
    import updateLocale from 'dayjs/plugin/updateLocale';
    dayjs.extend(updateLocale);
    dayjs.updateLocale('zh-cn', {
    weekStart: 0,
    });

    Why origin panel don't switch when using panelRender?

    When you change the layout of nodes by panelRender, React will unmount and re-mount it which reset the component state. You should keep the layout stable. Please ref #27263 for more info.

    Time