Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DatePicker2): after entering a customized date format and pressing Enter, the value should not change,closed alibaba-fusion#4896 #4929

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions components/date-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<DatePicker
defaultVisible
value={value}
format={'DD/MM/YYYY'}
outputFormat="YYYY-MM-DD"
onChange={v => {
setValue(v),
assert(
v === dayjs('12/02/2020', 'DD/MM/YYYY').format('YYYY-MM-DD')
);
}}
/>
);
}
wrapper = mount(<App />);
changeInput('12/02/2020');
findInput().simulate('keydown', { keyCode: KEYCODE.ENTER });
assert(getStrValue(wrapper) === '12/02/2020');
});
});
});

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
Loading