Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Optionally memorize min height in style panel advanced css editor (#4962)

Oleg Isonen2a21fc7eeb70
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
index d8280e9f1b..3242ccee2d 100644
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
@@ -22,6 +22,7 @@ import { getDots } from "../../shared/style-section";
import { CssEditor, type CssEditorApi } from "../../../../shared/css-editor";
import { $advancedStylesLonghands } from "./stores";
import { $selectedInstanceKey } from "~/shared/awareness";
+import { getSetting } from "~/builder/shared/client-settings";
// Only here to keep the same section module interface
export const properties = [];
@@ -141,6 +142,7 @@ export const Section = () => {
onDeleteAllDeclarations={handleDeleteAllDeclarations}
apiRef={apiRef}
recentProperties={recentProperties}
+ memorizeMinHeight={getSetting("stylePanelMode") !== "advanced"}
/>
</AdvancedStyleSection>
);
diff --git a/apps/builder/app/builder/shared/css-editor/css-editor.tsx b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
index 5ab221e337..ea74860877 100644
--- a/apps/builder/app/builder/shared/css-editor/css-editor.tsx
+++ b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
@@ -319,6 +319,7 @@ export const CssEditor = ({
apiRef,
showSearch = true,
recentProperties = [],
+ memorizeMinHeight = true,
}: {
onDeleteProperty: DeleteProperty;
onSetProperty: SetProperty;
@@ -327,6 +328,9 @@ export const CssEditor = ({
styleMap: CssStyleMap;
apiRef?: RefObject<CssEditorApi>;
showSearch?: boolean;
+ // When used as part of some larger scroll area to avoid scroll jumps during search.
+ // For example advanced section in the style panel.
+ memorizeMinHeight?: boolean;
recentProperties?: Array<CssProperty>;
}) => {
const [isAdding, setIsAdding] = useState(false);
@@ -354,10 +358,6 @@ export const CssEditor = ({
const showRecentProperties =
recentProperties.length > 0 && searchProperties === undefined;
- const memorizeMinHeight = () => {
- setMinHeight(containerRef.current?.getBoundingClientRect().height ?? 0);
- };
-
const handleInsertStyles = (cssText: string) => {
const styleMap = parseStyleInput(cssText);
if (styleMap.size === 0) {
@@ -386,7 +386,9 @@ export const CssEditor = ({
return handleAbortSearch();
}
- memorizeMinHeight();
+ if (memorizeMinHeight) {
+ setMinHeight(containerRef.current?.getBoundingClientRect().height ?? 0);
+ }
const styles = [];
for (const [property, value] of styleMap) {