Skip to content

Commit

Permalink
fix: Hacker0x01#4594 fix setSelected
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki0410-dev committed Mar 16, 2024
1 parent 72ded5b commit 77f3516
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ export default class DatePicker extends React.Component {
if (noRanges) {
onChange([changedDate, null], event);
} else if (hasStartRange) {
if (isDateBefore(changedDate, startDate)) {
if (changedDate === null) {
onChange([null, null], event);
} else if (isDateBefore(changedDate, startDate)) {
onChange([changedDate, null], event);
} else {
onChange([startDate, changedDate], event);
Expand Down
24 changes: 24 additions & 0 deletions test/datepicker_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,30 @@ describe("DatePicker", () => {
});
expect(cleared).toBe(true);
});
it("should correctly clear date with empty input string (selectsRange)", () => {
let instance;
const onChangeSpy = jest.fn();

render(
<DatePicker
ref={(node) => {
instance = node;
}}
selectsRange
startDate={utils.newDate("2016-11-22")}
endDate={null}
onChange={onChangeSpy}
isClearable
/>,
);
fireEvent.change(instance.input, {
target: {
value: "",
},
});

expect(onChangeSpy.mock.calls.at(-1)[0]).toStrictEqual([null, null]);
});
it("should correctly update the input when the value prop changes", () => {
let instance;
const { rerender } = render(
Expand Down

0 comments on commit 77f3516

Please sign in to comment.