Skip to content

Commit 04eb328

Browse files
author
刘欢
committed
fix: When value is null dateString=null
1 parent c339367 commit 04eb328

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
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/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)