Skip to content

Commit 7630d06

Browse files
improve(ui): quiet slash command menu hierarchy (#122237)
* improve(ui): quiet slash command menu hierarchy * improve(ui): compact slash command menu * improve(ui): polish slash command rows * improve(ui): streamline slash command sheet * chore(ui): refresh command copy baseline * fix(ui): keep skill selection in view * test(ui): type skill menu viewport stub
1 parent b529217 commit 7630d06

10 files changed

Lines changed: 321 additions & 284 deletions

File tree

‎ui/src/i18n/.i18n/raw-copy-baseline.json‎

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ui/src/i18n/locales/en.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,15 +4789,7 @@ export const en: TranslationMap = {
47894789
commands: {
47904790
arguments: "Command arguments",
47914791
menu: "Slash commands",
4792-
instant: "instant",
47934792
optionCount: "{count} options",
4794-
showMoreOne: "Show 1 more command",
4795-
showMoreMany: "Show {count} more commands",
4796-
navigate: "navigate",
4797-
fill: "fill",
4798-
run: "run",
4799-
select: "select",
4800-
close: "close",
48014793
clearDescription: "Clear chat history",
48024794
redirectDescription: "Abort and restart with a new message",
48034795
steerDescription: "Inject a message into the active run",

‎ui/src/lib/chat/commands.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,6 @@ export function getSkillCommandCompletions(filter: string): SlashCommandDef[] {
531531
.toSorted((left, right) => left.name.localeCompare(right.name));
532532
}
533533

534-
/** Count of commands hidden by tier filtering (for "Show N more" UI). */
535-
export function getHiddenCommandCount(): number {
536-
return SLASH_COMMANDS.filter((cmd) => (cmd.tier ?? "standard") === "power").length;
537-
}
538-
539534
type ParsedSlashCommand = {
540535
command: SlashCommandDef;
541536
args: string;

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,20 +3078,20 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
30783078

30793079
it("scrolls the keyboard-active slash option into view in short landscape", async () => {
30803080
const initiallyHidden = await page.evaluate(() => {
3081-
const menu = document.querySelector<HTMLElement>(".slash-menu");
3081+
const scrollRegion = document.querySelector<HTMLElement>(".slash-menu__scroll");
30823082
const options = Array.from(
30833083
document.querySelectorAll<HTMLElement>(".slash-menu-item[role='option']"),
30843084
);
30853085
const hiddenOption = options.find((option) => {
3086-
const menuRect = menu?.getBoundingClientRect();
3086+
const menuRect = scrollRegion?.getBoundingClientRect();
30873087
const optionRect = option.getBoundingClientRect();
30883088
return Boolean(menuRect && optionRect.bottom > menuRect.bottom + 1);
30893089
});
3090-
if (!menu || !hiddenOption) {
3090+
if (!scrollRegion || !hiddenOption) {
30913091
throw new Error("Expected an initially hidden slash option");
30923092
}
3093-
menu.scrollTop = 0;
3094-
const menuRect = menu.getBoundingClientRect();
3093+
scrollRegion.scrollTop = 0;
3094+
const menuRect = scrollRegion.getBoundingClientRect();
30953095
const itemRect = hiddenOption.getBoundingClientRect();
30963096
return {
30973097
id: hiddenOption.id,
@@ -3112,11 +3112,11 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
31123112
}, initiallyHidden.id);
31133113
await page.waitForFunction((expectedId) => {
31143114
const active = document.getElementById(expectedId);
3115-
const menu = active?.closest<HTMLElement>(".slash-menu");
3116-
if (!active || !menu) {
3115+
const scrollRegion = active?.closest<HTMLElement>(".slash-menu__scroll");
3116+
if (!active || !scrollRegion) {
31173117
return false;
31183118
}
3119-
const menuRect = menu.getBoundingClientRect();
3119+
const menuRect = scrollRegion.getBoundingClientRect();
31203120
const activeRect = active.getBoundingClientRect();
31213121
return activeRect.top >= menuRect.top - 1 && activeRect.bottom <= menuRect.bottom + 1;
31223122
}, initiallyHidden.id);
@@ -3125,17 +3125,17 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
31253125
const input = document.querySelector<HTMLTextAreaElement>(
31263126
".agent-chat__composer-combobox > textarea",
31273127
);
3128-
const menu = document.querySelector<HTMLElement>(".slash-menu");
3128+
const scrollRegion = document.querySelector<HTMLElement>(".slash-menu__scroll");
31293129
const active = document.querySelector<HTMLElement>(".slash-menu-item--active");
3130-
if (!input || !menu || !active) {
3130+
if (!input || !scrollRegion || !active) {
31313131
throw new Error("Expected active slash option after keyboard navigation");
31323132
}
3133-
const menuRect = menu.getBoundingClientRect();
3133+
const menuRect = scrollRegion.getBoundingClientRect();
31343134
const activeRect = active.getBoundingClientRect();
31353135
return {
31363136
activeDescendant: input.getAttribute("aria-activedescendant"),
31373137
focusedTag: document.activeElement?.tagName,
3138-
scrollTop: menu.scrollTop,
3138+
scrollTop: scrollRegion.scrollTop,
31393139
visible: activeRect.top >= menuRect.top - 1 && activeRect.bottom <= menuRect.bottom + 1,
31403140
};
31413141
});
@@ -3147,6 +3147,52 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
31473147
});
31483148
});
31493149

3150+
it("keeps overflowing skill suggestions on the nested scroll viewport", async () => {
3151+
const page = await openBrowserPage(568, 320);
3152+
try {
3153+
const items = Array.from({ length: 16 }, (_, index) => {
3154+
const active = index === 15 ? " slash-menu-item--active" : "";
3155+
return `<div class="slash-menu-item${active}" role="option">
3156+
<span class="slash-menu-leading">
3157+
<span class="slash-menu-icon">${iconSvg()}</span>
3158+
<span class="slash-menu-name">$skill_${index + 1}</span>
3159+
</span>
3160+
</div>`;
3161+
}).join("");
3162+
await page.setContent(`<!doctype html><html><head><style>${readUiCss()}</style></head><body>
3163+
<div class="slash-menu skill-menu" role="listbox">
3164+
<div class="slash-menu__scroll">${items}</div>
3165+
</div>
3166+
</body></html>`);
3167+
3168+
const result = await page.evaluate(() => {
3169+
const active = document.querySelector<HTMLElement>(".slash-menu-item--active");
3170+
const scrollRegion = active?.closest<HTMLElement>(".slash-menu__scroll");
3171+
if (!active || !scrollRegion) {
3172+
throw new Error("Expected an active skill inside the nested viewport");
3173+
}
3174+
const viewport = scrollRegion.getBoundingClientRect();
3175+
const option = active.getBoundingClientRect();
3176+
scrollRegion.scrollTop += option.bottom - viewport.bottom;
3177+
const settledOption = active.getBoundingClientRect();
3178+
const settledViewport = scrollRegion.getBoundingClientRect();
3179+
return {
3180+
outerScrollTop: active.closest<HTMLElement>(".skill-menu")?.scrollTop,
3181+
scrollTop: scrollRegion.scrollTop,
3182+
visible:
3183+
settledOption.top >= settledViewport.top - 1 &&
3184+
settledOption.bottom <= settledViewport.bottom + 1,
3185+
};
3186+
});
3187+
3188+
expect(result.outerScrollTop).toBe(0);
3189+
expect(result.scrollTop).toBeGreaterThan(0);
3190+
expect(result.visible).toBe(true);
3191+
} finally {
3192+
await closeBrowserPage(page);
3193+
}
3194+
});
3195+
31503196
it("uses the compact mobile grid when the agent filter is not rendered", async () => {
31513197
const page = await openFixture(320, 568, { singleAgent: true });
31523198
try {

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,65 @@ describe("chat slash menu accessibility", () => {
36863686
expect(container.querySelector(".skill-menu")).toBeNull();
36873687
});
36883688

3689+
it("scrolls the keyboard-active skill inside the nested menu viewport", () => {
3690+
replaceSkillCommands(
3691+
...Array.from({ length: 8 }, (_, index) => ({
3692+
key: `skill_${index + 1}`,
3693+
description: `Skill ${index + 1}.`,
3694+
})),
3695+
);
3696+
const animationFrames: FrameRequestCallback[] = [];
3697+
vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
3698+
animationFrames.push(callback);
3699+
return animationFrames.length;
3700+
});
3701+
vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(
3702+
function (this: HTMLElement) {
3703+
const height = 28;
3704+
let top = 0;
3705+
if (this.classList.contains("slash-menu-item")) {
3706+
const scrollRegion = this.closest<HTMLElement>(".slash-menu__scroll");
3707+
const options = Array.from(
3708+
scrollRegion?.querySelectorAll<HTMLElement>(".slash-menu-item") ?? [],
3709+
);
3710+
top = options.indexOf(this) * height - (scrollRegion?.scrollTop ?? 0);
3711+
}
3712+
const bottom = this.classList.contains("slash-menu__scroll") ? height * 2 : top + height;
3713+
return {
3714+
bottom,
3715+
height: bottom - top,
3716+
left: 0,
3717+
right: 240,
3718+
top,
3719+
width: 240,
3720+
x: 0,
3721+
y: top,
3722+
toJSON: () => ({}),
3723+
};
3724+
},
3725+
);
3726+
const { container } = createReactiveDraftHarness();
3727+
document.body.append(container);
3728+
inputDraftAtEnd(container, "Use $");
3729+
animationFrames.length = 0;
3730+
3731+
for (let index = 0; index < 4; index += 1) {
3732+
keydownComposer(container, "ArrowDown");
3733+
}
3734+
animationFrames.at(-1)?.(0);
3735+
3736+
const scrollRegion = container.querySelector<HTMLElement>(".skill-menu .slash-menu__scroll");
3737+
const outerMenu = container.querySelector<HTMLElement>(".skill-menu");
3738+
const activeOption = container.querySelector<HTMLElement>(".slash-menu-item--active");
3739+
const viewportBounds = scrollRegion?.getBoundingClientRect();
3740+
const optionBounds = activeOption?.getBoundingClientRect();
3741+
expect(scrollRegion?.scrollTop).toBeGreaterThan(0);
3742+
expect(outerMenu?.scrollTop).toBe(0);
3743+
expect(optionBounds?.top).toBeGreaterThanOrEqual(viewportBounds?.top ?? 0);
3744+
expect(optionBounds?.bottom).toBeLessThanOrEqual(viewportBounds?.bottom ?? 0);
3745+
container.remove();
3746+
});
3747+
36893748
it("does not reopen a dismissed skill picker after a slow refresh", async () => {
36903749
replaceSkillCommands({ key: "prose", description: "Prose skill." });
36913750
const refresh = createDeferred();
@@ -3985,6 +4044,47 @@ describe("chat slash menu accessibility", () => {
39854044
expect(listbox?.querySelector(`#${activeId}`)?.getAttribute("role")).toBe("option");
39864045
});
39874046

4047+
it("removes instant implementation badges without hiding option counts", () => {
4048+
const harness = createSlashRerenderHarness();
4049+
const container = harness.inputAndRender(harness.container, "/");
4050+
const stopOption = Array.from(
4051+
container.querySelectorAll<HTMLElement>(".slash-menu [role='option']"),
4052+
).find((option) => option.querySelector(".slash-menu-name")?.textContent?.trim() === "/stop");
4053+
4054+
expect(stopOption).toBeDefined();
4055+
expect(stopOption?.querySelector(".slash-menu-badge")).toBeNull();
4056+
expect(container.querySelector(".slash-menu-badge")).not.toBeNull();
4057+
});
4058+
4059+
it("shows every command directly without an expander or keyboard footer", () => {
4060+
replaceSlashCommands([
4061+
{
4062+
key: "standard-command",
4063+
name: "standard-command",
4064+
description: "Standard command.",
4065+
tier: "standard",
4066+
category: "session",
4067+
},
4068+
{
4069+
key: "power-command",
4070+
name: "power-command",
4071+
description: "Power command.",
4072+
tier: "power",
4073+
category: "tools",
4074+
},
4075+
]);
4076+
const harness = createSlashRerenderHarness();
4077+
const container = harness.inputAndRender(harness.container, "/");
4078+
4079+
expect(
4080+
Array.from(container.querySelectorAll<HTMLElement>(".slash-menu [role='option']")).map(
4081+
(option) => option.querySelector(".slash-menu-name")?.textContent?.trim(),
4082+
),
4083+
).toEqual(["/standard-command", "/power-command"]);
4084+
expect(container.querySelector(".slash-menu-show-more")).toBeNull();
4085+
expect(container.querySelector(".slash-menu-footer")).toBeNull();
4086+
});
4087+
39884088
it("keeps filtered command DOM and keyboard order aligned with relevance", () => {
39894089
replaceSlashCommands([
39904090
{

0 commit comments

Comments
 (0)