Skip to content

Commit

Permalink
fix: Form validateMessages in nested ConfigProvider (#33705)
Browse files Browse the repository at this point in the history
close #33691
  • Loading branch information
afc163 committed Jan 13, 2022
1 parent a8495ba commit 2d484bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 1 addition & 3 deletions components/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {

let childNode = children;
// Additional Form provider
let validateMessages: ValidateMessages = {
...defaultLocale.Form?.defaultValidateMessages,
};
let validateMessages: ValidateMessages = {};

if (locale) {
validateMessages =
Expand Down
21 changes: 12 additions & 9 deletions components/form/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -613,23 +614,25 @@ 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
<ConfigProvider>
<Form>
<Form.Item name="test" label="Bamboo" rules={[{ required: true }]}>
<input />
</Form.Item>
</Form>
<ConfigProvider locale={zhCN}>
<ConfigProvider>
<Form>
<Form.Item name="test" label="Bamboo" rules={[{ required: true }]}>
<input />
</Form.Item>
</Form>
</ConfigProvider>
</ConfigProvider>,
);

wrapper.find('form').simulate('submit');
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 () => {
Expand Down

0 comments on commit 2d484bb

Please sign in to comment.