From e4cddcb0253724a2579f7f2ba74b5382fa97f4db Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 13 Jan 2022 11:45:27 +0800 Subject: [PATCH] fix: Form validateMessages in nested ConfigProvider close #33691 --- components/config-provider/index.tsx | 4 +--- components/form/__tests__/index.test.js | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 82e3c804be53..bb98b5164aab 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -216,9 +216,7 @@ const ProviderChildren: React.FC = props => { let childNode = children; // Additional Form provider - let validateMessages: ValidateMessages = { - ...defaultLocale.Form?.defaultValidateMessages, - }; + let validateMessages: ValidateMessages = {}; if (locale) { validateMessages = diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index 324033707c94..f847fd2b9e66 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -13,6 +13,7 @@ import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { sleep } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; +import zhCN from '../../locale/zh_CN'; jest.mock('scroll-into-view-if-needed'); @@ -613,15 +614,17 @@ describe('Form', () => { expect(wrapper.find('.ant-form-item-explain').first().text()).toEqual('Bamboo is good!'); }); - it('should have default validateMessages in default locale', async () => { + // https://github.com/ant-design/ant-design/issues/33691 + it('should keep upper locale in nested ConfigProvider', async () => { const wrapper = mount( - // eslint-disable-next-line no-template-curly-in-string - -
- - - -
+ + +
+ + + +
+
, ); @@ -629,7 +632,7 @@ describe('Form', () => { await sleep(100); wrapper.update(); await sleep(100); - expect(wrapper.find('.ant-form-item-explain').first().text()).toEqual('Please enter Bamboo'); + expect(wrapper.find('.ant-form-item-explain').first().text()).toEqual('请输入Bamboo'); }); it('`name` support template when label is not provided', async () => {