Skip to content

Commit 2ade021

Browse files
vanceingallsclaude
andcommitted
refactor(studio): scroll only the open group's body, keep headers fixed
Collapsed group headers render in fixed, non-scrolling document flow above and below the open group; only the open group's own content scrolls, in a dedicated region. Also fixes the flat inspector footer's missing background. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent 9e8e27d commit 2ade021

6 files changed

Lines changed: 263 additions & 59 deletions

File tree

‎packages/studio/src/components/editor/PropertyPanel.test.tsx‎

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ function inferredMotionElement() {
165165
// A single "to" tween running from t=2 to t=5 (position 2, duration 3), with
166166
// keyframes on "x" at 0/50/100% — enough to drive both FlatTimingRow's
167167
// inference and the Layout "x" row's keyframe-seek gutter.
168+
// Six-group fixture (fixed-headers + scrollable-open-section worked example):
169+
// tagName "img" turns on both Media and Grade (resolveEditingSections), on top
170+
// of baseElement()'s text-editable + style-editable + timing-eligible
171+
// (data-start) defaults — yielding all six groups in a known order:
172+
// [text, style, layout, motion, grade, media].
173+
function sixGroupElement() {
174+
return {
175+
...baseElement(),
176+
id: "six-group",
177+
selector: "#six-group",
178+
label: "Six Group",
179+
tagName: "img",
180+
dataAttributes: { start: "0", duration: "4" },
181+
};
182+
}
183+
168184
const INFERRED_TIMING_ANIMATION = {
169185
id: "a1",
170186
targetSelector: "#inferred-anim",
@@ -812,7 +828,7 @@ describe("PropertyPanel — pinning", () => {
812828
expect(pinnedRow?.textContent).toContain("Pinned");
813829

814830
// The divider must appear after the pinned zone.
815-
const container = host.querySelector(".flex-1.overflow-y-auto");
831+
const container = host.querySelector('[data-flat-panel-body="true"]');
816832
const children = Array.from(container?.children ?? []);
817833
const pinnedIndex = children.indexOf(pinnedRow as Element);
818834
const dividerIndex = children.findIndex((el) => el.textContent?.includes("one open below"));
@@ -837,3 +853,95 @@ describe("PropertyPanel — pinning", () => {
837853
RENDER_TIMEOUT_MS,
838854
);
839855
});
856+
857+
// design_handoff scrollable-open-section: collapsed headers before/after the
858+
// open group render in normal document flow and never move (no sticky, no
859+
// stacking offsets) — only the open group's own body content scrolls, in a
860+
// dedicated region between the two fixed header stacks. Worked example: 6
861+
// groups [text, style, layout, motion, grade, media], motion open (index 3)
862+
// -> text/style/layout render as fixed collapsed headers before it, motion
863+
// renders as an open header + scrollable body, grade/media render as fixed
864+
// collapsed headers after it — in exactly that DOM order, nothing sticky.
865+
describe("PropertyPanel — fixed headers + scrollable open section (Plan 11)", () => {
866+
it(
867+
"renders before-open headers, the open group (header + scrollable body), then after-open headers, in that exact order, with nothing sticky",
868+
async () => {
869+
const { host, root } = await renderPanel(true, sixGroupElement());
870+
// sixGroupElement() opens Text by default; open Motion (index 3) to
871+
// match the worked example.
872+
openFlatGroup(host, "Motion");
873+
expect(openGroupText(host)).toContain("Motion");
874+
875+
const body = host.querySelector('[data-flat-panel-body="true"]');
876+
if (!body) throw new Error("expected the flat panel body container");
877+
878+
// Titles in DOM order: each child is either a collapsed header button
879+
// (before/after the open group) or the open-group wrapper div.
880+
const titles = Array.from(body.children).map((child) => {
881+
if (child.matches('[data-flat-group-collapsed="true"]')) return child.textContent ?? "";
882+
if (child.matches('[data-flat-group-open="true"]')) return child.textContent ?? "";
883+
return null;
884+
});
885+
// Filter to just the group entries (drop nulls from any divider, none
886+
// expected here since no groups are pinned).
887+
const groupTitles = titles.filter((t): t is string => t !== null);
888+
expect(groupTitles).toHaveLength(6);
889+
expect(groupTitles[0]).toContain("Text");
890+
expect(groupTitles[1]).toContain("Style");
891+
expect(groupTitles[2]).toContain("Layout");
892+
expect(groupTitles[3]).toContain("Motion");
893+
expect(groupTitles[4]).toContain("Grade");
894+
expect(groupTitles[5]).toContain("Media");
895+
896+
// The open group (Motion, index 3) is the one wrapped in
897+
// data-flat-group-open, sitting between the before/after collapsed
898+
// headers — and it must contain a dedicated scrollable body.
899+
const openWrapper = host.querySelector('[data-flat-group-open="true"]');
900+
if (!openWrapper) throw new Error("expected the open-group wrapper");
901+
expect(openWrapper.textContent).toContain("Motion");
902+
expect(openWrapper.querySelector(".overflow-y-auto")).not.toBeNull();
903+
904+
// Nothing anywhere in the panel body carries inline sticky positioning
905+
// — the entire sticky-stacking mechanism is gone.
906+
const stickyEls = Array.from(body.querySelectorAll<HTMLElement>("[style]")).filter(
907+
(el) => el.style.position === "sticky",
908+
);
909+
expect(stickyEls).toHaveLength(0);
910+
act(() => root.unmount());
911+
},
912+
RENDER_TIMEOUT_MS,
913+
);
914+
915+
it(
916+
"renders every group as a plain collapsed header with no scrollable middle region when nothing is open",
917+
async () => {
918+
const { host, root } = await renderPanel(true, sixGroupElement());
919+
// Collapse the default-open Text group so openGroupId becomes "".
920+
const collapseButton = host.querySelector<HTMLButtonElement>(
921+
'[data-flat-group-open="true"] button[title="Collapse"]',
922+
);
923+
act(() => collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
924+
expect(host.querySelector('[data-flat-group-open="true"]')).toBeNull();
925+
926+
const collapsedRows = Array.from(
927+
host.querySelectorAll<HTMLButtonElement>('[data-flat-group-collapsed="true"]'),
928+
);
929+
expect(collapsedRows).toHaveLength(6);
930+
const titlesInOrder = collapsedRows.map((el) => el.textContent ?? "");
931+
expect(titlesInOrder[0]).toContain("Text");
932+
expect(titlesInOrder[1]).toContain("Style");
933+
expect(titlesInOrder[2]).toContain("Layout");
934+
expect(titlesInOrder[3]).toContain("Motion");
935+
expect(titlesInOrder[4]).toContain("Grade");
936+
expect(titlesInOrder[5]).toContain("Media");
937+
938+
const body = host.querySelector('[data-flat-panel-body="true"]');
939+
expect(body?.querySelector(".overflow-y-auto")).toBeNull();
940+
for (const row of collapsedRows) {
941+
expect(row.style.position).toBe("");
942+
}
943+
act(() => root.unmount());
944+
},
945+
RENDER_TIMEOUT_MS,
946+
);
947+
});

‎packages/studio/src/components/editor/PropertyPanelFlat.tsx‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { PropertyPanelProps } from "./propertyPanelHelpers";
66
import { formatPxMetricValue } from "./propertyPanelHelpers";
77
import { PropertyPanelFlatHeader } from "./PropertyPanelFlatHeader";
88
import { PropertyPanelFlatFooter } from "./PropertyPanelFlatFooter";
9-
import { FlatGroup, PinnedGroupRow, PinnedZoneDivider } from "./propertyPanelFlatPrimitives";
9+
import { FlatGroupHeader, PinnedGroupRow, PinnedZoneDivider } from "./propertyPanelFlatPrimitives";
1010
import { FlatTextSection } from "./propertyPanelFlatTextSection";
1111
import { FlatStyleSection } from "./propertyPanelFlatStyleSections";
1212
import { FlatLayoutSection } from "./propertyPanelFlatLayoutSection";
@@ -456,6 +456,18 @@ export function PropertyPanelFlat({
456456
const pinned = groups.filter((g) => pinnedGroupIds.includes(g.id));
457457
const unpinned = groups.filter((g) => !pinnedGroupIds.includes(g.id));
458458

459+
// Fixed-headers + scrollable-open-section layout (design_handoff
460+
// scrollable-open-section, replaces the prior sticky-stacking mechanism):
461+
// collapsed headers before/after the open group render in normal document
462+
// flow and never move. Only the open group's own body content scrolls, in
463+
// a dedicated region between the two fixed header stacks. When no group is
464+
// open, every group is just a collapsed header — there's no scrollable
465+
// middle region at all, since nothing is expanded.
466+
const openIndex = unpinned.findIndex((g) => g.id === openGroupId);
467+
const beforeOpen = openIndex === -1 ? unpinned : unpinned.slice(0, openIndex);
468+
const openGroup = openIndex === -1 ? null : unpinned[openIndex];
469+
const afterOpen = openIndex === -1 ? [] : unpinned.slice(openIndex + 1);
470+
459471
return (
460472
<div className="flex h-full min-h-0 flex-col overflow-hidden bg-panel-bg text-panel-text-1">
461473
<PropertyPanelFlatHeader
@@ -474,7 +486,7 @@ export function PropertyPanelFlat({
474486
onUngroup={onUngroup}
475487
showUngroup={Boolean(onUngroup && element.dataAttributes["hf-group"] != null)}
476488
/>
477-
<div className="flex-1 overflow-y-auto">
489+
<div data-flat-panel-body="true" className="flex min-h-0 flex-1 flex-col overflow-hidden">
478490
{pinned.map((g) => (
479491
<PinnedGroupRow
480492
key={g.id}
@@ -486,19 +498,42 @@ export function PropertyPanelFlat({
486498
</PinnedGroupRow>
487499
))}
488500
{pinned.length > 0 && unpinned.length > 0 && <PinnedZoneDivider />}
489-
{unpinned.map((g) => (
490-
<FlatGroup
501+
{beforeOpen.map((g) => (
502+
<FlatGroupHeader
491503
key={g.id}
492504
title={g.title}
493-
isOpen={openGroupId === g.id}
505+
isOpen={false}
494506
isPinned={false}
495507
onToggleOpen={() => toggleOpen(g.id)}
496508
onTogglePin={() => togglePin(g.id)}
497509
summary={g.summary}
498-
accessory={g.accessory}
499-
>
500-
{g.content}
501-
</FlatGroup>
510+
/>
511+
))}
512+
{openGroup && (
513+
<div data-flat-group-open="true" className="flex min-h-0 flex-1 flex-col">
514+
<FlatGroupHeader
515+
title={openGroup.title}
516+
isOpen
517+
isPinned={false}
518+
onToggleOpen={() => toggleOpen(openGroup.id)}
519+
onTogglePin={() => togglePin(openGroup.id)}
520+
accessory={openGroup.accessory}
521+
/>
522+
<div className="min-h-0 flex-1 overflow-y-auto border-b border-panel-hairline px-4 py-3">
523+
{openGroup.content}
524+
</div>
525+
</div>
526+
)}
527+
{afterOpen.map((g) => (
528+
<FlatGroupHeader
529+
key={g.id}
530+
title={g.title}
531+
isOpen={false}
532+
isPinned={false}
533+
onToggleOpen={() => toggleOpen(g.id)}
534+
onTogglePin={() => togglePin(g.id)}
535+
summary={g.summary}
536+
/>
502537
))}
503538
</div>
504539
<PropertyPanelFlatFooter

‎packages/studio/src/components/editor/PropertyPanelFlatFooter.test.tsx‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,33 @@ describe("PropertyPanelFlatFooter", () => {
5252
expect(recordButton?.title).toBe("Stop recording 2.4s");
5353
act(() => root.unmount());
5454
});
55+
56+
// Plan 10 (sticky-footer-gap): the root must carry an opaque background —
57+
// it previously had none at all, letting scrolled panel content show
58+
// through. Regression coverage for the definite fix from the brief.
59+
it("has an opaque bg-panel-bg background on its root element", () => {
60+
const { host, root } = renderFooter({ onAskAgent: vi.fn() });
61+
const footerRoot = host.firstElementChild as HTMLElement;
62+
expect(footerRoot.className).toContain("bg-panel-bg");
63+
act(() => root.unmount());
64+
});
65+
66+
// Plan 11 (scrollable-open-section): the prior sticky-stacking mechanism —
67+
// and the Plan 10 hairline-sealing hack it required at this exact boundary
68+
// (an absolutely-positioned overlay patching a Chromium sticky-offset
69+
// rounding gap) — is gone now that nothing above the footer is
70+
// `position: sticky`. Live browser verification (p11 report) confirmed the
71+
// boundary renders as a single clean hairline without it: whatever
72+
// immediately precedes the footer (a collapsed FlatGroupHeader, the open
73+
// group's scrollable body wrapper, or a PinnedGroupRow) already draws its
74+
// own border-b in normal document flow, so the footer needs no border or
75+
// seal of its own.
76+
it("renders no seal overlay and no border of its own — the boundary line comes from whatever precedes it", () => {
77+
const { host, root } = renderFooter({ onAskAgent: vi.fn() });
78+
const footerRoot = host.firstElementChild as HTMLElement;
79+
expect(footerRoot.className).not.toContain("border-t");
80+
expect(footerRoot.className).not.toContain("border-b");
81+
expect(host.querySelector('[data-flat-footer-seal="true"]')).toBeNull();
82+
act(() => root.unmount());
83+
});
5584
});

‎packages/studio/src/components/editor/PropertyPanelFlatFooter.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export function PropertyPanelFlatFooter({
1515
: "Record gesture (R)";
1616

1717
return (
18-
<div className="flex items-center justify-between border-t border-panel-hairline px-4 py-[11px]">
18+
// No border-t here: every possible element immediately above this footer
19+
// in the new fixed-headers + scrollable-open-section layout (a collapsed
20+
// FlatGroupHeader, the open group's scrollable body wrapper, or a
21+
// PinnedGroupRow) already draws its own border-b in normal document flow
22+
// — nothing here is `position: sticky` anymore, so there's no rounding
23+
// seam to seal (see p11-scrollable-open-section-report.md).
24+
<div className="flex items-center justify-between bg-panel-bg px-4 py-[11px]">
1925
<button
2026
type="button"
2127
data-flat-footer-ask="true"

‎packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx‎

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { act } from "react";
44
import { createRoot } from "react-dom/client";
55
import { afterEach, describe, expect, it, vi } from "vitest";
66
import {
7-
FlatGroup,
7+
FlatGroupHeader,
88
FlatRow,
99
FlatSegmentedRow,
1010
FlatSelectRow,
@@ -109,49 +109,78 @@ describe("FlatSegmentedRow", () => {
109109
});
110110
});
111111

112-
describe("FlatGroup", () => {
113-
it("renders the open header (name + pin + caret) and shows children", () => {
112+
describe("FlatGroupHeader", () => {
113+
it("renders the open header (name + pin + caret), with no sticky-related props required", () => {
114114
const onToggleOpen = vi.fn();
115115
const onTogglePin = vi.fn();
116116
const { host, root } = renderInto(
117-
<FlatGroup
117+
<FlatGroupHeader
118118
title="Text"
119119
isOpen
120120
isPinned={false}
121121
onToggleOpen={onToggleOpen}
122122
onTogglePin={onTogglePin}
123-
>
124-
<div data-testid="body">body</div>
125-
</FlatGroup>,
123+
/>,
126124
);
127-
expect(host.querySelector('[data-testid="body"]')).not.toBeNull();
125+
expect(host.textContent).toContain("Text");
128126
const pin = host.querySelector<HTMLButtonElement>('[data-flat-group-pin="true"]');
129127
act(() => pin?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
130128
expect(onTogglePin).toHaveBeenCalledTimes(1);
129+
const collapse = host.querySelector<HTMLButtonElement>('button[title="Collapse"]');
130+
act(() => collapse?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
131+
expect(onToggleOpen).toHaveBeenCalledTimes(1);
131132
act(() => root.unmount());
132133
});
133134

134-
it("renders the collapsed row (name + summary + caret-right) and no children", () => {
135+
it("renders the collapsed row (name + summary + caret-right) with no sticky positioning", () => {
135136
const onToggleOpen = vi.fn();
136137
const { host, root } = renderInto(
137-
<FlatGroup
138+
<FlatGroupHeader
138139
title="Style"
139140
isOpen={false}
140141
isPinned={false}
141142
onToggleOpen={onToggleOpen}
142143
onTogglePin={vi.fn()}
143144
summary="fill none · 100%"
144-
>
145-
<div data-testid="body">body</div>
146-
</FlatGroup>,
145+
/>,
147146
);
148-
expect(host.querySelector('[data-testid="body"]')).toBeNull();
149147
expect(host.textContent).toContain("fill none · 100%");
150148
const row = host.querySelector<HTMLButtonElement>('[data-flat-group-collapsed="true"]');
149+
expect(row?.style.position).toBe("");
151150
act(() => row?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
152151
expect(onToggleOpen).toHaveBeenCalledTimes(1);
153152
act(() => root.unmount());
154153
});
154+
155+
it("renders no inline position styling in either state (collapsed headers never move)", () => {
156+
const { host: collapsedHost, root: collapsedRoot } = renderInto(
157+
<FlatGroupHeader
158+
title="Layout"
159+
isOpen={false}
160+
isPinned={false}
161+
onToggleOpen={vi.fn()}
162+
onTogglePin={vi.fn()}
163+
/>,
164+
);
165+
const row = collapsedHost.querySelector<HTMLButtonElement>(
166+
'[data-flat-group-collapsed="true"]',
167+
);
168+
expect(row?.getAttribute("style")).toBeNull();
169+
act(() => collapsedRoot.unmount());
170+
171+
const { host: openHost, root: openRoot } = renderInto(
172+
<FlatGroupHeader
173+
title="Motion"
174+
isOpen
175+
isPinned={false}
176+
onToggleOpen={vi.fn()}
177+
onTogglePin={vi.fn()}
178+
/>,
179+
);
180+
expect(openHost.textContent).toContain("Motion");
181+
expect(openHost.querySelector("[style]")).toBeNull();
182+
act(() => openRoot.unmount());
183+
});
155184
});
156185

157186
describe("PinnedZoneDivider", () => {

0 commit comments

Comments
 (0)