Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-data-validation): date dropdown display error on invalid value (#3055)
zhangw2e899831bde8
diff --git a/packages/sheets-data-validation/src/views/date-dropdown/index.tsx b/packages/sheets-data-validation/src/views/date-dropdown/index.tsxindex 1530f6ee71..f14d3756af 100644--- a/packages/sheets-data-validation/src/views/date-dropdown/index.tsx+++ b/packages/sheets-data-validation/src/views/date-dropdown/index.tsx@@ -16,7 +16,7 @@import React, { useState } from 'react';import type { CellValue, Nullable } from '@univerjs/core';-import { DataValidationErrorStyle, ICommandService, useDependency } from '@univerjs/core';+import { DataValidationErrorStyle, ICommandService, LocaleService, useDependency } from '@univerjs/core';import { Button, DatePanel } from '@univerjs/design';import { SetRangeValuesCommand } from '@univerjs/sheets';import dayjs from 'dayjs';@@ -60,16 +60,17 @@ export function DateDropdown(props: IDropdownComponentProps) {const [localDate, setLocalDate] = useState<dayjs.Dayjs | undefined>(originDate);const showTime = Boolean(rule?.bizInfo?.showTime);const date = localDate && localDate.isValid() ? localDate : dayjs();+ const localeService = useDependency(LocaleService);if (!cellData || !rule || !validator) {return;}const handleSave = async () => {- if (!localDate) {+ if (!date) {return;}- const newValue = localDate;+ const newValue = date;// convert current date to utc dateconst dateStr = `${newValue.format(showTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD 00:00:00').split(' ').join('T')}Z`;const serialTime = timestamp2SerialTime(dayjs(dateStr).unix());@@ -117,8 +118,8 @@ export function DateDropdown(props: IDropdownComponentProps) {return (<div className={styles.dvDateDropdown}><DatePanel- defaultValue={localDate}- pickerValue={localDate ?? date}+ defaultValue={date}+ pickerValue={date}showTime={showTime || undefined}onSelect={async (newValue) => {setLocalDate(newValue);@@ -128,8 +129,8 @@ export function DateDropdown(props: IDropdownComponentProps) {}}/><div className={styles.dvDateDropdownBtns}>- <Button size="small" type="primary" onClick={handleSave} disabled={!localDate}>- 确定+ <Button size="small" type="primary" onClick={handleSave} disabled={!date.isValid()}>+ {localeService.t('dataValidation.alert.ok')}</Button></div></div>