Skip to content

Commit 9c85cb5

Browse files
authoredMay 10, 2022
fix(DateInputRange): 表单中使用清除无效问题 (#808)
1 parent 3ac20e1 commit 9c85cb5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎packages/react-date-input/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ function Demo(){
9191
if (current.date) {
9292
Notify.success({
9393
title: '提交成功!',
94-
description: `表单提交时间成功,时间为:${current.date}`,
94+
description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange}`,
9595
});
9696
} else {
9797
Notify.error({
9898
title: '提交失败!',
99-
description: `表单提交时间成功,时间为:${current.date},将自动填充初始化值!`,
99+
description: `表单提交时间成功,时间为:${current.date} range:${current.dateRange},将自动填充初始化值!`,
100100
});
101101
}
102102
}}
@@ -123,6 +123,7 @@ function Demo(){
123123
</Row>
124124
<Row style={{ width: 200 }} >
125125
<Col fixed>{fields.dateRange}</Col>
126+
<Col fixed>{JSON.stringify(state)}</Col>
126127
</Row>
127128
<Row gutter={10}>
128129
<Col>

‎packages/react-date-input/src/DateInputRange.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export function DateInputRange<V extends string | Date>(props: DateInputRangePro
5050
onChange && onChange(cdate, changeValue);
5151
}
5252

53+
function clearDateRange() {
54+
setDateRange([]);
55+
onChange && onChange(undefined, []);
56+
}
57+
5358
return (
5459
<div
5560
className={[`${prefixCls}-contents`, `${prefixCls}-inner`].filter(Boolean).join(' ').trim()}
@@ -105,7 +110,7 @@ export function DateInputRange<V extends string | Date>(props: DateInputRangePro
105110
/>
106111
</Popover>
107112
{allowClear && dateRange.length > 0 && (
108-
<Icon className={`${prefixCls}-close-btn`} color="#ccc" onClick={() => setDateRange([])} type="close" />
113+
<Icon className={`${prefixCls}-close-btn`} color="#a5a5a5" onClick={() => clearDateRange()} type="close" />
109114
)}
110115
</div>
111116
);

0 commit comments

Comments
 (0)
Please sign in to comment.