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: display error in font family (#1700)

Ran Luo8c2282b17488
diff --git a/packages/ui/src/components/font-family/FontFamily.tsx b/packages/ui/src/components/font-family/FontFamily.tsx
index f2910c90dd..f7857455e0 100644
--- a/packages/ui/src/components/font-family/FontFamily.tsx
+++ b/packages/ui/src/components/font-family/FontFamily.tsx
@@ -16,7 +16,7 @@
import { LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import React from 'react';
+import React, { useMemo } from 'react';
import styles from './index.module.less';
import type { IFontFamilyProps } from './interface';
@@ -26,9 +26,21 @@ export const FontFamily = (props: IFontFamilyProps) => {
const localeService = useDependency(LocaleService);
+ const viewValue = useMemo(() => {
+ let fontFamily = localeService.t(`fontFamily.${(`${value}` ?? '').replace(/\s/g, '')}`);
+
+ // Handle font family from copy paste.
+ if (fontFamily.startsWith('fontFamily.') && typeof value === 'string') {
+ fontFamily = value.split(',')[0];
+ }
+
+ return fontFamily;
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [value]);
+
return (
<div className={styles.uiPluginSheetsFontFamily} style={{ fontFamily: value as string }}>
- {localeService.t(`fontFamily.${(`${value}` ?? '').replace(/\s/g, '')}`)}
+ {viewValue}
</div>
);
};