fix: avoid crashes when emptying DatePicker's value (#2237)

* fix: avoid crashes when emptying DatePicker's value

* chore: better type
This commit is contained in:
被雨水过滤的空气-Rain 2023-07-13 14:12:53 +08:00 committed by GitHub
parent 11d127e3a4
commit 623ffc9c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));