Browse Source
Merge pull request #15923 from ant-design/fix-label-switch
fix(Form): switch should be trigger by form label
pull/15931/head
偏右
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
3 additions and
13 deletions
-
components/form/FormItem.tsx
|
|
@ -304,8 +304,7 @@ export default class FormItem extends React.Component<FormItemProps, any> { |
|
|
|
|
|
|
|
// Resolve duplicated ids bug between different forms
|
|
|
|
// https://github.com/ant-design/ant-design/issues/7351
|
|
|
|
onLabelClick = (e: any) => { |
|
|
|
const { label } = this.props; |
|
|
|
onLabelClick = () => { |
|
|
|
const id = this.props.id || this.getId(); |
|
|
|
if (!id) { |
|
|
|
return; |
|
|
@ -313,17 +312,8 @@ export default class FormItem extends React.Component<FormItemProps, any> { |
|
|
|
|
|
|
|
const formItemNode = ReactDOM.findDOMNode(this) as Element; |
|
|
|
const control = formItemNode.querySelector(`[id="${id}"]`) as HTMLElement; |
|
|
|
|
|
|
|
if (control) { |
|
|
|
// Only prevent in default situation
|
|
|
|
// Avoid preventing event in `label={<a href="xx">link</a>}``
|
|
|
|
if (typeof label === 'string') { |
|
|
|
e.preventDefault(); |
|
|
|
} |
|
|
|
|
|
|
|
if (control.focus) { |
|
|
|
control.focus(); |
|
|
|
} |
|
|
|
if (control && control.focus) { |
|
|
|
control.focus(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|