Skip to content

Commit d525fc9

Browse files
cliffhallclaude
andauthored
fix(web): ResourceControls single-scroll, full-height panel, right/down chevrons (#1462) (#1464)
* fix(web): ResourceControls single-scroll + right/down disclosure chevrons (#1462) Two fixes to the Resources controls panel: 1. Sections scrolled prematurely. `panelMaxHeight` divided the available height equally across open sections (`… / n`), so a section with many items scrolled while sparse siblings left their equal share unused. Replace the per-section ScrollAreas with a single viewport-bounded ScrollArea.Autosize around the whole accordion (matching ToolControls / PromptControls). Sections size to content; nothing scrolls until the open sections' combined height exceeds the cap. 2. Accordion chevrons pointed down/up. Add a `disclosure` Accordion theme variant + `.disclosure-chevron[data-rotate]` rule that rotates a right-pointing RiArrowRightSLine 90° (not Mantine's default 180°), so closed sections point right and open sections point down — matching the ResourceLink chevron convention. Also keep empty (disabled) sections out of the accordion's open set so they render collapsed with a right chevron instead of an open-but-empty panel. Verified all states in a real browser via Playwright. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(web): cover empty-section-collapsed behavior in ResourceControls (#1462) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(web): make Resources sidebar fill panel height before scrolling (#1462) The first pass capped the accordion scroll region at a fixed sub-viewport height (`100vh - … - 160px`), so the sidebar scrolled before reaching the height of the detail panel to its right. Make the sidebar card full-height instead: add a `sidebar` Card variant (height:100%, flex column, overflow hidden), give it `flex: 1`, and let ResourceControls' root Stack (`flex: 1; min-height: 0`) and a plain flex-filling ScrollArea claim the space below the title/search. The card now matches the detail panel's height exactly and the single inner scroll region scrolls only once the open sections overflow the full panel. Adds a ResourcesScreen ManyResources story asserting the sidebar/detail height match and that overflow scrolls, plus a unit test for the empty-section-collapsed behavior. Verified heights + scroll in a real browser via Playwright. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(web): pin Resources section headers, scroll each section in place (#1462) The previous pass scrolled the whole accordion as one block (headers scrolled away). Restore pinned headers with per-section scrolling, without the original equal-division premature-scroll bug. The `disclosure` Accordion now fills its full-height card as a flex column (`disclosure-sections`): controls are pinned, and each open section's panel scrolls within its own share of the remaining height. Per-item `flex` weights (shrink ∝ item count, grow 0) hand space from long sections to short ones, so nothing scrolls until the combined content overflows the panel — a long URIs list scrolls in place while Templates stays fully visible below it. Drops the single outer ScrollArea (and useScrollMemory). Verified in a real browser: 6 URIs → no scroll, headers pinned, empty space at the bottom; 40 URIs → URIs panel scrolls in place, Templates intact, all three headers pinned, sidebar still matches the detail height. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(web): Resources sidebar grows with content, capped at screen (#1462) The `sidebar` Card variant forced `height: 100%`, so the panel was always full-height with empty space below short content. Switch to `max-height: 100%` (and drop `flex: 1`) so the card hugs its content and only caps at the screen height — matching the Tools panel. When content overflows the cap, the flex accordion still takes over per-section scrolling with pinned headers. Verified in a real browser: 6 URIs → card hugs (638px, shorter than the detail panel); 40 URIs → card caps at the screen (949px == detail), headers pinned, URIs scrolls in place. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(web): preserve empty-section intent + kill accordion collapse jump (#1464 review) Address review feedback on PR #1464: - Intent loss (review #1): the accordion's `value` is the filtered `visibleOpenSections`, so Mantine's toggle dropped open-but-empty sections from the persisted intent. Merge them back in the onChange handler so an open empty section stays open and reappears with items. Adds a unit test. - Collapse animation jump (review #3): Mantine's Collapse briefly set the panel to its full natural height (fighting the flex layout) on open/close, flashing siblings. Set `transitionDuration={0}` so flex controls the height; restore a smooth chevron rotation via CSS. Verified no jump in a real browser (panel 501→0, no spike). Since closed sections now render no content, drop the redundant (and incorrect) "Templates" toggle clicks from 4 ResourcesScreen tests (the section is open by default) and add a section-toggle test to keep the openSections handler covered. - Nits: scope the stories' chevron query to the accordion root; tighten the Collapsed assertion to the identity transform. Native-vs-styled scrollbar (review #4) split out as #1466. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(web): clarify chevron-timing and intent-merge invariants (#1464 review) Address the two optional doc nits from the re-review: - Note that the chevron's 200ms restates Mantine's default accordion duration (keep in sync if accordion timing is themed). - Note that the unconditional empty-section merge is safe because empty-section controls are disabled, so `next` never contains one. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 3220d62 commit d525fc9

11 files changed

Lines changed: 388 additions & 64 deletions

File tree

‎clients/web/src/App.css‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,62 @@
182182
}
183183
}
184184

