mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-05 23:46:28 +08:00
fix: Field id (#24929)
This commit is contained in:
parent
83b028c7fe
commit
ada59b9d37
@ -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)]);
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user