Skip to content

Commit

Permalink
fix: should not reset showDate when value is empty array, close: ant-…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui authored Apr 26, 2017
1 parent 286fc96 commit 44c4d5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion components/date-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import Icon from '../icon';
import { getLocaleCode } from '../_util/getLocale';
import warning from '../_util/warning';

function getShowDateFromValue(value: moment.Moment[]): moment.Moment[] {
function getShowDateFromValue(value: moment.Moment[]): moment.Moment[] | undefined {
const [ start, end ] = value;
// value could be an empty array, then we should not reset showDate
if (!start && !end) {
return;
}
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
return [start, newEnd];
}
Expand Down
16 changes: 16 additions & 0 deletions components/date-picker/__tests__/RangePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ describe('RangePicker', () => {
expect(render(wrapper.find('Trigger').node.getComponent()))
.toMatchSnapshot();
});

// issue: https://github.com/ant-design/ant-design/issues/5872
it('should not throw error when value is reset to `[]`', () => {
const birthday = moment('2000-01-01', 'YYYY-MM-DD');
const wrapper = mount(
<RangePicker
getCalendarContainer={trigger => trigger}
value={[birthday, birthday]}
open
/>
);
wrapper.setProps({ value: [] });
const rangeCalendarWrapper = mount(wrapper.find('Trigger').node.getComponent());
expect(() => rangeCalendarWrapper.find('.ant-calendar-today').simulate('click').simulate('click'))
.not.toThrow();
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"omit.js": "^0.1.0",
"prop-types": "^15.5.7",
"rc-animate": "~2.3.0",
"rc-calendar": "~8.0.0",
"rc-calendar": "~8.1.0",
"rc-cascader": "~0.11.0",
"rc-checkbox": "~1.5.0",
"rc-collapse": "~1.7.0",
Expand Down

0 comments on commit 44c4d5c

Please sign in to comment.