Skip to content

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.

fix(editor): add valid attribute (#1730)

Univer2dee2686141b
diff --git a/packages/ui/src/components/editor/TextEditor.tsx b/packages/ui/src/components/editor/TextEditor.tsx
index c12e7eaace..492b8f0aa3 100644
--- a/packages/ui/src/components/editor/TextEditor.tsx
+++ b/packages/ui/src/components/editor/TextEditor.tsx
@@ -80,6 +80,8 @@ export interface ITextEditorProps {
onValid?: (state: boolean) => void; // Editor input value validation, currently effective only under onlyRange and onlyFormula conditions.
placeholder?: string; // Placeholder text.
+
+ isValueValid?: boolean; // Whether the value is valid.
}
/**
@@ -113,6 +115,8 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
onValid,
placeholder = '',
+
+ isValueValid = true,
} = props;
const editorService = useDependency(IEditorService);
@@ -121,7 +125,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
const [validationContent, setValidationContent] = useState<string>('');
- const [validationVisible, setValidationVisible] = useState(false);
+ const [validationVisible, setValidationVisible] = useState(isValueValid);
const [validationOffset, setValidationOffset] = useState<[number, number]>([0, 0]);
@@ -244,6 +248,10 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
editorService.setValueNoRefresh(value, id);
}, [value]);
+ useEffect(() => {
+ setValidationVisible(isValueValid);
+ }, [isValueValid]);
+
function hasValue() {
const value = editorService.getValue(id);
if (value == null) {