fix: DatePicker date order (#17694)

* Fix selected time order #17346

* add test case
This commit is contained in:
mraiguo 2019-07-22 17:07:13 +08:00 committed by 偏右
parent 271b08192e
commit ebe9097689
2 changed files with 16 additions and 0 deletions

View File

@ -150,6 +150,9 @@ class RangePicker extends React.Component<any, RangePickerState> {
showDate: getShowDateFromValue(value) || showDate, showDate: getShowDateFromValue(value) || showDate,
})); }));
} }
if (value[0] && value[0].diff(value[1]) > 0) {
value[1] = undefined;
}
const [start, end] = value; const [start, end] = value;
props.onChange(value, [formatDate(start, props.format), formatDate(end, props.format)]); props.onChange(value, [formatDate(start, props.format), formatDate(end, props.format)]);
}; };

View File

@ -387,4 +387,17 @@ describe('RangePicker', () => {
).toBe(false); ).toBe(false);
}); });
}); });
// https://github.com/ant-design/ant-design/issues/17135
it('the end time should be less than the start time', () => {
const wrapper = mount(
<RangePicker defaultValue={[moment(), moment()]} />,
);
wrapper.find('.ant-calendar-picker-input').simulate('click');
const firstInput = wrapper.find('.ant-calendar-input').first();
const secondInput = wrapper.find('.ant-calendar-input').last();
firstInput.simulate('change', { target: { value: moment().add(1, 'day').format('YYYY-MM-DD')}});
expect(firstInput.getDOMNode().value).toBe(moment().add(1, 'day').format('YYYY-MM-DD'));
expect(secondInput.getDOMNode().value).toBe('');
});
}); });