Skip to content

Commit f1790c6

Browse files
committed
fix: End time can not typing before start time
1 parent 153844e commit f1790c6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Picker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
118118
suffixIcon,
119119
clearIcon,
120120
disabled,
121+
disabledDate,
121122
placeholder,
122123
getPopupContainer,
123124
inputRef,
@@ -241,7 +242,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
241242
text,
242243
formatList,
243244
);
244-
if (inputDate) {
245+
if (inputDate && (!disabledDate || !disabledDate(inputDate))) {
245246
setSelectedValue(inputDate);
246247
}
247248
};

tests/range.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import MockDate from 'mockdate';
3+
import KeyCode from 'rc-util/lib/KeyCode';
34
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
45
import { Moment } from 'moment';
56
import {
@@ -506,4 +507,31 @@ describe('Range', () => {
506507
expect(onPanelChange.mock.calls[0][1]).toEqual(['month', 'month']);
507508
});
508509
});
510+
511+
it('type can not change before start time', () => {
512+
const onChange = jest.fn();
513+
const wrapper = mount(
514+
<MomentRangePicker
515+
defaultValue={[getMoment('2000-01-15'), getMoment('2000-01-16')]}
516+
onChange={onChange}
517+
/>,
518+
);
519+
520+
wrapper
521+
.find('input')
522+
.last()
523+
.simulate('change', {
524+
target: {
525+
value: '2000-01-11',
526+
},
527+
});
528+
wrapper
529+
.find('input')
530+
.last()
531+
.simulate('keyDown', {
532+
which: KeyCode.ENTER,
533+
});
534+
535+
expect(onChange).not.toHaveBeenCalled();
536+
});
509537
});

0 commit comments

Comments
 (0)