-
-
Notifications
You must be signed in to change notification settings - Fork 334
fix: When value is null, the dateString in onchange is null #942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain仅在 clear(value 为 null)时将 dateStrings 置为 null,避免扩大行为面;并显式比较 null 当前实现对第二参采用 建议:
可按如下修改: - const everyEmpty = clone.every((val) => !val);
+ const everyEmpty = clone.every((val) => val == null);
onChange(
// Return null directly if all date are empty
- isNullValue && everyEmpty ? null : clone,
- everyEmpty ? null : getDateTexts(clone),
+ isNullValue && everyEmpty ? null : clone,
+ isNullValue && everyEmpty ? null : getDateTexts(clone),
); [uggest_recommended_refactor] 为确保类型一致性,请确认 🏁 Script executed: #!/bin/bash
# 查找 RangePicker 与 Picker 的 onChange 类型定义
rg -nP -C3 '\binterface\s+RangePickerProps\b[\s\S]*?\bonChange\?\s*:\s*\(' --type ts --type tsx
rg -nP -C3 '\binterface\s+PickerProps\b[\s\S]*?\bonChange\?\s*:\s*\(' --type ts --type tsx
# 查找 ReplaceListType 定义
rg -nP -C2 'type\s+ReplaceListType' --type ts Length of output: 336 🏁 Script executed: #!/bin/bash
# 查找 RangePickerProps 与 PickerProps 类型定义
rg -nP 'interface\s+RangePickerProps\b' -n -g '*.ts' -g '*.tsx'
rg -nP 'interface\s+PickerProps\b' -n -g '*.ts' -g '*.tsx'
# 查找所有 onChange? 签名,确认第二参数是否允许 null
rg -nP 'onChange\?\s*:' -n -g '*.ts' -g '*.tsx' Length of output: 779 🏁 Script executed: #!/bin/bash
# 查看 RangePickerProps 接口及 onChange 签名
rg -nP -C5 'interface\s+RangePickerProps' -n src/PickerInput/RangePicker.tsx
rg -nP -C5 'onChange\?:' -n src/PickerInput/RangePicker.tsx
# 查看 PickerProps 接口及 onChange 签名
rg -nP -C5 'interface\s+PickerProps' -n src/PickerInput/SinglePicker.tsx
rg -nP -C5 'onChange\?:' -n src/PickerInput/SinglePicker.tsx Length of output: 2090 修复类型定义并仅在 clear 时将 dateStrings 设为 null
🤖 Prompt for AI Agents
|
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好,这个改动将
dateString
在清空时设置为null
,这与onChange
回调函数在PickerProps
和RangePickerProps
中的类型定义不一致,可能会导致 TypeScript 编译错误。例如,在
RangePickerProps
中,dateStrings
的类型是[string, string]
,并不接受null
。在
PickerProps
(用于SinglePicker
) 中,dateString
的类型是string | string[]
,同样不接受null
。虽然测试用例已经更新以适应
null
值,但 TypeScript 的类型定义也需要同步更新,以避免给库的使用者带来类型错误。建议在
src/PickerInput/RangePicker.tsx
和src/PickerInput/SinglePicker.tsx
中更新onChange
的类型定义,以允许dateString
/dateStrings
为null
。