From f68e517fdf3867f51ee7237fa04b25751339c230 Mon Sep 17 00:00:00 2001 From: GCHHCG <3124485281@qq.com> Date: Fri, 6 Sep 2024 17:34:59 +0800 Subject: [PATCH] fix(DatePicker2): after entering a customized date format and pressing Enter, the value should not change,closed #4896 --- .../date-picker2/__tests__/index-spec.js | 25 +++++++++++++++++++ components/date-picker2/picker.jsx | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/components/date-picker2/__tests__/index-spec.js b/components/date-picker2/__tests__/index-spec.js index d2d7764938..93e5989378 100644 --- a/components/date-picker2/__tests__/index-spec.js +++ b/components/date-picker2/__tests__/index-spec.js @@ -1232,6 +1232,31 @@ describe('Picker', () => { findInput(0).simulate('keydown', { keyCode: KEYCODE.SPACE }); assert(getStrValue(wrapper).join(',') === '2020-11-11 ,'); }) + + // fix https://github.com/alibaba-fusion/next/issues/4896 + it('After entering a customized date format and pressing Enter, the value should not change', () => { + function App() { + const [value, setValue] = useState(''); + return ( + { + setValue(v), + assert( + v === dayjs('12/02/2020', 'DD/MM/YYYY').format('YYYY-MM-DD') + ); + }} + /> + ); + } + wrapper = mount(); + changeInput('12/02/2020'); + findInput().simulate('keydown', { keyCode: KEYCODE.ENTER }); + assert(getStrValue(wrapper) === '12/02/2020'); + }); }); }); diff --git a/components/date-picker2/picker.jsx b/components/date-picker2/picker.jsx index 16522897a4..049f8158d7 100644 --- a/components/date-picker2/picker.jsx +++ b/components/date-picker2/picker.jsx @@ -440,7 +440,7 @@ class Picker extends React.Component { const isTemporary = showOk && !forceEvents.includes(eventType); // 面板收起时候,将值设置为确认值 - v = eventType === 'VISIBLE_CHANGE' ? value : this.checkValue(v, !isTemporary); + v = eventType === 'VISIBLE_CHANGE' ? value : this.checkValue(v, !isTemporary, format); this.setState({ curValue: v,