diff --git a/components/time-picker2/__tests__/index-spec.js b/components/time-picker2/__tests__/index-spec.js index 22f14589de..f260aef5d8 100644 --- a/components/time-picker2/__tests__/index-spec.js +++ b/components/time-picker2/__tests__/index-spec.js @@ -385,6 +385,21 @@ describe('TimePicker2', () => { done(); }, 1000); }); + + it('should support custom formatting , close #3651', () => { + const div = document.createElement('div'); + document.body.appendChild(div); + const wrapper = mount(, { attachTo: div }); + wrapper + .find('.next-time-picker2-input input') + .simulate('change', { target: { value: '12' } }); + wrapper.update(); + assert( + document + .querySelector('li[title="12"][role="option"]') + .classList.contains('next-selected') + ); + }); }); }); diff --git a/components/time-picker2/time-picker.jsx b/components/time-picker2/time-picker.jsx index f33911fcf7..882631ae13 100644 --- a/components/time-picker2/time-picker.jsx +++ b/components/time-picker2/time-picker.jsx @@ -402,11 +402,12 @@ class TimePicker2 extends Component { checkValue = (value, strictly) => { const { inputType } = this.state; - const formatter = v => (typeof v === 'string' ? datejs(v, 'HH:mm:ss') : v); + const { format, type, disabled } = this.props; + const formatter = v => (typeof v === 'string' ? datejs(v, format) : v); const formattedValue = Array.isArray(value) ? value.map(v => formatter(v)) : formatter(value); - return this.props.type === TIME_PICKER_TYPE.RANGE - ? checkRangeDate(formattedValue, inputType, this.props.disabled, strictly) + return type === TIME_PICKER_TYPE.RANGE + ? checkRangeDate(formattedValue, inputType, disabled, strictly) : checkDate(formattedValue); };