Skip to content

Commit

Permalink
fix(date-picker): showTime should work correctly when format is function
Browse files Browse the repository at this point in the history
  • Loading branch information
kerm1it committed Oct 14, 2020
1 parent 43e2651 commit 0bc651e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/date-picker/__tests__/DatePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ describe('DatePicker', () => {
.length,
).toBe(60);
});
it('showTime should work correctly when format is custom function', () => {
const wrapper = mount(
<DatePicker defaultValue={moment()} showTime format={val => val.format('YYYY-MM-DD')} open />,
);
const input = wrapper.find('input').simulate('mousedown');
expect(input.simulate.bind(input, 'focus')).not.toThrowError();
});

it('12 hours', () => {
const wrapper = mount(
Expand Down
5 changes: 5 additions & 0 deletions components/date-picker/generatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export function getTimeProps<DateType>(
return showTimeObj;
}

if (typeof firstFormat === 'function') {
// format of showTime should use default when format is custom format function
delete showTimeObj.format;
}

return {
showTime: showTimeObj,
};
Expand Down

0 comments on commit 0bc651e

Please sign in to comment.