Skip to content

Commit 2c60a3e

Browse files
authored
fix: Fix font family bugs (#4184)
## Description 2 bugs are getting fixed here: 1. when opening fonts manager, we immediately set a value on blur, but when font manager is open this should not be needed 2. when on blur and onhighlight (dropdown) value is set, its not being parsed as css, so the entire stack: "Arial, Verdana, serif" becomes a value in a stack {type: 'fontFamily', value: ['Arial, Verdana,serif']} instead of {type: 'fontFamily', value: ['Arial', 'Verdana', 'serif']} ## Steps for reproduction 1. click button 3. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 6eae04d commit 2c60a3e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const FontFamilyControl = () => {
5555
value: label,
5656
}));
5757
}, [assetContainers]);
58+
const [isFontManagerOpen, setIsFontMangerOpen] = useState(false);
5859

5960
const itemValue = useMemo(() => {
6061
// Replacing the quotes just to make it look cleaner in the UI
@@ -67,6 +68,7 @@ export const FontFamilyControl = () => {
6768
suffix={
6869
<FloatingPanel
6970
title="Fonts"
71+
onOpenChange={setIsFontMangerOpen}
7072
content={
7173
<FontsManager
7274
value={value.type === "fontFamily" ? value : undefined}
@@ -83,9 +85,14 @@ export const FontFamilyControl = () => {
8385
items={items}
8486
itemToString={(item) => item?.label ?? item?.value ?? ""}
8587
onItemHighlight={(item) => {
86-
const value = item === null ? itemValue : item.value;
88+
if (item === null) {
89+
setValue(parseCssValue("fontFamily", itemValue), {
90+
isEphemeral: true,
91+
});
92+
return;
93+
}
8794
setValue(
88-
{ type: "fontFamily", value: [value] },
95+
{ type: "fontFamily", value: [item.value] },
8996
{ isEphemeral: true }
9097
);
9198
}}
@@ -98,10 +105,10 @@ export const FontFamilyControl = () => {
98105
setIntermediateValue(value);
99106
}}
100107
onBlur={() => {
101-
setValue({
102-
type: "fontFamily",
103-
value: [itemValue],
104-
});
108+
if (isFontManagerOpen) {
109+
return;
110+
}
111+
setValue(parseCssValue("fontFamily", itemValue));
105112
}}
106113
match={matchOrSuggestToCreate}
107114
/>

0 commit comments

Comments
 (0)