Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix(editor): ensure font picker font names are not quoted (#11036)

David Luzar4a5c9e990ca2
diff --git a/packages/excalidraw/components/FontPicker/FontPickerList.tsx b/packages/excalidraw/components/FontPicker/FontPickerList.tsx
index e5e7b85aea..5d107cbeb1 100644
--- a/packages/excalidraw/components/FontPicker/FontPickerList.tsx
+++ b/packages/excalidraw/components/FontPicker/FontPickerList.tsx
@@ -46,6 +46,7 @@ import {
import { fontPickerKeyHandler } from "./keyboardNavHandlers";
import type { JSX } from "react";
+import type { ExcalidrawFontFace } from "../../fonts/ExcalidrawFontFace";
export interface FontDescriptor {
value: number;
@@ -86,6 +87,15 @@ const getFontFamilyIcon = (fontFamily: FontFamilyValues): JSX.Element => {
}
};
+const getFontFamilyLabel = (
+ fontFamily: FontFamilyValues,
+ fontFaces: ExcalidrawFontFace[],
+) =>
+ // prefer our config as the browser resolved names may be wrapped in quotes and such
+ Object.entries(FONT_FAMILY).find(([, id]) => id === fontFamily)?.[0] ??
+ fontFaces[0]?.fontFace?.family ??
+ "Unknown";
+
export const FontPickerList = React.memo(
({
selectedFontFamily,
@@ -114,7 +124,7 @@ export const FontPickerList = React.memo(
const fontDescriptor = {
value: familyId,
icon: getFontFamilyIcon(familyId),
- text: fontFaces[0]?.fontFace?.family ?? "Unknown",
+ text: getFontFamilyLabel(familyId, fontFaces),
};
if (metadata.deprecated) {