Skip to content

Commit 0661d90

Browse files
EmilyyyLiu刘欢
andauthored
fix: When value is null, the dateString in onchange is null (#942)
* fix: When value is null dateString=null * feat: add test to multiple picker --------- Co-authored-by: 刘欢 <[email protected]>
1 parent c339367 commit 0661d90

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/PickerInput/hooks/useRangeValue.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,11 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
283283

284284
// Trigger `onChange` if needed
285285
if (onChange && !isSameMergedDates) {
286+
const everyEmpty = clone.every((val) => !val);
286287
onChange(
287288
// Return null directly if all date are empty
288-
isNullValue && clone.every((val) => !val) ? null : clone,
289-
getDateTexts(clone),
289+
isNullValue && everyEmpty ? null : clone,
290+
everyEmpty ? null : getDateTexts(clone),
290291
);
291292
}
292293
}

tests/multiple.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { fireEvent, render } from '@testing-library/react';
33
import { resetWarned } from '@rc-component/util/lib/warning';
44
import React from 'react';
5-
import { DayPicker, getDay, isOpen, openPicker, selectCell } from './util/commonUtil';
5+
import { clearValue, DayPicker, getDay, isOpen, openPicker, selectCell } from './util/commonUtil';
66

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

@@ -57,6 +57,8 @@ describe('Picker.Multiple', () => {
5757
]);
5858

5959
expect(onChange.mock.calls[0][0]).toHaveLength(3);
60+
clearValue();
61+
expect(onChange).toHaveBeenCalledWith(null, null);
6062
});
6163

6264
it('panel click to remove', () => {

tests/picker.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('Picker.Basic', () => {
283283
onChange.mockReset();
284284

285285
clearValue();
286-
expect(onChange).toHaveBeenCalledWith(null, '');
286+
expect(onChange).toHaveBeenCalledWith(null, null);
287287
expect(isOpen()).toBeFalsy();
288288

289289
openPicker(container);

tests/range.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe('Picker.Range', () => {
202202
expect(onChange).toHaveBeenCalledWith([expect.anything(), null], ['1990-09-11', '']);
203203

204204
clearValue();
205-
expect(onChange).toHaveBeenCalledWith(null, ['', '']);
205+
expect(onChange).toHaveBeenCalledWith(null, null);
206206
onChange.mockReset();
207207

208208
// Not allow empty with startDate

0 commit comments

Comments
 (0)