diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index 077c2ebf23..ff45b49d11 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -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([...toArray(trigger), ...toArray(validateTrigger)]); diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index b80f563a7f..6a1624786f 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -573,4 +573,16 @@ describe('Form', () => { ); expect(errorSpy).not.toHaveBeenCalled(); }); + + it('should customize id work', () => { + const wrapper = mount( +
+ + + +
, + ); + + expect(wrapper.find('input').prop('id')).toEqual('bamboo'); + }); });