ant-design/components/date-picker/index.zh-CN.md
陈帅 523b74e3b6
merge master into Feature (#25262)
* feat: add successColor for Progress (#24655)

* feat: add successColor for Progress

* feat: update

* fix: update test

* remove snap

* feat: add test case

* refactor success

* feat: adjust styyle

* feat: add DevWarning

* feat: Support rowSelection.dirty (#24718)

* feat: Support rowSelection.dirty

* rename to reserveKeys

* preserveKeys will keep record also

* to preserveSelectedRowKeys

* feat: add ghost prop for collapse (#24734)

* feat: add ghost prop for collapse

* doc: version of collapse's ghost prop

* refactor: make ghost collapse's less code to a nested style

* chore: remove redundant codes in ghost collapse's less & doc

* doc: add a background wrapper for ghost collapse demo

* doc: dark-theme wrapper bg-color for ghost collapse demo

* test: update snapshot of ghost collapse

* doc: use softer bg-color on ghost collapse demo

* doc: remove disabled panel in ghost collapse demo

* feat: form instance support getFieldInstance (#24711)

* support getFieldInstance

* update doc

* fix lint

* move func

* move into hooks

* update ref logic

* fix lint

* rm only

* fix docs

* feat: dropdown support arrow (#23869)

* feat: dropdown support arrow prop

close #22758

* test: update snapshot

* fix: fix dropdown cls names

* test: update snapshot

* test: update snapshot

* doc: update demo

* test: update demo snapshot

* demo

* fix: snapshot

* chore: change the style of ghost collapse & demo modified (#24762)

* refactor: reduce content padding in ghost collapse

* doc: remove the wrapper outside ghost collapse

Designer want the demo differs from other demos

* refactor: remove redundant .less code in collapse

* feat: cascader dropdown-render prop (#24812)

* feat: cascader dropdown-render prop

* fix: update Cascader dropdownRender type annotation

* fix: set rc-cascader semver from ^ to ~

* docs: fix coding style in cascader/custom-dropdown

* feat: 🆕 support Drawer closeIcon (#24842)

* feat: 🆕 support Drawer closeIcon

close #19283
close #19153

* add test case

* update docs

* feat: 🆕 Cascader expandIcon (#24865)

* feat: cascader expandIcon

* fix: snap

* refactor: reduce CSS size (#24846)

* refactor: reduce button css size

* refactor: remove redundant button .less code

* feat: add Table onChange an action param (#24697)

* Working on tests

* created TableAction type

* changed TableActions to tuple

* removed chinese documentation line

* refactor TableActions

* fix documentation

* Moved action into extra param

* minor doc change

* feat: add closeIcon customize tag close (#24885)

* feat: add closeIcon customize tag close

* docs fix

* update snap

* fix: css name

* update snapshot

* snapshot

* feat: add radio `optionType` api to set radio option type (#24809)

* feat: radio component

* docs: update md

* fix: snap

* test components

* fix: use optionType

* fix name

* add warning

* fix

* feat: expand rate character (#24903)

* feat: expand rate character

* fix: demo

* fix: snap

* Update components/rate/index.zh-CN.md

Co-authored-by: 偏右 <afc163@gmail.com>

* fix

Co-authored-by: 偏右 <afc163@gmail.com>

* Refactor demo code box actions (#24887)

* refactor: refine the styling of actions part of demo code-box

* fix: lint style

* refactor: move Result children to end (#24945)

* feat: remove content max-width on dot-step (#24907)

* feat: add Skeleton-Image (#24805)

* feat: add Skeleton-Image

* feat: add docs

* fix: adjust skeleton

* feat: adjust Image Component

* feat: rebase

* feat: adjust style

* fix: lint

* feat: remove size

* feat: delete md

* feat: fix style

*  feat: Mentions support autoSize (#24961)

close #17746

* chore: replace textarea with rc-textarea (#24966)

* feat: update pagination@2.3.0 support onChange called when pageSize change (#24964)

* feat: update pagination@2.5.0 and add test case to relative component

* fix: lint

* delete

* feat: add test case for pagination

* adjust test case

* feat: Implement centered prop in Tabs (#24958)

* Implement centered in Tabs along with its tests and docs

* Fix build error

* Add Chinese translations and remove test case

Co-authored-by: Ashkan Pourghasem <ashkan.pourghasem@gmail.com>

* feat: Add modal style parameter (#24773)

* add some paramters in default.less

* Update components/style/themes/default.less

Co-authored-by: Amumu <yoyo837@hotmail.com>

* change parameter in compact.less

Co-authored-by: Crystal Gao <jinggao@ebay.com>
Co-authored-by: Amumu <yoyo837@hotmail.com>

* feat: export Tabs addIcon (#25006)

* feat: export Tabs addIcon

* update snapshot

* feat: showNow on timepicker and datetimepicker (#25032)

* feat: update rc-picker@1.7.1 and fix icons of month and quarter picker in DatePicker Component (#25035)

* feat: update rc-picker@1.7.1

* delete

* add

* feat: expand rate support props (#24993)

* docs: 📝 Add Form.Item hidden in doc (#25108)

close #25101

* fix: ⌨️ Improve Pagination accessibility issue (#25119)

* ⌨️ Improve Pagination a11y by fixing a W3C error

https://github.com/react-component/pagination/issues/280

* update snapshot

* 🆙 rc-pagination to 2.4.1

* feat: support triggerSubMenuAction for <Menu /> (#25127)

* feat(menu): add triggerSubMenuAction for Menu

* feat(menu): test cases

* chore: Adjust picker logic (#25135)

* chore: update rc-picker 1.10.0 (#25174)

* feat: table row check strictly (#24931)

* feat: add checkStrictly on Table.rowSelection

* fix: LGTM warnings

* test: table rowSelection.checkStrictly

* test: add cov [wip]

* refactor: tree.rowSelection.checkStrictly [wip]

* test: table.rowSelection.checkStrictly basic case

* feat: support rowKey on checkStrictly table

* feat: Table checkStrictly support getCheckboxProps

* docs: Table checkStrictly

* chore: typo

* chore: remove useless comment

* chore: update snapshot

* chore: update snapshot

* fix: fire selectAll on selection dropdown menu & changeRows incorrect in selectAll callback

* docs: typo

* chore

* chore

* fix: expand buttons of leaf rows in tree data are not hidden

* feat: Table warning about rowKey index parameter

* perf: only generate keyEntities when not checkStrictly

* refactor: remove useless parseCheckedKeys

* refactor: get derived selected & half selected keys from selectedRowKeys

* chore: remove env condition stmt

* chore: revert index usage & code formatting

* chore: rerun ci

* docs: table tree-data checkstrictly

* test: update snapshots

* refactor: use useMergedState hook

* chore: rerun ci

* chore: rerun ci 2

* chore: revert selection select all behavior

* refactor: refactor code based on feature

* chore: revert table code format

* chore: revert table code format

* fix: useMemo deps

* fix: useMemo deps

* fix: useMemo deps

* feat: support preserve (#25186)

* docs: add responsibly order for Col (#25139)

* feat: add type

* feat: add responsibly order cols

* feat: add docs

* feat: add test case

* fix test

Co-authored-by: 二货机器人 <smith3816@gmail.com>
Co-authored-by: 偏右 <afc163@gmail.com>
Co-authored-by: zoomdong <1344492820@qq.com>
Co-authored-by: 07akioni <07akioni2@gmail.com>
Co-authored-by: wendellhu <wendellhu95@gmail.com>
Co-authored-by: xrkffgg <xrkffgg@gmail.com>
Co-authored-by: Neto Braghetto <netow93@gmail.com>
Co-authored-by: Kermit Xuan <kermitlx@outlook.com>
Co-authored-by: Ashkan Pourghasem <64011067+ashkan-pm@users.noreply.github.com>
Co-authored-by: Ashkan Pourghasem <ashkan.pourghasem@gmail.com>
Co-authored-by: hicrystal <295247343@qq.com>
Co-authored-by: Crystal Gao <jinggao@ebay.com>
Co-authored-by: Amumu <yoyo837@hotmail.com>
Co-authored-by: Li Ming <armyiljfe@gmail.com>
2020-06-28 22:41:59 +08:00

10 KiB
Raw Blame History

category type title subtitle cover
Components 数据录入 DatePicker 日期选择框 https://gw.alipayobjects.com/zos/alicdn/RT_USzA48/DatePicker.svg

输入或选择日期的控件。

何时使用

当用户需要输入一个日期,可以点击标准输入框,弹出日期面板进行选择。

API

日期类组件包括以下五种形式。

  • DatePicker
  • MonthPicker
  • RangePicker
  • WeekPicker
  • YearPicker
  • QuarterPicker (4.1.0 新增)

国际化配置

默认配置为 en-US如果你需要设置其他语言推荐在入口处使用我们提供的国际化组件详见ConfigProvider 国际化

如有特殊需求(仅修改单一组件的语言),请使用 locale 参数,参考:默认配置

import locale from 'antd/es/date-picker/locale/zh_CN';

<DatePicker locale={locale} />;
// 默认语言为 en-US如果你需要设置其他语言推荐在入口文件全局设置 locale
import moment from 'moment';
import 'moment/locale/zh-cn';

<DatePicker defaultValue={moment('2015-01-01', 'YYYY-MM-DD')} />;

共同的 API

以下 API 为 DatePicker、YearPicker、MonthPicker、RangePicker, WeekPicker 共享的 API。

参数 说明 类型 默认值 版本
allowClear 是否显示清除按钮 boolean true
autoFocus 自动获取焦点 boolean false
className 选择器 className string ''
dateRender 自定义日期单元格的内容 function(currentDate: moment, today: moment) => React.ReactNode -
disabled 禁用 boolean false
disabledDate 不可选择的日期 (currentDate: moment) => boolean -
dropdownClassName 额外的弹出日历 className string -
getPopupContainer 定义浮层的容器,默认为 body 上新建 div function(trigger) -
locale 国际化配置 object 默认配置
mode 日期面板的状态(设置后无法选择年份/月份? time | date | month | year | decade -
open 控制弹层是否展开 boolean -
picker 设置选择器类型 date | week | month | quarter (4.1.0) | year date
placeholder 输入框提示文字 string | [string, string] -
popupStyle 额外的弹出日历样式 CSSProperties {}
size 输入框大小,large 高度为 40pxsmall 为 24px默认是 32px large | middle | small -
bordered 是否有边框 boolean true
suffixIcon 自定义的选择框后缀图标 ReactNode -
style 自定义输入框样式 CSSProperties {}
onOpenChange 弹出日历和关闭日历的回调 function(open) -
onPanelChange 日历面板切换的回调 function(value, mode) -
inputReadOnly 设置输入框为只读(避免在移动设备上打开虚拟键盘) boolean false

共同的方法

名称 描述 版本
blur() 移除焦点
focus() 获取焦点

DatePicker

参数 说明 类型 默认值 版本
defaultValue 默认日期,如果开始时间或结束时间为 null 或者 undefined,日期范围将是一个开区间 moment -
defaultPickerValue 默认面板日期 moment -
disabledTime 不可选择的时间 function(date) -
format 设置日期格式,为数组时支持多格式匹配,展示以第一个为准。配置参考 moment.js string | string[] "YYYY-MM-DD"
renderExtraFooter 在面板中添加额外的页脚 (mode) => React.ReactNode -
showTime 增加时间选择功能 Object|boolean TimePicker Options
showTime.defaultValue 设置用户选择日期时默认的时分秒,例子 moment moment()
showToday 是否展示“今天”按钮 boolean true
value 日期 moment -
onChange 时间发生变化的回调 function(date: moment, dateString: string) -
onOk 点击确定按钮的回调 function() -
onPanelChange 日期面板变化时的回调 function(value, mode) -
showNow 当设定了 showTime 的时候,面板是否显示“此刻”按钮 boolean - 4.4.0

YearPicker

参数 说明 类型 默认值 版本
defaultValue 默认日期 moment -
defaultPickerValue 默认面板日期 moment -
format 展示的日期格式,配置参考 moment.js string "YYYY"
renderExtraFooter 在面板中添加额外的页脚 () => React.ReactNode -
value 日期 moment -
onChange 时间发生变化的回调,发生在用户选择时间时 function(date: moment, dateString: string) -

QuarterPicker

4.1.0 新增。

参数 说明 类型 默认值 版本
defaultValue 默认日期 moment -
defaultPickerValue 默认面板日期 moment -
format 展示的日期格式,配置参考 moment.js string "YYYY-\QQ"
renderExtraFooter 在面板中添加额外的页脚 () => React.ReactNode -
value 日期 moment -
onChange 时间发生变化的回调,发生在用户选择时间时 function(date: moment, dateString: string) -

MonthPicker

参数 说明 类型 默认值 版本
defaultValue 默认日期 moment -
defaultPickerValue 默认面板日期 moment -
format 展示的日期格式,配置参考 moment.js string "YYYY-MM"
monthCellRender 自定义的月份内容渲染方法 function(date, locale): ReactNode -
renderExtraFooter 在面板中添加额外的页脚 () => React.ReactNode -
value 日期 moment -
onChange 时间发生变化的回调,发生在用户选择时间时 function(date: moment, dateString: string) -

WeekPicker

参数 说明 类型 默认值 版本
defaultValue 默认日期 moment -
defaultPickerValue 默认面板日期 moment -
format 展示的日期格式,配置参考 moment.js string "YYYY-wo"
value 日期 moment -
onChange 时间发生变化的回调,发生在用户选择时间时 function(date: moment, dateString: string) -
renderExtraFooter 在面板中添加额外的页脚 (mode) => React.ReactNode -

RangePicker

参数 说明 类型 默认值 版本
allowEmpty 允许起始项部分为空 [boolean, boolean] [false, false]
dateRender 自定义日期单元格的内容。info 参数自 4.3.0 添加 function(currentDate: moment, today: moment, info: { range: 'start' | ''end }) => React.ReactNode -
defaultValue 默认日期 moment[] -
defaultPickerValue 默认面板日期 moment[] -
disabled 禁用起始项 [boolean, boolean] -
disabledTime 不可选择的时间 function(dates: [moment, moment], partial: `'start' 'end'`) -
format 展示的日期格式 string "YYYY-MM-DD HH:mm:ss"
ranges 预设时间范围快捷选择 { [range: string]: moment[] } | { [range: string]: () => moment[] } -
renderExtraFooter 在面板中添加额外的页脚 () => React.ReactNode -
separator 设置分隔符 string ~
showTime 增加时间选择功能 Object|boolean TimePicker Options
showTime.defaultValue 设置用户选择日期时默认的时分秒,例子 moment[] [moment(), moment()]
value 日期 moment[] -
onCalendarChange 待选日期发生变化的回调 function(dates: [moment, moment], dateStrings: [string, string]) -
onChange 日期范围发生变化的回调 function(dates: [moment, moment], dateStrings: [string, string]) -

FAQ