Skip to content

Commit ee36ed8

Browse files
committed
fix(fonts): the font list keeps its names readable and previews the face on a sample
1 parent 1bcf7e7 commit ee36ed8

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎src/components/Fonts/FontManager.test.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ describe("FontManager delete owners", () => {
129129
});
130130

131131
describe("FontManager preview face", () => {
132-
it("draws a cached font's name in the face the cache registered", () => {
132+
it("draws a sample beside a cached font's name in the face the cache registered, and the name in the UI face", () => {
133133
const r = render(<FontManager />);
134-
expect(r.getByTitle("E:ARIAL.TTF").style.fontFamily).toMatch(/^"zpl-/);
134+
const name = r.getByTitle("E:ARIAL.TTF");
135+
expect(name.style.fontFamily).toBe("");
136+
expect((name.nextElementSibling as HTMLElement).style.fontFamily).toMatch(/^"zpl-/);
135137
});
136138

137139
it("names a font no browser face took, and leaves its row unstyled", async () => {
@@ -151,7 +153,7 @@ describe("FontManager preview face", () => {
151153
}
152154
const r = render(<FontManager />);
153155
expect(r.getByText(/cannot render this font/)).toBeTruthy();
154-
expect(r.getByTitle("E:BROKEN.TTF").style.fontFamily).toBe("");
156+
expect(r.getByTitle("E:BROKEN.TTF").nextElementSibling).toBeNull();
155157
});
156158
});
157159

‎src/components/Fonts/FontManager.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,16 @@ function FontEntry({
274274
return (
275275
<div className="flex flex-col gap-0.5 px-2 py-1.5 rounded border border-transparent hover:border-border-2 hover:bg-surface-2 transition-colors">
276276
<div className="grid grid-cols-[1fr_3rem_auto] items-center gap-2">
277-
<span
278-
className="font-mono text-xs text-text truncate"
279-
style={cachedFontFaceStyle(previewFamily)}
280-
title={name}
281-
>
282-
{name}
277+
<span className="flex items-center gap-2 min-w-0">
278+
<span className="font-mono text-xs text-text truncate" title={name}>
279+
{name}
280+
</span>
281+
{/* The face shows on a sample, not on the name, so a display font leaves the name readable. */}
282+
{previewFamily && (
283+
<span className="text-sm leading-none text-muted shrink-0" style={cachedFontFaceStyle(previewFamily)} aria-hidden="true">
284+
Aa
285+
</span>
286+
)}
283287
</span>
284288
<Tooltip
285289
className="w-full"

0 commit comments

Comments
 (0)