185+
/* ── Accordion disclosure chevron (right when closed, down when open) ──
186+
*
187+
* Mantine's default chevron rotation flips 180° on open (e.g. down → up). For
188+
* the `disclosure` Accordion variant we use a right-pointing chevron and rotate
189+
* it only 90° so closed sections point right and open sections point down — the
190+
* standard disclosure direction, matching ResourceLink's chevron (issue #1462).
191+
* `[data-rotate]` is set by Mantine on the chevron slot when the item is open;
192+
* the class+attribute selector outranks Mantine's `:where()`-wrapped default. */
193+
194+
/* Restore a smooth rotation: the accordion sets `transitionDuration={0}` to
195+
* disable its panel height animation (which fights the flex layout), and that
196+
* zeroes the shared `--accordion-transition-duration` the chevron would use.
197+
* The 200ms restates Mantine's default accordion duration — keep it in sync if
198+
* accordion timing is ever themed. */
199+
.disclosure-chevron {
200+
transition: transform 200ms ease;
201+
}
202+
203+
.disclosure-chevron[data-rotate] {
204+
transform: rotate(90deg);
205+
}
206+
207+
/* ── Full-height sectioned accordion (Resources) ─────────────────
208+
*
209+
* The `disclosure` Accordion fills its full-height card as a flex column. The
210+
* section controls (headers) stay pinned while each OPEN section's panel scrolls
211+
* within its own share of the remaining height — the per-item `flex` weight
212+
* (set in ResourceControls) hands space from long sections to short ones. With
213+
* `flex-grow: 0`, nothing expands or scrolls until the combined content
214+
* overflows the panel, so sections never scroll while the panel has free space
215+
* (issue #1462). Closed sections collapse to their header height. */
216+
217+
.disclosure-sections {
218+
display: flex;
219+
flex-direction: column;
220+
min-height: 0;
221+
}
222+
223+
.disclosure-sections > .mantine-Accordion-item[data-active] {
224+
display: flex;
225+
flex-direction: column;
226+
min-height: 0;
227+
}
228+
229+
.disclosure-sections .mantine-Accordion-control {
230+
flex: 0 0 auto;
231+
}
232+
233+
.disclosure-sections
234+
> .mantine-Accordion-item[data-active]
235+
.mantine-Accordion-panel {
236+
flex: 1 1 auto;
237+
min-height: 0;
238+
overflow-y: auto;
239+
}
240+
185241
/* ── List item hover ────────────────────────────────────── */
186242

