From c89c597e7f56571593744693b7abab1f90c1aa06 Mon Sep 17 00:00:00 2001 From: zombieJ Date: Wed, 24 Apr 2019 17:29:49 +0800 Subject: [PATCH] feat: add `htmlFor` in Form.Item (#16278) * add htmlFor in Form.Item * update doc --- components/form/FormItem.tsx | 13 ++++++++++--- components/form/__tests__/label.test.js | 26 +++++++++++++++++++++++++ components/form/index.en-US.md | 23 +++++++++++----------- components/form/index.zh-CN.md | 23 +++++++++++----------- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index e890e1e8dc..98bc00a208 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -20,6 +20,7 @@ export interface FormItemProps { prefixCls?: string; className?: string; id?: string; + htmlFor?: string; label?: React.ReactNode; labelAlign?: FormLabelAlign; labelCol?: ColProps; @@ -60,7 +61,7 @@ export default class FormItem extends React.Component { helpShow = false; componentDidMount() { - const { children, help, validateStatus } = this.props; + const { children, help, validateStatus, id } = this.props; warning( this.getControls(children, true).length <= 1 || (help !== undefined || validateStatus !== undefined), @@ -68,6 +69,12 @@ export default class FormItem extends React.Component { 'Cannot generate `validateStatus` and `help` automatically, ' + 'while there are more than one `getFieldDecorator` in it.', ); + + warning( + !id, + 'Form.Item', + '`id` is deprecated for its label `htmlFor`. Please use `htmlFor` directly.', + ); } getHelpMessage() { @@ -328,7 +335,7 @@ export default class FormItem extends React.Component { labelCol: contextLabelCol, colon: contextColon, }: FormContextProps) => { - const { label, labelCol, labelAlign, colon, id } = this.props; + const { label, labelCol, labelAlign, colon, id, htmlFor } = this.props; const required = this.isRequired(); const mergedLabelCol: ColProps = @@ -361,7 +368,7 @@ export default class FormItem extends React.Component { return label ? (