From 984ae2a93de61977779fa69b8e57d7b1c81caa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AF=B8=E5=B2=B3?= Date: Wed, 3 Apr 2019 18:13:16 +0800 Subject: [PATCH] fix(TimePicker): prop locale should works, close #15813 --- .../__snapshots__/index.test.js.snap | 40 +++++++++++++++++++ .../time-picker/__tests__/index.test.js | 8 ++++ components/time-picker/index.tsx | 13 +++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/components/time-picker/__tests__/__snapshots__/index.test.js.snap b/components/time-picker/__tests__/__snapshots__/index.test.js.snap index 33ed64b7c739..839d2be4f4c3 100644 --- a/components/time-picker/__tests__/__snapshots__/index.test.js.snap +++ b/components/time-picker/__tests__/__snapshots__/index.test.js.snap @@ -39,6 +39,46 @@ exports[`TimePicker not render clean icon when allowClear is false 1`] = ` `; +exports[`TimePicker prop locale should works 1`] = ` + + + + + + + + +`; + exports[`TimePicker renders addon correctly 1`] = `
{
test
, ); }); + + it('prop locale should works', () => { + const locale = { + placeholder: 'Избери дата', + }; + const wrapper = mount(); + expect(wrapper.render()).toMatchSnapshot(); + }); }); diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx index bad8cbe7ab48..d01f479753bc 100644 --- a/components/time-picker/index.tsx +++ b/components/time-picker/index.tsx @@ -7,7 +7,7 @@ import classNames from 'classnames'; import warning from '../_util/warning'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; -import defaultLocale from './locale/en_US'; +import enUS from './locale/en_US'; import interopDefault from '../_util/interopDefault'; import Icon from '../icon'; @@ -54,6 +54,7 @@ export interface TimePickerProps { popupStyle?: React.CSSProperties; suffixIcon?: React.ReactNode; clearIcon?: React.ReactNode; + locale?: TimePickerLocale; } export interface TimePickerLocale { @@ -176,6 +177,14 @@ class TimePicker extends React.Component { return ; } + getDefaultLocale = () => { + const defaultLocale = { + ...enUS, + ...this.props.locale, + }; + return defaultLocale; + }; + renderTimePicker = (locale: TimePickerLocale) => ( {({ getPopupContainer: getContextPopupContainer, getPrefixCls }: ConfigConsumerProps) => { @@ -225,7 +234,7 @@ class TimePicker extends React.Component { render() { return ( - + {this.renderTimePicker} );