fix: FormItem required not work without name (#21168)

This commit is contained in:
二货机器人 2020-02-01 20:09:29 +08:00 committed by GitHub
parent 048a6e28a3
commit 074fa324b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -169,7 +169,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
])}
>
{/* Label */}
<FormItemLabel htmlFor={fieldId} {...props} required={isRequired} prefixCls={prefixCls} />
<FormItemLabel htmlFor={fieldId} required={isRequired} {...props} prefixCls={prefixCls} />
{/* Input Group */}
<FormItemInput
{...props}

View File

@ -417,4 +417,15 @@ describe('Form', () => {
);
expect(wrapper.find('.ant-form-item-explain').length).toBeTruthy();
});
// https://github.com/ant-design/ant-design/issues/21167
it('`require` without `name`', () => {
const wrapper = mount(
<Form.Item label="test" required>
<input />
</Form.Item>,
);
expect(wrapper.find('.ant-form-item-required')).toHaveLength(1);
});
});