Ignore invalid end date

Fix #9267
This commit is contained in:
Wei Zhu 2018-02-07 14:22:35 +08:00
parent 33e2ef0f8d
commit e992682aa8
3 changed files with 18 additions and 2 deletions

View File

@ -157,6 +157,9 @@ export default class RangePicker extends React.Component<any, RangePickerState>
}
handleCalendarInputSelect = (value: RangePickerValue) => {
if (!value[0]) {
return;
}
this.setState(({ showDate }) => ({
value,
showDate: getShowDateFromValue(value) || showDate,

View File

@ -3,6 +3,7 @@ import { mount, render } from 'enzyme';
import moment from 'moment';
import DatePicker from '../';
import { setMockDate, resetMockDate } from '../../../tests/utils';
import { selectDate } from './utils';
import focusTest from '../../../tests/shared/focusTest';
const { RangePicker } = DatePicker;
@ -202,4 +203,16 @@ describe('RangePicker', () => {
wrapper.find('.ant-calendar-range-quick-selector a').simulate('click');
expect(handleOk).toBeCalledWith(range);
});
// https://github.com/ant-design/ant-design/issues/9267
it('invali end date not throw error', () => {
const wrapper = mount(<RangePicker />);
wrapper.find('.ant-calendar-picker-input').simulate('click');
selectDate(wrapper, moment('2017-09-18'), 0);
selectDate(wrapper, moment('2017-10-18'), 1);
wrapper.find('.ant-calendar-picker-input').simulate('click');
expect(() =>
wrapper.find('.ant-calendar-input').at(1).simulate('change', { target: { value: '2016-01-01' } })
).not.toThrow();
});
});

View File

@ -1,8 +1,8 @@
/* eslint-disable import/prefer-default-export */
export function selectDate(wrapper, date, index) {
let calendar = wrapper;
if (index) {
calendar = wrapper.find('.ant-calendar-range-part')[index];
if (index !== undefined) {
calendar = wrapper.find('.ant-calendar-range-part').at(index);
}
calendar.find({ title: date.format('LL'), role: 'gridcell' }).simulate('click');
}