Skip to content
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

fix(DateInputRange): 表单中使用清除无效问题 #808

Merged
merged 1 commit into from
May 10, 2022
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 packages/react-date-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ function Demo(){
if (current.date) {
Notify.success({
title: '提交成功!',
description: `表单提交时间成功,时间为:${current.date}`,
description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange}`,
});
} else {
Notify.error({
title: '提交失败!',
description: `表单提交时间成功,时间为:${current.date},将自动填充初始化值!`,
description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange},将自动填充初始化值!`,
});
}
}}
Expand All @@ -123,6 +123,7 @@ function Demo(){
</Row>
<Row style={{ width: 200 }} >
<Col fixed>{fields.dateRange}</Col>
<Col fixed>{JSON.stringify(state)}</Col>
</Row>
<Row gutter={10}>
<Col>
Expand Down
7 changes: 6 additions & 1 deletion packages/react-date-input/src/DateInputRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export function DateInputRange<V extends string | Date>(props: DateInputRangePro
onChange && onChange(cdate, changeValue);
}

function clearDateRange() {
setDateRange([]);
onChange && onChange(undefined, []);
}

return (
<div
className={[`${prefixCls}-contents`, `${prefixCls}-inner`].filter(Boolean).join(' ').trim()}
Expand Down Expand Up @@ -105,7 +110,7 @@ export function DateInputRange<V extends string | Date>(props: DateInputRangePro
/>
</Popover>
{allowClear && dateRange.length > 0 && (
<Icon className={`${prefixCls}-close-btn`} color="#ccc" onClick={() => setDateRange([])} type="close" />
<Icon className={`${prefixCls}-close-btn`} color="#a5a5a5" onClick={() => clearDateRange()} type="close" />
)}
</div>
);
Expand Down