Skip to content

Commit 6151138

Browse files
authored
fix: show token name when convert local styles to token (#5123)
Ref https://discord.com/channels/955905230107738152/1360809139810599063/1360809139810599063 There were two problems here 1. empty token name collapsed and was not editable; fixed it with nbsp 2. the label set with dom didn't have proper timing; fixed it by rendering label by react
1 parent acbb038 commit 6151138

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

apps/builder/app/builder/features/navigator/navigator-tree.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ const TreeNodeContent = ({
437437
ref={mergeRefs(editableRef, ref)}
438438
{...handlers}
439439
isEditing={isEditing}
440-
/>
440+
>
441+
{label}
442+
</EditableTreeNodeLabel>
441443
</TreeNodeLabel>
442444
);
443445
};

apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ const EditableText = ({
136136
spellCheck={false}
137137
userSelect={isEditing ? "text" : "none"}
138138
css={{
139+
// prevent collapsing horizontally editable text when empty
140+
flexGrow: 1,
139141
outline: "none",
140142
textOverflow: isEditing ? "clip" : "ellipsis",
141143
cursor: isEditing ? "auto" : "default",
142144
}}
143145
{...handlers}
144-
/>
146+
>
147+
{value}
148+
</Text>
145149
);
146150
};
147151

apps/builder/app/shared/dom-hooks/use-content-editable.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,8 @@ export const useContentEditable = ({
2020
value: string;
2121
}) => {
2222
const elementRef = useRef<HTMLDivElement | null>(null);
23-
const setTextContent = () => {
24-
if (elementRef.current && isEditing === false) {
25-
elementRef.current.textContent = value;
26-
}
27-
};
28-
const ref = (element: HTMLDivElement | null) => {
29-
elementRef.current = element;
30-
setTextContent();
31-
};
3223
const getValue = () => elementRef.current?.textContent ?? "";
3324

34-
useEffect(setTextContent, [value, isEditing]);
35-
3625
useEffect(() => {
3726
const element = elementRef.current;
3827
if (element === null) {
@@ -56,13 +45,6 @@ export const useContentEditable = ({
5645
}
5746

5847
element.removeAttribute("contenteditable");
59-
// This is needed to force layout to recalc max-width when editing is done,
60-
// because otherwise, layout will keep the value from before engaging contenteditable.
61-
const { parentElement } = element;
62-
if (parentElement) {
63-
parentElement.removeChild(element);
64-
parentElement.appendChild(element);
65-
}
6648
}, [isEditing]);
6749

6850
const handleEnd = (event: KeyboardEvent<Element> | FocusEvent<Element>) => {
@@ -111,5 +93,5 @@ export const useContentEditable = ({
11193
onDoubleClick: handleDoubleClick,
11294
};
11395

114-
return { ref, handlers };
96+
return { ref: elementRef, handlers };
11597
};

0 commit comments

Comments
 (0)