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:
parent
11d127e3a4
commit
623ffc9c57
@ -44,7 +44,7 @@ export interface Moment2strOptions {
|
|||||||
picker?: 'year' | 'month' | 'week' | 'quarter';
|
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;
|
const { showTime, gmt, picker, utc = true } = options;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return value;
|
return value;
|
||||||
@ -71,9 +71,9 @@ export const mapDatePicker = function () {
|
|||||||
...props,
|
...props,
|
||||||
format: format,
|
format: format,
|
||||||
value: str2moment(props.value, props),
|
value: str2moment(props.value, props),
|
||||||
onChange: (value: Dayjs) => {
|
onChange: (value: Dayjs | null) => {
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
if (!props.showTime) {
|
if (!props.showTime && value) {
|
||||||
value = value.startOf('day');
|
value = value.startOf('day');
|
||||||
}
|
}
|
||||||
onChange(moment2str(value, props));
|
onChange(moment2str(value, props));
|
||||||
|
Loading…
Reference in New Issue
Block a user