mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 13:08:41 +08:00
fix(DatePicker): locale in DatePicker cannot override ConfigProvider locale (#30380)
* fix(DatePicker): locale in DatePicker cannot override ConfigProvider locale close #30374 * fix: DatePicker.RangePicker * test: add test
This commit is contained in:
parent
836163adc0
commit
1699754bd5
@ -4,6 +4,9 @@ import moment from 'moment';
|
|||||||
import DatePicker from '..';
|
import DatePicker from '..';
|
||||||
import LocaleProvider from '../../locale-provider';
|
import LocaleProvider from '../../locale-provider';
|
||||||
import locale from '../../locale-provider/zh_CN';
|
import locale from '../../locale-provider/zh_CN';
|
||||||
|
import ConfigProvider from '../../config-provider';
|
||||||
|
import jaJP from '../../locale/ja_JP';
|
||||||
|
import zhTW from '../locale/zh_TW';
|
||||||
|
|
||||||
const { MonthPicker, WeekPicker } = DatePicker;
|
const { MonthPicker, WeekPicker } = DatePicker;
|
||||||
|
|
||||||
@ -53,3 +56,23 @@ describe('MonthPicker and WeekPicker', () => {
|
|||||||
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Override locale setting of the ConfigProvider', () => {
|
||||||
|
it('DatePicker', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<ConfigProvider locale={jaJP}>
|
||||||
|
<DatePicker locale={zhTW} />
|
||||||
|
</ConfigProvider>,
|
||||||
|
);
|
||||||
|
expect(wrapper.find('input').props().placeholder).toEqual('請選擇日期');
|
||||||
|
});
|
||||||
|
it('RangePicker', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<ConfigProvider locale={jaJP}>
|
||||||
|
<DatePicker.RangePicker locale={zhTW} />
|
||||||
|
</ConfigProvider>,
|
||||||
|
);
|
||||||
|
expect(wrapper.find('input').at(0).props().placeholder).toEqual('開始日期');
|
||||||
|
expect(wrapper.find('input').at(1).props().placeholder).toEqual('結束日期');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -35,20 +35,8 @@ export default function generateRangePicker<DateType>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getDefaultLocale = () => {
|
renderPicker = (contextLocale: PickerLocale) => {
|
||||||
const { locale } = this.props;
|
const locale = { ...contextLocale, ...this.props.locale };
|
||||||
const result = {
|
|
||||||
...enUS,
|
|
||||||
...locale,
|
|
||||||
};
|
|
||||||
result.lang = {
|
|
||||||
...result.lang,
|
|
||||||
...((locale || {}) as PickerLocale).lang,
|
|
||||||
};
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
renderPicker = (locale: PickerLocale) => {
|
|
||||||
const { getPrefixCls, direction, getPopupContainer } = this.context;
|
const { getPrefixCls, direction, getPopupContainer } = this.context;
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
@ -117,7 +105,7 @@ export default function generateRangePicker<DateType>(
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<LocaleReceiver componentName="DatePicker" defaultLocale={this.getDefaultLocale}>
|
<LocaleReceiver componentName="DatePicker" defaultLocale={enUS}>
|
||||||
{this.renderPicker}
|
{this.renderPicker}
|
||||||
</LocaleReceiver>
|
</LocaleReceiver>
|
||||||
);
|
);
|
||||||
|
@ -58,20 +58,8 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getDefaultLocale = () => {
|
renderPicker = (contextLocale: PickerLocale) => {
|
||||||
const { locale } = this.props;
|
const locale = { ...contextLocale, ...this.props.locale };
|
||||||
const result = {
|
|
||||||
...enUS,
|
|
||||||
...locale,
|
|
||||||
};
|
|
||||||
result.lang = {
|
|
||||||
...result.lang,
|
|
||||||
...((locale || {}) as PickerLocale).lang,
|
|
||||||
};
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
renderPicker = (locale: PickerLocale) => {
|
|
||||||
const { getPrefixCls, direction, getPopupContainer } = this.context;
|
const { getPrefixCls, direction, getPopupContainer } = this.context;
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
@ -148,7 +136,7 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<LocaleReceiver componentName="DatePicker" defaultLocale={this.getDefaultLocale}>
|
<LocaleReceiver componentName="DatePicker" defaultLocale={enUS}>
|
||||||
{this.renderPicker}
|
{this.renderPicker}
|
||||||
</LocaleReceiver>
|
</LocaleReceiver>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user