Skip to content

Commit

Permalink
fix(DatePicker2): pressing enter should correctly display the formatt…
Browse files Browse the repository at this point in the history
…ed value
  • Loading branch information
GCHHCG committed Sep 6, 2024
1 parent c5ba17c commit 9a26aeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions components/date-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ describe('Picker', () => {
wrapper.unmount();
});

it('pressing enter should correctly display the formatted value', () => {
wrapper = mount(<DatePicker format={v => v.format('DD/MM/YYYY')}/>);
changeInput('2020/02/12');
findInput().simulate('keydown', { keyCode: KEYCODE.ENTER });
assert(getStrValue(wrapper) === dayjs('2020/02/12').format('DD/MM/YYYY'));
})

it('outputFormat', () => {
wrapper = mount(
<DatePicker
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker2/picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9a26aeb

Please sign in to comment.