Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext

// Trigger `onChange` if needed
if (onChange && !isSameMergedDates) {
const everyEmpty = clone.every((val) => !val);
onChange(
// Return null directly if all date are empty
isNullValue && clone.every((val) => !val) ? null : clone,
getDateTexts(clone),
isNullValue && everyEmpty ? null : clone,
everyEmpty ? null : getDateTexts(clone),
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/multiple.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fireEvent, render } from '@testing-library/react';
import { resetWarned } from '@rc-component/util/lib/warning';
import React from 'react';
import { DayPicker, getDay, isOpen, openPicker, selectCell } from './util/commonUtil';
import { clearValue, DayPicker, getDay, isOpen, openPicker, selectCell } from './util/commonUtil';

const fakeTime = getDay('1990-09-03 00:00:00').valueOf();

Expand Down Expand Up @@ -57,6 +57,8 @@ describe('Picker.Multiple', () => {
]);

expect(onChange.mock.calls[0][0]).toHaveLength(3);
clearValue();
expect(onChange).toHaveBeenCalledWith(null, null);
});

it('panel click to remove', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe('Picker.Basic', () => {
onChange.mockReset();

clearValue();
expect(onChange).toHaveBeenCalledWith(null, '');
expect(onChange).toHaveBeenCalledWith(null, null);
expect(isOpen()).toBeFalsy();

openPicker(container);
Expand Down
2 changes: 1 addition & 1 deletion tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('Picker.Range', () => {
expect(onChange).toHaveBeenCalledWith([expect.anything(), null], ['1990-09-11', '']);

clearValue();
expect(onChange).toHaveBeenCalledWith(null, ['', '']);
expect(onChange).toHaveBeenCalledWith(null, null);
onChange.mockReset();

// Not allow empty with startDate
Expand Down