Skip to content

Commit d44724d

Browse files
author
am
committed
fix(shell): preserve clamped sidebar width during toggles
Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent ad386a8 commit d44724d

2 files changed

Lines changed: 127 additions & 112 deletions

File tree

‎src/shared/styles/globals.css‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@
232232
min-width: 0;
233233
flex: none;
234234
width: max-content;
235-
max-width: max(220px, calc(100% - 336px));
236235
overflow: visible;
237236
clip-path: none;
238237
/* Release resize help only after expansion; contain content while moving. */
@@ -254,6 +253,7 @@
254253
}
255254
.shell-content {
256255
@apply relative flex h-full min-h-0 min-w-0;
256+
container-type: inline-size;
257257
}
258258
.shell-sidebar,
259259
.shell-sidebar-default {
@@ -271,22 +271,11 @@
271271
> .shell-navigation-content
272272
> :is(.shell-sidebar, .shell-sidebar-default) {
273273
flex: none;
274-
max-width: 100%;
275-
/* Hold the sidebar at its own width while the track moves; reflowing it
276-
every frame re-measures every row. The clamp returns once expanded. */
277-
transition: max-width var(--duration-settle) step-end allow-discrete;
278-
}
279-
.shell-navigation[data-sidebar-collapsible][aria-hidden="true"]
280-
> .shell-navigation-content
281-
> :is(.shell-sidebar, .shell-sidebar-default) {
282-
max-width: none;
283-
transition-timing-function: step-start;
274+
/* Clamp against the stable shell, not the animated navigation track. */
275+
max-width: max(220px, calc(100cqi - 336px));
284276
}
285277
@media (prefers-reduced-motion: reduce) {
286-
.shell-navigation[data-sidebar-collapsible],
287-
.shell-navigation[data-sidebar-collapsible]
288-
> .shell-navigation-content
289-
> :is(.shell-sidebar, .shell-sidebar-default) {
278+
.shell-navigation[data-sidebar-collapsible] {
290279
transition: none;
291280
}
292281
}

‎tests/browser/sidenav-polish.spec.mjs‎

Lines changed: 123 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,129 @@ test("shell toggle restores the shared sidebar for Channels and Agents", async (
375375
expect(help.overflow).toBe("visible");
376376
}
377377
const sidebarNode = await sidebar.elementHandle();
378-
const expandedWidth = await sidebar.evaluate(
379-
(node) => node.closest(".shell-sidebar").getBoundingClientRect().width,
380-
);
378+
let expandedWidth;
379+
for (const viewportWidth of [1440, 800]) {
380+
if (viewportWidth === 800) await handle.press("End");
381+
await page.setViewportSize({ width: viewportWidth, height: 950 });
382+
expandedWidth = await sidebar.evaluate(
383+
(node) => node.closest(".shell-sidebar").getBoundingClientRect().width,
384+
);
385+
const gutterWidth = await handle.evaluate((element) => {
386+
const style = getComputedStyle(element);
387+
return (
388+
element.getBoundingClientRect().width +
389+
Number.parseFloat(style.marginLeft) +
390+
Number.parseFloat(style.marginRight)
391+
);
392+
});
393+
const track = await shellNavigation.evaluate((node) => {
394+
const style = getComputedStyle(node);
395+
return {
396+
width: node.getBoundingClientRect().width,
397+
property: style.transitionProperty,
398+
duration: style.transitionDuration,
399+
};
400+
});
401+
expect(track.width).toBe(expandedWidth + gutterWidth);
402+
expect(track.property).toContain("grid-template-columns");
403+
expect(parseFloat(track.duration)).toBeGreaterThan(0);
404+
const openGap = await page.evaluate(() => {
405+
const sidebar = document.querySelector(".shell-sidebar");
406+
const main = document.querySelector("#main-content");
407+
if (!(sidebar instanceof HTMLElement) || !(main instanceof HTMLElement))
408+
throw new Error("Missing shell panels");
409+
return (
410+
main.getBoundingClientRect().left -
411+
sidebar.getBoundingClientRect().right
412+
);
413+
});
414+
expect(openGap).toBe(gutterWidth);
415+
// Seek paused real transitions so runner speed cannot hide an immediate jump.
416+
// Pause them when the toggle commits, before any frame: transitionrun arrives
417+
// in a later frame, and a stalled WebKit frame can finish the 220ms transition
418+
// first. Only the track and the sidebar it holds are seeked; the resize help's
419+
// own descendant transitions are unrelated.
420+
for (const label of ["Hide Channel sidebar", "Show Channel sidebar"]) {
421+
const samples = await page.evaluate(async (label) => {
422+
const nav = document.querySelector("#shell-navigation");
423+
const sidebar = nav.querySelector(".shell-sidebar");
424+
const button = document.querySelector(`button[aria-label="${label}"]`);
425+
const committed = new Promise((resolve) => {
426+
const observer = new MutationObserver(() => {
427+
observer.disconnect();
428+
// getAnimations() flushes style, so the toggle's transitions exist.
429+
const transitions = [
430+
...nav.getAnimations(),
431+
...sidebar.getAnimations(),
432+
];
433+
for (const transition of transitions) transition.pause();
434+
resolve(transitions);
435+
});
436+
observer.observe(nav, {
437+
attributes: true,
438+
attributeFilter: ["aria-hidden"],
439+
});
440+
});
441+
button.click();
442+
const transitions = await committed;
443+
try {
444+
const properties = transitions.map(
445+
(transition) => transition.transitionProperty,
446+
);
447+
for (const property of ["grid-template-columns", "clip-path"])
448+
if (!properties.includes(property))
449+
throw new Error(`Missing ${property} transition`);
450+
return [0, 0.1, 0.25, 0.5, 0.75, 1].map((progress) => {
451+
for (const transition of transitions)
452+
transition.currentTime =
453+
transition.effect.getTiming().duration * progress;
454+
return {
455+
width: nav.getBoundingClientRect().width,
456+
sidebar: sidebar.getBoundingClientRect().width,
457+
clip: getComputedStyle(nav).clipPath,
458+
};
459+
});
460+
} finally {
461+
for (const transition of transitions) transition.finish();
462+
await Promise.all(
463+
transitions.map((transition) => transition.finished),
464+
);
465+
}
466+
}, label);
467+
const width = expandedWidth + gutterWidth;
468+
const hiding = label.startsWith("Hide");
469+
// The track leaves its real extent on the first sampled step and crosses
470+
// the midpoint halfway through, instead of stalling behind a larger
471+
// ceiling; the sidebar itself keeps its width and is only clipped.
472+
expect(samples[0].width).toBe(hiding ? width : 0);
473+
expect(samples[1].width).toBeGreaterThan(0);
474+
expect(samples[1].width).toBeLessThan(width);
475+
expect(Math.abs(samples[3].width - width / 2)).toBeLessThan(1);
476+
for (let index = 1; index < samples.length; index++) {
477+
const step = samples[index].width - samples[index - 1].width;
478+
expect(hiding ? -step : step).toBeGreaterThan(0);
479+
}
480+
expect(samples.at(-1).width).toBe(hiding ? 0 : width);
481+
for (const sample of samples) expect(sample.sidebar).toBe(expandedWidth);
482+
for (const sample of samples.slice(1, -1))
483+
expect(sample.clip).toBe("inset(0px)");
484+
expect(samples.at(-1).clip).toBe(hiding ? "inset(0px)" : "none");
485+
}
486+
487+
if (viewportWidth === 800) {
488+
expect(expandedWidth).toBeGreaterThan(220);
489+
expect(expandedWidth).toBeLessThan(520);
490+
}
491+
}
492+
await page.setViewportSize({ width: 1440, height: 950 });
493+
await expect
494+
.poll(() =>
495+
sidebar.evaluate(
496+
(node) => node.closest(".shell-sidebar").getBoundingClientRect().width,
497+
),
498+
)
499+
.toBe(520);
500+
expandedWidth = 520;
381501
const gutterWidth = await handle.evaluate((element) => {
382502
const style = getComputedStyle(element);
383503
return (
@@ -386,100 +506,6 @@ test("shell toggle restores the shared sidebar for Channels and Agents", async (
386506
Number.parseFloat(style.marginRight)
387507
);
388508
});
389-
const track = await shellNavigation.evaluate((node) => {
390-
const style = getComputedStyle(node);
391-
return {
392-
width: node.getBoundingClientRect().width,
393-
property: style.transitionProperty,
394-
duration: style.transitionDuration,
395-
};
396-
});
397-
expect(track.width).toBe(expandedWidth + gutterWidth);
398-
expect(track.property).toContain("grid-template-columns");
399-
expect(parseFloat(track.duration)).toBeGreaterThan(0);
400-
const openGap = await page.evaluate(() => {
401-
const sidebar = document.querySelector(".shell-sidebar");
402-
const main = document.querySelector("#main-content");
403-
if (!(sidebar instanceof HTMLElement) || !(main instanceof HTMLElement))
404-
throw new Error("Missing shell panels");
405-
return (
406-
main.getBoundingClientRect().left - sidebar.getBoundingClientRect().right
407-
);
408-
});
409-
expect(openGap).toBe(gutterWidth);
410-
// Seek paused real transitions so runner speed cannot hide an immediate jump.
411-
// Pause them when the toggle commits, before any frame: transitionrun arrives
412-
// in a later frame, and a stalled WebKit frame can finish the 220ms transition
413-
// first. Only the track and the sidebar it holds are seeked; the resize help's
414-
// own descendant transitions are unrelated.
415-
for (const label of ["Hide Channel sidebar", "Show Channel sidebar"]) {
416-
const samples = await page.evaluate(async (label) => {
417-
const nav = document.querySelector("#shell-navigation");
418-
const sidebar = nav.querySelector(".shell-sidebar");
419-
const button = document.querySelector(`button[aria-label="${label}"]`);
420-
const committed = new Promise((resolve) => {
421-
const observer = new MutationObserver(() => {
422-
observer.disconnect();
423-
// getAnimations() flushes style, so the toggle's transitions exist.
424-
const transitions = [
425-
...nav.getAnimations(),
426-
...sidebar.getAnimations(),
427-
];
428-
for (const transition of transitions) transition.pause();
429-
resolve(transitions);
430-
});
431-
observer.observe(nav, {
432-
attributes: true,
433-
attributeFilter: ["aria-hidden"],
434-
});
435-
});
436-
button.click();
437-
const transitions = await committed;
438-
try {
439-
const properties = transitions.map(
440-
(transition) => transition.transitionProperty,
441-
);
442-
for (const property of [
443-
"grid-template-columns",
444-
"clip-path",
445-
"max-width",
446-
])
447-
if (!properties.includes(property))
448-
throw new Error(`Missing ${property} transition`);
449-
return [0, 0.1, 0.25, 0.5, 0.75, 1].map((progress) => {
450-
for (const transition of transitions)
451-
transition.currentTime =
452-
transition.effect.getTiming().duration * progress;
453-
return {
454-
width: nav.getBoundingClientRect().width,
455-
sidebar: sidebar.getBoundingClientRect().width,
456-
clip: getComputedStyle(nav).clipPath,
457-
};
458-
});
459-
} finally {
460-
for (const transition of transitions) transition.finish();
461-
await Promise.all(transitions.map((transition) => transition.finished));
462-
}
463-
}, label);
464-
const width = expandedWidth + gutterWidth;
465-
const hiding = label.startsWith("Hide");
466-
// The track leaves its real extent on the first sampled step and crosses
467-
// the midpoint halfway through, instead of stalling behind a larger
468-
// ceiling; the sidebar itself keeps its width and is only clipped.
469-
expect(samples[0].width).toBe(hiding ? width : 0);
470-
expect(samples[1].width).toBeGreaterThan(0);
471-
expect(samples[1].width).toBeLessThan(width);
472-
expect(Math.abs(samples[3].width - width / 2)).toBeLessThan(1);
473-
for (let index = 1; index < samples.length; index++) {
474-
const step = samples[index].width - samples[index - 1].width;
475-
expect(hiding ? -step : step).toBeGreaterThan(0);
476-
}
477-
expect(samples.at(-1).width).toBe(hiding ? 0 : width);
478-
for (const sample of samples) expect(sample.sidebar).toBe(expandedWidth);
479-
for (const sample of samples.slice(1, -1))
480-
expect(sample.clip).toBe("inset(0px)");
481-
expect(samples.at(-1).clip).toBe(hiding ? "inset(0px)" : "none");
482-
}
483509

484510
await page.emulateMedia({ reducedMotion: "reduce" });
485511
await expect

0 commit comments

Comments
 (0)