From 623ffc9c57017ef578a70163c2b9ad7f5694637e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Thu, 13 Jul 2023 14:12:53 +0800 Subject: [PATCH] fix: avoid crashes when emptying DatePicker's value (#2237) * fix: avoid crashes when emptying DatePicker's value * chore: better type --- .../client/src/schema-component/antd/date-picker/util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/date-picker/util.ts b/packages/core/client/src/schema-component/antd/date-picker/util.ts index aa0a810ae..e037070bd 100644 --- a/packages/core/client/src/schema-component/antd/date-picker/util.ts +++ b/packages/core/client/src/schema-component/antd/date-picker/util.ts @@ -44,7 +44,7 @@ export interface Moment2strOptions { picker?: 'year' | 'month' | 'week' | 'quarter'; } -export const moment2str = (value?: Dayjs, options: Moment2strOptions = {}) => { +export const moment2str = (value?: Dayjs | null, options: Moment2strOptions = {}) => { const { showTime, gmt, picker, utc = true } = options; if (!value) { return value; @@ -71,9 +71,9 @@ export const mapDatePicker = function () { ...props, format: format, value: str2moment(props.value, props), - onChange: (value: Dayjs) => { + onChange: (value: Dayjs | null) => { if (onChange) { - if (!props.showTime) { + if (!props.showTime && value) { value = value.startOf('day'); } onChange(moment2str(value, props));