This commit is contained in:
afc163 2018-01-24 21:49:14 +08:00
parent d54dfdfac2
commit b3f31216df

View File

@ -222,13 +222,19 @@ 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 = () => {
onLabelClick = (e: any) => {
const { label } = this.props;
const id = this.props.id || this.getId();
if (!id) {
return;
}
const controls = document.querySelectorAll(`[id="${id}"]`);
if (controls.length !== 1) {
// Only prevent in default situation
// Avoid preventing event in `label={<a href="xx">link</a>}``
if (typeof label === 'string') {
e.preventDefault();
}
const control = ReactDOM.findDOMNode(this).querySelector(`[id="${id}"]`) as HTMLElement;
if (control && control.focus) {
control.focus();