187243
.list-item:hover {

‎clients/web/src/components/groups/ResourceControls/ResourceControls.stories.tsx‎

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ import type {
44
ResourceTemplate,
55
} from "@modelcontextprotocol/sdk/types.js";
66
import type { InspectorResourceSubscription } from "../../../../../../core/mcp/types.js";
7-
import { fn } from "storybook/test";
7+
import { expect, fn, within } from "storybook/test";
88
import { ResourceControls } from "./ResourceControls";
99

10+
// rotate(90deg) — Mantine sets `data-rotate` on the chevron slot of an open
11+
// section; App.css rotates the right-pointing arrow 90° so it points down.
12+
const ROTATED_DOWN = "matrix(0, 1, -1, 0, 0, 0)";
13+
// Identity — a closed section's right-pointing chevron at its natural 0°.
14+
const NOT_ROTATED = "matrix(1, 0, 0, 1, 0, 0)";
15+
16+
function chevronTransforms(canvasElement: HTMLElement): string[] {
17+
// Scoped to the accordion root so it still works if a story ever renders more
18+
// than one disclosure accordion on the canvas.
19+
const root = canvasElement.querySelector(".disclosure-sections");
20+
return [
21+
...(root ?? canvasElement).querySelectorAll(".disclosure-chevron"),
22+
].map((c) => getComputedStyle(c).transform);
23+
}
24+
1025
const meta: Meta<typeof ResourceControls> = {
1126
title: "Groups/ResourceControls",
1227
component: ResourceControls,
@@ -65,6 +80,13 @@ export const Default: Story = {
6580
templates: sampleTemplates,
6681
subscriptions: sampleSubscriptions,
6782
},
83+
// All three populated sections open by default (compact=false) → every
84+
// chevron points down.
85+
play: async ({ canvasElement }) => {
86+
const transforms = chevronTransforms(canvasElement);
87+
expect(transforms).toHaveLength(3);
88+
for (const t of transforms) expect(t).toBe(ROTATED_DOWN);
89+
},
6890
};
6991

7092
export const WithSearch: Story = {
@@ -87,3 +109,54 @@ export const Empty: Story = {
87109
subscriptions: [],
88110
},
89111
};
112+
113+
// Sections explicitly collapsed: every chevron points right (no rotation).
114+
export const Collapsed: Story = {
115+
args: {
116+
resources: sampleResources,
117+
templates: sampleTemplates,
118+
subscriptions: sampleSubscriptions,
119+
openSections: [],
120+
},
121+
play: async ({ canvasElement }) => {
122+
const transforms = chevronTransforms(canvasElement);
123+
expect(transforms).toHaveLength(3);
124+
// Identity matrix = the right-pointing arrow's natural 0° (not rotated).
125+
for (const t of transforms) expect(t).toBe(NOT_ROTATED);
126+
},
127+
};
128+
129+
// Populated URIs/Templates but no Subscriptions, all "open" in intent. The
130+
// empty Subscriptions section is kept out of the open set, so its chevron
131+
// points right while the two populated ones point down.
132+
export const EmptySectionCollapsed: Story = {
133+
args: {
134+
resources: sampleResources,
135+
templates: sampleTemplates,
136+
subscriptions: [],
137+
openSections: ["resources", "templates", "subscriptions"],
138+
},
139+
play: async ({ canvasElement }) => {
140+
const canvas = within(canvasElement);
141+
expect(canvas.getByText("Subscriptions (0)")).toBeInTheDocument();
142+
const transforms = chevronTransforms(canvasElement);
143+
const downCount = transforms.filter((t) => t === ROTATED_DOWN).length;
144+
expect(downCount).toBe(2); // URIs + Templates down, Subscriptions right
145+
},
146+
};
147+
148+
// Many URIs with sparse Templates/Subscriptions: under the old equal `/ n`
149+
// height split, URIs scrolled while the others left their share unused. Now the
150+
// sections size to content inside one bounded scroll region.
151+
const manyResources: Resource[] = Array.from({ length: 30 }, (_, i) => ({
152+
name: `resource-${String(i + 1).padStart(2, "0")}.md`,
153+
uri: `file:///docs/resource-${i + 1}.md`,
154+
}));
155+
156+
export const ManyResources: Story = {
157+
args: {
158+
resources: manyResources,
159+
templates: sampleTemplates,
160+
subscriptions: sampleSubscriptions,
161+
},
162+
};

‎clients/web/src/components/groups/ResourceControls/ResourceControls.test.tsx‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,51 @@ describe("ResourceControls", () => {
222222
expect(onCompactChange).toHaveBeenLastCalledWith(false);
223223
});
224224

225+
it("keeps an empty section collapsed even when it's in openSections", () => {
226+
// All three sections requested open, but Subscriptions has no items: its
227+
// control must render collapsed (aria-expanded=false) so the chevron points
228+
// right, while the populated sections stay expanded (#1462).
229+
renderWithMantine(
230+
<ResourceControls
231+
{...baseProps}
232+
subscriptions={[]}
233+
openSections={["resources", "templates", "subscriptions"]}
234+
/>,
235+
);
236+
expect(screen.getByRole("button", { name: /URIs \(2\)/ })).toHaveAttribute(
237+
"aria-expanded",
238+
"true",
239+
);
240+
expect(
241+
screen.getByRole("button", { name: /Templates \(1\)/ }),
242+
).toHaveAttribute("aria-expanded", "true");
243+
expect(
244+
screen.getByRole("button", { name: /Subscriptions \(0\)/ }),
245+
).toHaveAttribute("aria-expanded", "false");
246+
});
247+
248+
it("preserves an open-but-empty section's intent when toggling another section", async () => {
249+
// Subscriptions is open-in-intent but empty (excluded from the accordion's
250+
// value). Collapsing a populated section must not drop subscriptions from
251+
// the persisted intent, so it reopens once it has items again (#1462).
252+
const user = userEvent.setup();
253+
const onOpenSectionsChange = vi.fn();
254+
renderWithMantine(
255+
<ResourceControls
256+
{...baseProps}
257+
subscriptions={[]}
258+
openSections={["resources", "templates", "subscriptions"]}
259+
onOpenSectionsChange={onOpenSectionsChange}
260+
/>,
261+
);
262+
await user.click(screen.getByRole("button", { name: /Templates \(1\)/ }));
263+
// Mantine emits ["resources"]; "subscriptions" is merged back in.
264+
expect(onOpenSectionsChange).toHaveBeenCalledWith(
265+
expect.arrayContaining(["resources", "subscriptions"]),
266+
);
267+
expect(onOpenSectionsChange.mock.calls[0][0]).not.toContain("templates");
268+
});
269+
225270
it("filters by resource title when title is set", async () => {
226271
const user = userEvent.setup();
227272
const resourcesWithTitle: Resource[] = [

0 commit comments

Comments
 (0)