From ada59b9d37638752eecda0cc1a2484e04aa34973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 11 Jun 2020 22:25:58 +0800 Subject: [PATCH] fix: Field id (#24929) --- components/form/FormItem.tsx | 4 +++- components/form/__tests__/index.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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'); + }); });