fix: Field id (#24929)

This commit is contained in:
二货机器人 2020-06-11 22:25:58 +08:00 committed by GitHub
parent 83b028c7fe
commit ada59b9d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -283,7 +283,6 @@ function FormItem(props: FormItemProps): React.ReactElement {
// ======================= Children =======================
const mergedControl: typeof control = {
...control,
id: fieldId,
};
let childNode: React.ReactNode = null;
@ -315,6 +314,9 @@ function FormItem(props: FormItemProps): React.ReactElement {
);
const childProps = { ...children.props, ...mergedControl };
if (!childProps.id) {
childProps.id = fieldId;
}
// We should keep user origin event handler
const triggers = new Set<string>([...toArray(trigger), ...toArray(validateTrigger)]);

View File

@ -573,4 +573,16 @@ describe('Form', () => {
);
expect(errorSpy).not.toHaveBeenCalled();
});
it('should customize id work', () => {
const wrapper = mount(
<Form>
<Form.Item name="light">
<Input id="bamboo" />
</Form.Item>
</Form>,
);
expect(wrapper.find('input').prop('id')).toEqual('bamboo');
});
});