diff --git a/components/date-picker/__tests__/other.test.js b/components/date-picker/__tests__/other.test.js index c7bde7f6eb..e79cf9902a 100644 --- a/components/date-picker/__tests__/other.test.js +++ b/components/date-picker/__tests__/other.test.js @@ -4,6 +4,9 @@ import moment from 'moment'; import DatePicker from '..'; import LocaleProvider from '../../locale-provider'; 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; @@ -53,3 +56,23 @@ describe('MonthPicker and WeekPicker', () => { expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot(); }); }); + +describe('Override locale setting of the ConfigProvider', () => { + it('DatePicker', () => { + const wrapper = mount( + + + , + ); + expect(wrapper.find('input').props().placeholder).toEqual('請選擇日期'); + }); + it('RangePicker', () => { + const wrapper = mount( + + + , + ); + expect(wrapper.find('input').at(0).props().placeholder).toEqual('開始日期'); + expect(wrapper.find('input').at(1).props().placeholder).toEqual('結束日期'); + }); +}); diff --git a/components/date-picker/generatePicker/generateRangePicker.tsx b/components/date-picker/generatePicker/generateRangePicker.tsx index bc8743e406..7b2463dd7b 100644 --- a/components/date-picker/generatePicker/generateRangePicker.tsx +++ b/components/date-picker/generatePicker/generateRangePicker.tsx @@ -35,20 +35,8 @@ export default function generateRangePicker( } }; - getDefaultLocale = () => { - const { locale } = this.props; - const result = { - ...enUS, - ...locale, - }; - result.lang = { - ...result.lang, - ...((locale || {}) as PickerLocale).lang, - }; - return result; - }; - - renderPicker = (locale: PickerLocale) => { + renderPicker = (contextLocale: PickerLocale) => { + const locale = { ...contextLocale, ...this.props.locale }; const { getPrefixCls, direction, getPopupContainer } = this.context; const { prefixCls: customizePrefixCls, @@ -117,7 +105,7 @@ export default function generateRangePicker( render() { return ( - + {this.renderPicker} ); diff --git a/components/date-picker/generatePicker/generateSinglePicker.tsx b/components/date-picker/generatePicker/generateSinglePicker.tsx index cba076dedc..9b0cd681e8 100644 --- a/components/date-picker/generatePicker/generateSinglePicker.tsx +++ b/components/date-picker/generatePicker/generateSinglePicker.tsx @@ -58,20 +58,8 @@ export default function generatePicker(generateConfig: GenerateConfig< } }; - getDefaultLocale = () => { - const { locale } = this.props; - const result = { - ...enUS, - ...locale, - }; - result.lang = { - ...result.lang, - ...((locale || {}) as PickerLocale).lang, - }; - return result; - }; - - renderPicker = (locale: PickerLocale) => { + renderPicker = (contextLocale: PickerLocale) => { + const locale = { ...contextLocale, ...this.props.locale }; const { getPrefixCls, direction, getPopupContainer } = this.context; const { prefixCls: customizePrefixCls, @@ -148,7 +136,7 @@ export default function generatePicker(generateConfig: GenerateConfig< render() { return ( - + {this.renderPicker} );