Skip to content

🙌 OpenHands: AI-Driven Development

feat(conversation): give the drawer tab strip real tab semantics (#17612)

Denis Ermakov64f12b3a3294
diff --git a/.pr/issue-17268/index.html b/.pr/issue-17268/index.html
new file mode 100644
index 0000000000..7e175d8ab1
--- /dev/null
+++ b/.pr/issue-17268/index.html
@@ -0,0 +1,457 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <title>Accessible conversation drawer tabs — review doc</title>
+ <style>
+ :root {
+ --bg: #101114;
+ --panel: #17191d;
+ --panel-2: #1d2026;
+ --ink: #e8e9ec;
+ --muted: #9aa0ab;
+ --line: #2a2e36;
+ --accent: #f2c94c;
+ --good: #5ac48b;
+ --bad: #e2766b;
+ --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
+ }
+ * { box-sizing: border-box; }
+ body {
+ margin: 0;
+ background: var(--bg);
+ color: var(--ink);
+ font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
+ }
+ .wrap { max-width: 1040px; margin: 0 auto; padding: 40px 20px 80px; }
+ header h1 { font-size: 30px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.02em; }
+ header .sub { color: var(--muted); font-size: 14px; margin: 0 0 4px; }
+ header .stats { color: var(--muted); font-size: 13px; font-family: var(--mono); }
+ .star {
+ margin: 24px 0 32px;
+ border: 1px solid var(--accent);
+ border-left-width: 4px;
+ border-radius: 8px;
+ background: rgba(242, 201, 76, 0.07);
+ padding: 16px 18px;
+ }
+ .star b { color: var(--accent); }
+ h2 {
+ font-size: 20px;
+ margin: 40px 0 14px;
+ padding-bottom: 8px;
+ border-bottom: 1px solid var(--line);
+ letter-spacing: -0.01em;
+ }
+ h3 { font-size: 16px; margin: 26px 0 8px; }
+ p { margin: 10px 0; }
+ code, .mono { font-family: var(--mono); font-size: 13px; }
+ code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
+ a { color: #8ab4f8; }
+ .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
+ @media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
+ .card {
+ background: var(--panel);
+ border: 1px solid var(--line);
+ border-radius: 10px;
+ padding: 14px 16px;
+ }
+ .card h4 { margin: 0 0 10px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
+ .card.before h4 { color: var(--bad); }
+ .card.after h4 { color: var(--good); }
+ pre {
+ margin: 0;
+ overflow-x: auto;
+ font-family: var(--mono);
+ font-size: 12.5px;
+ line-height: 1.55;
+ color: #cfd3da;
+ white-space: pre;
+ }
+ figure { margin: 14px 0 0; }
+ figure img { width: 100%; border: 1px solid var(--line); border-radius: 8px; display: block; }
+ figcaption { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
+ table { border-collapse: collapse; width: 100%; font-size: 14px; }
+ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
+ th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; }
+ td.path { font-family: var(--mono); font-size: 12.5px; }
+ .tag { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
+ ul { margin: 10px 0; padding-left: 20px; }
+ li { margin: 4px 0; }
+ .note { color: var(--muted); font-size: 13.5px; }
+ </style>
+ </head>
+ <body>
+ <div class="wrap">
+ <header>
+ <h1>Accessible conversation drawer tabs</h1>
+ <p class="sub">
+ Review doc for <strong>OpenHands/OpenHands#17268</strong> — conversation
+ drawer tabs need accessible semantics and collision-aware overflow.
+ </p>
+ <p class="stats">
+ base cf1cc69f · 10 code files · updated after the first review
+ </p>
+ </header>
+
+ <div class="star">
+ <b>★ The whole change lives in one folder</b>
+ (<code>src/components/features/conversation/conversation-tabs/</code>) plus two
+ new translation keys. Nothing in the tab store, the pin/unpin preferences,
+ or the responsive overflow measurement moves — the strip keeps the exact
+ same DOM shape and click behaviour, and gains ARIA attributes, a roving
+ tabindex, and a viewport clamp on the portaled menu. The one behavioural
+ change a mouse user can notice is the overflow menu no longer running off
+ the right edge of the viewport.
+ </div>
+
+ <h2>1 · What a screen-reader / keyboard user gets</h2>
+
+ <p class="note">
+ Captured from a real Chromium session against <code>npm run dev:mock</code>,
+ on this branch and on its merge-base, same viewport (1280×800) and same
+ drawer width. <code>ariaSnapshot()</code> is Playwright's view of the
+ browser's accessibility tree — not our own assertion of it.
+ </p>
+
+ <div class="grid2">
+ <div class="card before">
+ <h4>Before — accessibility tree of the tab strip</h4>
+<pre>- button "Files":
+ - img
+ - text: Files
+- button:
+ - img
+- button
+- button "More options":
+ - img</pre>
+ <p class="note">
+ No tablist, no tabs, no selected state. Every tab except the open one
+ hides its label, so it reaches assistive tech as an unnamed
+ <code>button</code>. The overflow trigger is "More options".
+ </p>
+ </div>
+ <div class="card after">
+ <h4>After — accessibility tree of the tab strip</h4>
+<pre>- tablist "Conversation panels":
+ - tab "Files" [selected]:
+ - img
+ - text: Files
+ - tab "Commits":
+ - img
+ - tab "Planner"
+ - tab "Terminal"
+ - tab "Browser"
+ - tab "Usage"
+- button "Customize tabs":
+ - img</pre>
+ <p class="note">
+ Every control is a named <code>tab</code> inside a named
+ <code>tablist</code>, with the open one marked selected.
+ </p>
+ </div>
+ </div>
+
+ <h3>Keyboard: two <kbd>→</kbd> presses from the open Files tab</h3>
+ <div class="grid2">
+ <div class="card before">
+ <h4>Before — focus does not move</h4>
+ <figure>
+ <img src="./keyboard-before.png" onerror="this.onerror=null;this.src='https://raw.githubusercontent.com/errmakov/OpenHands/feat/accessible-conversation-drawer-tabs/.pr/issue-17268/keyboard-before.png'" alt="Tab strip with the focus ring still on the Files tab after two right-arrow presses" />
+ <figcaption>
+ <code>document.activeElement</code> →
+ <code>conversation-tab-files</code>, <code>aria-label: null</code>.
+ Arrow keys do nothing; every tab is its own <kbd>Tab</kbd> stop.
+ </figcaption>
+ </figure>
+ </div>
+ <div class="card after">
+ <h4>After — focus roves, selection stays put</h4>
+ <figure>
+ <img src="./keyboard-after.png" onerror="this.onerror=null;this.src='https://raw.githubusercontent.com/errmakov/OpenHands/feat/accessible-conversation-drawer-tabs/.pr/issue-17268/keyboard-after.png'" alt="Tab strip with the focus ring on the third tab while Files remains the selected tab" />
+ <figcaption>
+ <code>document.activeElement</code> →
+ <code>conversation-tab-planner</code>,
+ <code>aria-label: "Planner"</code>. Files is still the selected tab —
+ activation is manual (<kbd>Enter</kbd>/<kbd>Space</kbd>), so scanning
+ the strip does not thrash the drawer.
+ </figcaption>
+ </figure>
+ </div>
+ </div>
+
+ <h2>2 · The overflow menu at the viewport edge</h2>
+
+ <p>
+ The menu is portaled to <code>document.body</code> with
+ <code>position: fixed</code>. It was anchored with
+ <code>left: rect.left</code> and nothing else, so wherever the trigger sat
+ near the right edge — an embedded canvas, or just a narrow drawer — the
+ labels and the pin controls fell outside the viewport with no way to reach
+ them.
+ </p>
+
+ <div class="grid2">
+ <div class="card before">
+ <h4>Before — 87px of the menu is off-screen</h4>
+ <figure>
+ <img src="./overflow-menu-before.png" onerror="this.onerror=null;this.src='https://raw.githubusercontent.com/errmakov/OpenHands/feat/accessible-conversation-drawer-tabs/.pr/issue-17268/overflow-menu-before.png'" alt="Overflow menu clipped at the right edge, showing only the first letter of each tab name and no pin controls" />
+ <figcaption>
+ trigger <code>x = 1234.6</code> · menu
+ <code>x = 1234.6, w = 132.2</code> · viewport <code>1280</code> →
+ <strong>87px clipped</strong>. Labels read "P / F / C / T / B / U";
+ the pin toggles are unreachable.
+ </figcaption>
+ </figure>
+ </div>
+ <div class="card after">
+ <h4>After — clamped inside the viewport</h4>
+ <figure>
+ <img src="./overflow-menu-after.png" onerror="this.onerror=null;this.src='https://raw.githubusercontent.com/errmakov/OpenHands/feat/accessible-conversation-drawer-tabs/.pr/issue-17268/overflow-menu-after.png'" alt="Overflow menu fully inside the viewport with full tab names and pin controls visible" />
+ <figcaption>
+ same trigger · menu <code>x = 1139.8, w = 132.2</code> → right edge
+ <code>1272</code> · <strong>0px clipped</strong>. Full labels and the
+ pin toggles are visible.
+ </figcaption>
+ </figure>
+ </div>
+ </div>
+
+ <h3>The placement rule</h3>
+ <div class="grid2">
+ <div class="card before">
+ <h4>Before</h4>
+<pre>const gap = 8;
+setPortalStyle({
+ position: "fixed",
+ zIndex: 9999,
+ top: rect.bottom + gap,
+ left: rect.left,
+});</pre>
+ </div>
+ <div class="card after">
+ <h4>After</h4>
+<pre>const menuRect = ref.current?.getBoundingClientRect();
+
+const overflowsBelow =
+ rect.bottom + MENU_GAP_PX + (menuRect?.height ?? 0) &gt;
+ window.innerHeight;
+
+const rightmostLeft =
+ window.innerWidth - (menuRect?.width ?? 0)
+ - MENU_VIEWPORT_MARGIN_PX;
+
+setPortalStyle({
+ position: "fixed",
+ zIndex: 9999,
+ ...(overflowsBelow
+ ? { bottom: window.innerHeight - rect.top + MENU_GAP_PX }
+ : { top: rect.bottom + MENU_GAP_PX }),
+ left: Math.max(
+ MENU_VIEWPORT_MARGIN_PX,
+ Math.min(rect.left, rightmostLeft),
+ ),
+});</pre>
+ </div>
+ </div>
+ <p class="note">
+ The menu's own box is only measurable once it has painted, so the first
+ pass falls back to the trigger and a
+ <code>requestAnimationFrame</code> re-runs with real dimensions — the same
+ two-pass shape already used by the automations kebab menu
+ (<code>src/components/features/automations/kebab-menu.tsx</code>, PR #16926),
+ which this now matches, plus the horizontal clamp.
+ </p>
+
+ <h2>3 · Component API</h2>
+
+ <p>
+ <code>ConversationTabNav</code> gains three optional props. All are
+ additive; the measurement clones in the offscreen
+ <code>aria-hidden</code> row pass none of them and stay inert.
+ </p>
+
+ <div class="grid2">
+ <div class="card before">
+ <h4>Before</h4>
+<pre>type ConversationTabNavProps = {
+ tabValue: string;
+ icon: ComponentType&lt;{ className: string }&gt;;
+ onClick(): void;
+ isActive?: boolean;
+ label?: string;
+ className?: string;
+ measureOnly?: boolean;
+ suppressLayoutAnimation?: boolean;
+};</pre>
+ </div>
+ <div class="card after">
+ <h4>After</h4>
+<pre>type ConversationTabNavProps = {
+ tabValue: string;
+ icon: ComponentType&lt;{ className: string }&gt;;
+ onClick(): void;
+ isActive?: boolean;
+ label?: string;
+ className?: string;
+ measureOnly?: boolean;
+ suppressLayoutAnimation?: boolean;
+ <b>isSelected?: boolean;</b>
+ <b>tabIndex?: number;</b>
+ <b>onKeyDown?(event: KeyboardEvent&lt;HTMLButtonElement&gt;): void;</b>
+ <b>buttonRef?: Ref&lt;HTMLButtonElement&gt;;</b>
+};</pre>
+ </div>
+ </div>
+
+ <h3>New module: <code>conversation-tab-ids.ts</code></h3>
+<pre class="card">export const CONVERSATION_TAB_PANEL_ID = "conversation-tab-panel";</pre>
+ <p class="note">
+ Every tab's <code>aria-controls</code> and the panel's <code>id</code>
+ need the same identifier. The desktop drawer and the mobile
+ <code>/panel</code> route each render one strip and one panel and never
+ mount together, so a constant panel id is unambiguous.
+ </p>
+
+ <h3>Two states the first revision got wrong (fixed after review)</h3>
+ <ul>
+ <li>
+ <strong>Drawer closed.</strong> The collapsed drawer is only
+ <code>w-0 translate-x-full opacity-0</code>, so the strip stays in the
+ accessibility tree. <code>aria-selected</code> and the roving tab stop
+ were derived from <code>isTabActive</code> (selected <em>and</em> drawer
+ open), which left the tablist with no selected tab. They now follow
+ <code>selectedTab</code> through a separate <code>isSelected</code> prop;
+ <code>isActive</code> still drives only the highlight and the expanded
+ label, so nothing changes visually.
+ </li>
+ <li>
+ <strong>Selected tab in the overflow menu.</strong> The panel was named
+ with <code>aria-labelledby</code> pointing at the selected tab's button,
+ which is not in the DOM when a narrow drawer pushes that tab into the
+ overflow menu. The panel now carries the tab's name as
+ <code>aria-label</code>, which holds in every overflow state — including
+ the one where no tab fits inline at all.
+ </li>
+ </ul>
+
+ <h2>4 · Files</h2>
+ <table>
+ <thead>
+ <tr><th>File</th><th></th><th>What changed</th></tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td class="path">conversation-tabs/conversation-tab-ids.ts</td>
+ <td><span class="tag">added</span></td>
+ <td>The panel id and the tab-id helper shared by the strip and the panel.</td>
+ </tr>
+ <tr>
+ <td class="path">conversation-tabs/conversation-tab-nav.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ Real tabs get <code>role="tab"</code>, <code>aria-selected</code>
+ (from the new <code>isSelected</code>, independent of the drawer being
+ open), <code>aria-controls</code>, an explicit
+ <code>aria-label</code>, and the roving <code>tabIndex</code> /
+ <code>onKeyDown</code> / <code>ref</code>. Measurement clones get
+ <code>tabIndex=-1</code> and no role, so the offscreen
+ <code>aria-hidden</code> row holds no focusable elements.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">conversation-tabs/conversation-tabs.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ The inline row becomes the <code>tablist</code> (dropped when a narrow
+ drawer pushes every tab into the menu — a tablist owning no tabs is
+ not a tablist). Adds the roving-tabindex state and the
+ <code>←/→/Home/End</code> handler, and renames the overflow trigger.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">conversation-tabs/conversation-tabs-context-menu.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>Viewport-aware portal placement (clamp + flip), see §2.</td>
+ </tr>
+ <tr>
+ <td class="path">conversation-tab-content/tab-container.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ Becomes the <code>role="tabpanel"</code> with the shared id and an
+ <code>aria-label</code> carrying the selected tab's name.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">conversation-tab-content/conversation-tab-content.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ <code>TAB_CONFIG</code> gains a <code>labelKey</code> per tab; passes
+ <code>label={t(activeTab.labelKey)}</code> to the panel.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">src/i18n/translation.json</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ <code>CONVERSATION$TABS_LABEL</code> ("Conversation panels") and
+ <code>CONVERSATION$CUSTOMIZE_TABS</code> ("Customize tabs"), both with
+ all 15 locales.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">__tests__/…/conversation-tabs.test.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ Seven cases: tablist + <code>aria-selected</code> +
+ <code>aria-controls</code>; the selected tab stays marked and on the
+ tab stop with the drawer closed; icon-only tabs are named; the open
+ tab holds the only tab stop; arrows move focus without changing the
+ open tab; <kbd>Enter</kbd> activates; the trigger's name.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">__tests__/…/conversation-tabs-context-menu.test.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>
+ Three placement cases against stubbed trigger/menu rects: anchors
+ below-left when it fits, clamps at the right edge, flips above at the
+ bottom edge.
+ </td>
+ </tr>
+ <tr>
+ <td class="path">__tests__/…/conversation-tab-content.test.tsx</td>
+ <td><span class="tag">changed</span></td>
+ <td>The content area is the <code>tabpanel</code>, named after the selected tab without an id reference.</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <h2>5 · What is deliberately not in this PR</h2>
+ <ul>
+ <li>
+ <strong>No <code>tabIndex={0}</code> on the panel.</strong> APG only asks
+ for it when the panel has no focusable content; these panels host a file
+ tree, a terminal and a browser view, and adding a focus stop over the
+ whole drawer risked changing terminal focus handling for no gain.
+ </li>
+ <li>
+ <strong>No <code>aria-expanded</code> on the overflow trigger.</strong>
+ That means touching the shared <code>EllipsisButton</code> used by four
+ other surfaces; the issue asks for the trigger's <em>name</em>, so that is
+ what changed here.
+ </li>
+ <li>
+ <strong>No change to pin/unpin or to the overflow measurement.</strong>
+ The existing localStorage tests cover both and still pass unmodified.
+ </li>
+ </ul>
+
+ <p class="note" style="margin-top: 36px">
+ This page is a review aid under <code>.pr/</code> and is removed before
+ merge by <code>.github/workflows/pr-artifacts.yml</code>.
+ </p>
+ </div>
+ </body>
+</html>
diff --git a/.pr/issue-17268/keyboard-after.png b/.pr/issue-17268/keyboard-after.png
new file mode 100644
index 0000000000..122dd7accb
Binary files /dev/null and b/.pr/issue-17268/keyboard-after.png differ
diff --git a/.pr/issue-17268/keyboard-before.png b/.pr/issue-17268/keyboard-before.png
new file mode 100644
index 0000000000..0401a850e9
Binary files /dev/null and b/.pr/issue-17268/keyboard-before.png differ
diff --git a/.pr/issue-17268/overflow-menu-after.png b/.pr/issue-17268/overflow-menu-after.png
new file mode 100644
index 0000000000..2ccd459e6a
Binary files /dev/null and b/.pr/issue-17268/overflow-menu-after.png differ
diff --git a/.pr/issue-17268/overflow-menu-before.png b/.pr/issue-17268/overflow-menu-before.png
new file mode 100644
index 0000000000..38c066873f
Binary files /dev/null and b/.pr/issue-17268/overflow-menu-before.png differ
diff --git a/__tests__/components/features/conversation/conversation-tab-content.test.tsx b/__tests__/components/features/conversation/conversation-tab-content.test.tsx
index bae5fb21e5..183f60a1d8 100644
--- a/__tests__/components/features/conversation/conversation-tab-content.test.tsx
+++ b/__tests__/components/features/conversation/conversation-tab-content.test.tsx
@@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MemoryRouter } from "react-router";
import { ConversationTabContent } from "#/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content";
+import { CONVERSATION_TAB_PANEL_ID } from "#/components/features/conversation/conversation-tabs/conversation-tab-ids";
import {
useConversationStore,
ConversationTab,
@@ -99,6 +100,18 @@ describe("ConversationTabContent", () => {
});
});
+ it("should expose the content area as a panel named after the selected tab", () => {
+ setSelectedTab("browser");
+
+ render(<ConversationTabContent />, { wrapper: createWrapper() });
+
+ // Named directly rather than by reference: the selected tab's button is
+ // not in the DOM when a narrow drawer pushes it into the overflow menu.
+ const panel = screen.getByRole("tabpanel", { name: "COMMON$BROWSER" });
+ expect(panel).toHaveAttribute("id", CONVERSATION_TAB_PANEL_ID);
+ expect(panel).not.toHaveAttribute("aria-labelledby");
+ });
+
it("should render files tab when selectedTab is null", async () => {
setSelectedTab(null);
diff --git a/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx b/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
index 53dacf79d7..d0d30799be 100644
--- a/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
+++ b/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
@@ -1,4 +1,5 @@
import { render, screen } from "@testing-library/react";
+import { useRef } from "react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { ConversationTabsContextMenu } from "#/components/features/conversation/conversation-tabs/conversation-tabs-context-menu";
@@ -39,6 +40,76 @@ function seedActiveBackend(backend: Backend): void {
__resetActiveStoreForTests();
}
+const MENU_WIDTH = 220;
+const MENU_HEIGHT = 300;
+
+/**
+ * Renders the menu against a trigger pinned to a fixed viewport rect so the
+ * portal's collision handling can be asserted. jsdom reports a 1024x768
+ * viewport and zero-sized elements, so both rects are stubbed.
+ */
+function AnchoredMenu({
+ top,
+ bottom,
+ left,
+}: {
+ top: number;
+ bottom: number;
+ left: number;
+}) {
+ const anchorRef = useRef<HTMLButtonElement>(null);
+
+ const setAnchorRect = (node: HTMLButtonElement | null) => {
+ anchorRef.current = node;
+ if (!node) return;
+ vi.spyOn(node, "getBoundingClientRect").mockReturnValue({
+ top,
+ bottom,
+ left,
+ right: left + 24,
+ width: 24,
+ height: bottom - top,
+ x: left,
+ y: top,
+ toJSON: () => ({}),
+ } as DOMRect);
+ };
+
+ return (
+ <>
+ <button type="button" ref={setAnchorRect} />
+ <ConversationTabsContextMenu
+ isOpen
+ onClose={vi.fn()}
+ anchorRef={anchorRef}
+ />
+ </>
+ );
+}
+
+const renderAnchoredMenu = (rect: {
+ top: number;
+ bottom: number;
+ left: number;
+}) => {
+ vi.spyOn(HTMLUListElement.prototype, "getBoundingClientRect").mockReturnValue(
+ {
+ width: MENU_WIDTH,
+ height: MENU_HEIGHT,
+ top: 0,
+ bottom: MENU_HEIGHT,
+ left: 0,
+ right: MENU_WIDTH,
+ x: 0,
+ y: 0,
+ toJSON: () => ({}),
+ } as DOMRect,
+ );
+
+ render(<AnchoredMenu {...rect} />);
+ return document.querySelector<HTMLElement>('div[style*="position: fixed"]');
+};
+
describe("ConversationTabsContextMenu", () => {
beforeEach(() => {
localStorage.clear();
@@ -170,4 +241,31 @@ describe("ConversationTabsContextMenu", () => {
expect(screen.getByText("COMMON$TASK_LIST")).toBeInTheDocument();
});
});
+
+ describe("portal placement", () => {
+ it("anchors below and to the left of the trigger when the menu fits", () => {
+ const portal = renderAnchoredMenu({ top: 20, bottom: 44, left: 300 });
+
+ expect(portal?.style.top).toBe("52px");
+ expect(portal?.style.left).toBe("300px");
+ expect(portal?.style.bottom).toBe("");
+ });
+
+ it("keeps the menu inside the viewport when the trigger hugs the right edge", () => {
+ // An embedded canvas can sit hard against the viewport edge; left-aligning
+ // on the trigger there would clip the labels and the pin controls.
+ const portal = renderAnchoredMenu({ top: 20, bottom: 44, left: 1000 });
+
+ // 1024 (jsdom viewport) - 220 (menu) - 8 (margin)
+ expect(portal?.style.left).toBe("796px");
+ });
+
+ it("flips above the trigger when the menu would clip at the viewport bottom", () => {
+ const portal = renderAnchoredMenu({ top: 700, bottom: 724, left: 300 });
+
+ // 768 (jsdom viewport) - 700 (trigger top) + 8 (gap)
+ expect(portal?.style.bottom).toBe("76px");
+ expect(portal?.style.top).toBe("");
+ });
+ });
});
diff --git a/__tests__/components/features/conversation/conversation-tabs.test.tsx b/__tests__/components/features/conversation/conversation-tabs.test.tsx
index f65df72e74..c6d7ec6ab5 100644
--- a/__tests__/components/features/conversation/conversation-tabs.test.tsx
+++ b/__tests__/components/features/conversation/conversation-tabs.test.tsx
@@ -1,9 +1,10 @@
-import { render, screen } from "@testing-library/react";
+import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MemoryRouter } from "react-router";
import { ConversationTabs } from "#/components/features/conversation/conversation-tabs/conversation-tabs";
+import { CONVERSATION_TAB_PANEL_ID } from "#/components/features/conversation/conversation-tabs/conversation-tab-ids";
import { useConversationStore } from "#/stores/conversation-store";
import { AgentState } from "#/types/agent-state";
import { ActiveBackendProvider } from "#/contexts/active-backend-context";
@@ -671,4 +672,131 @@ describe("ConversationTabs localStorage behavior", () => {
expect(hasRightPanelToggled).toBe(true);
});
});
+ describe("accessible tab semantics", () => {
+ beforeEach(() => {
+ mockConversationId = REAL_CONVERSATION_ID;
+ });
+
+ it("exposes the tab strip as a tablist and marks the open tab selected", () => {
+ setActiveTabState("files");
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ const tablist = screen.getByRole("tablist");
+ expect(within(tablist).getAllByRole("tab").length).toBeGreaterThan(1);
+
+ const filesTab = screen.getByTestId("conversation-tab-files");
+ expect(filesTab).toHaveAttribute("aria-selected", "true");
+ expect(filesTab).toHaveAttribute(
+ "aria-controls",
+ CONVERSATION_TAB_PANEL_ID,
+ );
+ expect(screen.getByTestId("conversation-tab-browser")).toHaveAttribute(
+ "aria-selected",
+ "false",
+ );
+ });
+
+ it("keeps the selected tab marked, and on the tab stop, while the drawer is closed", () => {
+ // The strip stays in the accessibility tree when the drawer collapses,
+ // so the tab the drawer will reopen on must still read as selected.
+ seedConversationState(REAL_CONVERSATION_ID, { selectedTab: "terminal" });
+ useConversationStore.setState({
+ selectedTab: "terminal",
+ isRightPanelShown: false,
+ hasRightPanelToggled: false,
+ });
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ const terminalTab = screen.getByTestId("conversation-tab-terminal");
+ expect(terminalTab).toHaveAttribute("aria-selected", "true");
+ expect(terminalTab).toHaveAttribute("tabindex", "0");
+ expect(screen.getByTestId("conversation-tab-files")).toHaveAttribute(
+ "tabindex",
+ "-1",
+ );
+ });
+
+ it("names every tab, including the ones rendering icon-only", () => {
+ setActiveTabState("files");
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ // Inactive tabs hide their label, so without an explicit name they
+ // would be announced as an unlabelled button.
+ expect(
+ screen.getByRole("tab", { name: "COMMON$BROWSER" }),
+ ).toBeInTheDocument();
+ });
+
+ it("gives the open tab the strip's only tab stop", () => {
+ setActiveTabState("files");
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ expect(screen.getByTestId("conversation-tab-files")).toHaveAttribute(
+ "tabindex",
+ "0",
+ );
+ expect(screen.getByTestId("conversation-tab-commits")).toHaveAttribute(
+ "tabindex",
+ "-1",
+ );
+ });
+
+ it("moves focus with the arrow keys without changing the open tab", async () => {
+ setActiveTabState("files");
+ const user = userEvent.setup();
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ screen.getByTestId("conversation-tab-files").focus();
+ await user.keyboard("{ArrowRight}");
+
+ expect(screen.getByTestId("conversation-tab-commits")).toHaveFocus();
+ expect(useConversationStore.getState().selectedTab).toBe("files");
+
+ // Wraps around the start of the strip.
+ await user.keyboard("{ArrowLeft}{ArrowLeft}");
+ expect(screen.getByTestId("conversation-tab-usage")).toHaveFocus();
+ });
+
+ it("activates the focused tab with Enter", async () => {
+ setActiveTabState("files");
+ const user = userEvent.setup();
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ screen.getByTestId("conversation-tab-files").focus();
+ await user.keyboard("{ArrowRight}{Enter}");
+
+ expect(useConversationStore.getState().selectedTab).toBe("commits");
+ });
+
+ it("names the overflow trigger for what it customizes", () => {
+ setActiveTabState("files");
+
+ render(<ConversationTabs />, {
+ wrapper: createWrapper(REAL_CONVERSATION_ID),
+ });
+
+ expect(screen.getByTestId("ellipsis-button")).toHaveAttribute(
+ "aria-label",
+ "CONVERSATION$CUSTOMIZE_TABS",
+ );
+ });
+ });
});
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx
index 4f2da30496..8f08cb8346 100644
--- a/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx
+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content.tsx
@@ -1,10 +1,12 @@
import { lazy, useMemo } from "react";
+import { useTranslation } from "react-i18next";
import { TabWrapper } from "./tab-wrapper";
import { TabContainer } from "./tab-container";
import { TabContentArea } from "./tab-content-area";
import { ConversationTabContentCrossfade } from "./conversation-tab-content-crossfade";
import { useConversationStore } from "#/stores/conversation-store";
import { useConversationId } from "#/hooks/use-conversation-id";
+import { CONVERSATION_TAB_LABEL_KEYS } from "../conversation-tab-ids";
// Lazy load all tab components, including the terminal — xterm + addon-fit +
// xterm.css are large enough that we don't want them in the conversation
@@ -28,6 +30,7 @@ const TAB_CONFIG = {
};
export function ConversationTabContent() {
+ const { t } = useTranslation("openhands");
const { selectedTab, shouldShownAgentLoading } = useConversationStore();
const { conversationId } = useConversationId();
@@ -45,7 +48,9 @@ export function ConversationTabContent() {
: (selectedTab ?? "files");
return (
- <TabContainer>
+ <TabContainer
+ label={t(CONVERSATION_TAB_LABEL_KEYS[selectedTab ?? "files"])}
+ >
<TabContentArea>
<ConversationTabContentCrossfade
showAgentLoading={shouldShownAgentLoading}
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-container.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-container.tsx
index b6333eb69f..a35b0ae45d 100644
--- a/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-container.tsx
+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-container.tsx
@@ -1,9 +1,26 @@
import { ReactNode } from "react";
+import { CONVERSATION_TAB_PANEL_ID } from "../conversation-tab-ids";
interface TabContainerProps {
children: ReactNode;
+ /**
+ * Accessible name: the name of the tab whose content is showing. Passed as
+ * text rather than as an `aria-labelledby` reference because that tab's
+ * button leaves the DOM when a narrow drawer pushes it into the overflow
+ * menu, which would leave the panel unnamed.
+ */
+ label: string;
}
-export function TabContainer({ children }: TabContainerProps) {
- return <div className="flex flex-col h-full w-full">{children}</div>;
+export function TabContainer({ children, label }: TabContainerProps) {
+ return (
+ <div
+ id={CONVERSATION_TAB_PANEL_ID}
+ role="tabpanel"
+ aria-label={label}
+ className="flex flex-col h-full w-full"
+ >
+ {children}
+ </div>
+ );
}
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-ids.ts b/src/components/features/conversation/conversation-tabs/conversation-tab-ids.ts
new file mode 100644
index 0000000000..0dc49d1059
--- /dev/null
+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-ids.ts
@@ -0,0 +1,22 @@
+import { I18nKey } from "#/i18n/declaration";
+import type { ConversationTab } from "#/stores/conversation-store";
+
+/**
+ * DOM id of the drawer's tab panel, referenced by every tab's `aria-controls`.
+ *
+ * The desktop drawer and the mobile `/panel` route each render one tab
+ * strip plus one panel, and never both at once, so a constant panel id is
+ * unambiguous.
+ */
+export const CONVERSATION_TAB_PANEL_ID = "conversation-tab-panel";
+
+/** Each tab's name: shown in the strip and naming the panel it controls. */
+export const CONVERSATION_TAB_LABEL_KEYS: Record<ConversationTab, I18nKey> = {
+ files: I18nKey.COMMON$FILES,
+ commits: I18nKey.DIFF_VIEWER$COMMITS,
+ planner: I18nKey.COMMON$PLANNER,
+ tasklist: I18nKey.COMMON$TASK_LIST,
+ terminal: I18nKey.COMMON$TERMINAL,
+ browser: I18nKey.COMMON$BROWSER,
+ usage: I18nKey.COMMON$USAGE,
+};
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-nav.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-nav.tsx
index 0a84ef6ddb..e167ec7815 100644
--- a/src/components/features/conversation/conversation-tabs/conversation-tab-nav.tsx
+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-nav.tsx
@@ -1,6 +1,7 @@
-import { ComponentType } from "react";
+import { ComponentType, KeyboardEvent, Ref } from "react";
import { motion, useReducedMotion } from "framer-motion";
import { cn } from "#/utils/utils";
+import { CONVERSATION_TAB_PANEL_ID } from "./conversation-tab-ids";
const TAB_LABEL_MAX_WIDTH_PX = 160;
@@ -13,13 +14,24 @@ type ConversationTabNavProps = {
tabValue: string;
icon: ComponentType<{ className: string }>;
onClick(): void;
+ /** Selected and showing: drives the highlight and the expanded label. */
isActive?: boolean;
+ /**
+ * Selected, whether or not the drawer is open. The strip stays in the
+ * accessibility tree while the drawer is collapsed, so `aria-selected`
+ * follows this rather than `isActive`.
+ */
+ isSelected?: boolean;
label?: string;
className?: string;
/** Omit test id (e.g. offscreen width measurement clones). */
measureOnly?: boolean;
/** Disable layout-driven shifts while the drawer width is being dragged. */
suppressLayoutAnimation?: boolean;
+ /** Roving tabindex: only the strip's current tab stop gets `0`. */
+ tabIndex?: number;
+ onKeyDown?(event: KeyboardEvent<HTMLButtonElement>): void;
+ buttonRef?: Ref<HTMLButtonElement>;
};
export function ConversationTabNav({
@@ -27,16 +39,37 @@ export function ConversationTabNav({
icon: Icon,
onClick,
isActive,
+ isSelected,
label,
className,
measureOnly,
suppressLayoutAnimation = false,
+ tabIndex,
+ onKeyDown,
+ buttonRef,
}: ConversationTabNavProps) {
const reduceMotion = useReducedMotion();
const disableAnimation =
measureOnly || reduceMotion || import.meta.env.MODE === "test";
const enableLayoutAnimation = !disableAnimation && !suppressLayoutAnimation;
+ // Measurement clones live in an `aria-hidden` row, so they stay out of the
+ // tablist and out of the tab order. The real tabs carry an explicit name
+ // because an inactive tab hides its label and would otherwise be announced
+ // as an unlabelled button.
+ const tabProps = measureOnly
+ ? ({ "data-tab-measure": "true", tabIndex: -1 } as const)
+ : ({
+ "data-testid": `conversation-tab-${tabValue}`,
+ role: "tab",
+ "aria-selected": Boolean(isSelected),
+ "aria-controls": CONVERSATION_TAB_PANEL_ID,
+ "aria-label": label,
+ tabIndex,
+ onKeyDown,
+ ref: buttonRef,
+ } as const);
+
const buttonClassName = cn(
"flex items-center rounded-md cursor-pointer",
"pl-1.5 pr-2 py-1 lg:py-1.5",
@@ -77,10 +110,7 @@ export function ConversationTabNav({
<button
type="button"
onClick={onClick}
- {...(measureOnly
- ? {}
- : { "data-testid": `conversation-tab-${tabValue}` as const })}
- data-tab-measure={measureOnly ? "true" : undefined}
+ {...tabProps}
className={cn(buttonClassName, "gap-2")}
>
{iconElement}
@@ -94,10 +124,7 @@ export function ConversationTabNav({
layout={enableLayoutAnimation ? "position" : false}
type="button"
onClick={onClick}
- {...(measureOnly
- ? {}
- : { "data-testid": `conversation-tab-${tabValue}` as const })}
- data-tab-measure={measureOnly ? "true" : undefined}
+ {...tabProps}
className={buttonClassName}
transition={
enableLayoutAnimation ? { layout: tabLabelTransition } : undefined
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx b/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
index dbccf66690..b822f1b3f8 100644
--- a/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
+++ b/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
@@ -3,6 +3,7 @@ import ReactDOM from "react-dom";
import { useTranslation } from "react-i18next";
import { ContextMenu } from "#/ui/context-menu";
import { useClickOutsideElement } from "#/hooks/use-click-outside-element";
+import { clampLeftToViewport } from "#/hooks/use-popover-fixed-placement";
import { useConversationId } from "#/hooks/use-conversation-id";
import { useConversationLocalStorageState } from "#/utils/conversation-local-storage";
import {
@@ -26,6 +27,9 @@ import {
dropdownMenuRowIconWrapperClassName,
} from "#/utils/dropdown-classes";
+/** Space between the trigger and the portaled menu. */
+const MENU_GAP_PX = 8;
+
interface ConversationTabsContextMenuProps {
isOpen: boolean;
onClose: () => void;
@@ -56,23 +60,38 @@ export function ConversationTabsContextMenu({
const rect = anchorRef.current?.getBoundingClientRect();
if (!rect) return;
- const gap = 8;
+ // The menu's own box is only measurable once it has painted; the first
+ // pass falls back to anchoring on the trigger, and the frame below
+ // re-runs with real dimensions.
+ const menuRect = ref.current?.getBoundingClientRect();
+
+ const overflowsBelow =
+ rect.bottom + MENU_GAP_PX + (menuRect?.height ?? 0) >
+ window.innerHeight;
+
setPortalStyle({
position: "fixed",
zIndex: 9999,
- top: rect.bottom + gap,
- left: rect.left,
+ // Flip above the trigger rather than clipping at the viewport bottom.
+ ...(overflowsBelow
+ ? { bottom: window.innerHeight - rect.top + MENU_GAP_PX }
+ : { top: rect.bottom + MENU_GAP_PX }),
+ // An embedded canvas can sit hard against the viewport's right edge,
+ // where left-aligning on the trigger clips the labels and pin controls.
+ left: clampLeftToViewport(rect.left, menuRect?.width ?? 0),
});
};
updatePosition();
+ const frame = window.requestAnimationFrame(updatePosition);
window.addEventListener("resize", updatePosition);
window.addEventListener("scroll", updatePosition, true);
return () => {
+ window.cancelAnimationFrame(frame);
window.removeEventListener("resize", updatePosition);
window.removeEventListener("scroll", updatePosition, true);
};
- }, [isOpen, anchorRef]);
+ }, [isOpen, anchorRef, ref]);
const { t } = useTranslation("openhands");
const { conversationId } = useConversationId();
const {
diff --git a/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx b/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx
index dd148bec38..b0235efbf5 100644
--- a/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx
+++ b/src/components/features/conversation/conversation-tabs/conversation-tabs.tsx
@@ -1,4 +1,10 @@
-import { useEffect, useLayoutEffect, useRef, useState } from "react";
+import {
+ useEffect,
+ useLayoutEffect,
+ useRef,
+ useState,
+ type KeyboardEvent,
+} from "react";
import { useTranslation } from "react-i18next";
import { LayoutGroup } from "framer-motion";
import { Gauge, Globe, ListTodo, SquareChevronRight } from "lucide-react";
@@ -8,6 +14,7 @@ import DoubleCheckIcon from "#/icons/double-check.svg?react";
import { EllipsisButton } from "#/components/features/conversation-panel/ellipsis-button";
import { cn } from "#/utils/utils";
import { useConversationLocalStorageState } from "#/utils/conversation-local-storage";
+import { CONVERSATION_TAB_LABEL_KEYS } from "./conversation-tab-ids";
import { ConversationTabNav } from "./conversation-tab-nav";
import { DrawerVSCodeLink } from "./drawer-vscode-link";
import { ChatActionTooltip } from "../../chat/chat-action-tooltip";
@@ -89,36 +96,36 @@ export function ConversationTabs({
isActive: isTabActive("files"),
icon: DocumentIcon,
onClick: () => selectTab("files"),
- tooltipContent: t(I18nKey.COMMON$FILES),
- tooltipAriaLabel: t(I18nKey.COMMON$FILES),
- label: t(I18nKey.COMMON$FILES),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.files),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.files),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.files),
},
{
tabValue: "commits",
isActive: isTabActive("commits"),
icon: LuFileDiff,
onClick: () => selectTab("commits"),
- tooltipContent: t(I18nKey.DIFF_VIEWER$COMMITS),
- tooltipAriaLabel: t(I18nKey.DIFF_VIEWER$COMMITS),
- label: t(I18nKey.DIFF_VIEWER$COMMITS),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.commits),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.commits),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.commits),
},
{
tabValue: "planner",
isActive: isTabActive("planner"),
icon: ListTodo,
onClick: () => selectTab("planner"),
- tooltipContent: t(I18nKey.COMMON$PLANNER),
- tooltipAriaLabel: t(I18nKey.COMMON$PLANNER),
- label: t(I18nKey.COMMON$PLANNER),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.planner),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.planner),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.planner),
},
{
tabValue: "terminal",
isActive: isTabActive("terminal"),
icon: SquareChevronRight,
onClick: () => selectTab("terminal"),
- tooltipContent: t(I18nKey.COMMON$TERMINAL),
- tooltipAriaLabel: t(I18nKey.COMMON$TERMINAL),
- label: t(I18nKey.COMMON$TERMINAL),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.terminal),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.terminal),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.terminal),
className: "pl-2",
},
{
@@ -126,18 +133,18 @@ export function ConversationTabs({
isActive: isTabActive("browser"),
icon: Globe,
onClick: () => selectTab("browser"),
- tooltipContent: t(I18nKey.COMMON$BROWSER),
- tooltipAriaLabel: t(I18nKey.COMMON$BROWSER),
- label: t(I18nKey.COMMON$BROWSER),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.browser),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.browser),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.browser),
},
{
tabValue: "usage",
isActive: isTabActive("usage"),
icon: Gauge,
onClick: () => selectTab("usage"),
- tooltipContent: t(I18nKey.COMMON$USAGE),
- tooltipAriaLabel: t(I18nKey.COMMON$USAGE),
- label: t(I18nKey.COMMON$USAGE),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.usage),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.usage),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.usage),
},
];
@@ -148,9 +155,9 @@ export function ConversationTabs({
isActive: isTabActive("tasklist"),
icon: DoubleCheckIcon,
onClick: () => selectTab("tasklist"),
- tooltipContent: t(I18nKey.COMMON$TASK_LIST),
- tooltipAriaLabel: t(I18nKey.COMMON$TASK_LIST),
- label: t(I18nKey.COMMON$TASK_LIST),
+ tooltipContent: t(CONVERSATION_TAB_LABEL_KEYS.tasklist),
+ tooltipAriaLabel: t(CONVERSATION_TAB_LABEL_KEYS.tasklist),
+ label: t(CONVERSATION_TAB_LABEL_KEYS.tasklist),
});
}
@@ -251,6 +258,52 @@ export function ConversationTabs({
]);
const safeInlineTabCount = Math.min(inlineTabCount, visibleTabs.length);
+ const inlineTabs = visibleTabs.slice(0, safeInlineTabCount);
+
+ // Roving tabindex: the strip is a single tab stop. It sits on the selected
+ // tab — drawer open or not, since the strip stays in the accessibility tree
+ // while the drawer is collapsed — until the user arrows elsewhere.
+ const selectedTabIndex = inlineTabs.findIndex(
+ (tab) => tab.tabValue === selectedTab,
+ );
+ const [rovingTabIndex, setRovingTabIndex] = useState(0);
+ const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);
+
+ useEffect(() => {
+ if (selectedTabIndex >= 0) setRovingTabIndex(selectedTabIndex);
+ }, [selectedTabIndex]);
+
+ const tabStopIndex = Math.min(
+ rovingTabIndex,
+ Math.max(inlineTabs.length - 1, 0),
+ );
+
+ // Arrow keys move focus only; Enter/Space still activate, which keeps the
+ // drawer from thrashing through tabs as the user scans the strip.
+ const handleTabKeyDown = (
+ event: KeyboardEvent<HTMLButtonElement>,
+ index: number,
+ ) => {
+ const lastIndex = inlineTabs.length - 1;
+ if (lastIndex < 0) return;
+
+ let nextIndex: number;
+ if (event.key === "ArrowRight") {
+ nextIndex = index === lastIndex ? 0 : index + 1;
+ } else if (event.key === "ArrowLeft") {
+ nextIndex = index === 0 ? lastIndex : index - 1;
+ } else if (event.key === "Home") {
+ nextIndex = 0;
+ } else if (event.key === "End") {
+ nextIndex = lastIndex;
+ } else {
+ return;
+ }
+
+ event.preventDefault();
+ setRovingTabIndex(nextIndex);
+ tabRefs.current[nextIndex]?.focus();
+ };
return (
<>
@@ -305,47 +358,57 @@ export function ConversationTabs({
<div className="flex min-w-0 flex-1 items-center justify-start overflow-hidden">
<div className="flex w-fit max-w-full min-w-0 items-center gap-1.5">
<LayoutGroup id="conversation-drawer-tabs">
- <div className="flex w-fit max-w-full min-w-0 flex-nowrap items-center gap-1.5 overflow-x-hidden">
- {visibleTabs
- .slice(0, safeInlineTabCount)
- .map(
- (
- {
- tabValue,
- icon,
- onClick,
- isActive,
- tooltipContent,
- tooltipAriaLabel,
- label,
- className: tabClassName,
- },
- index,
- ) => (
- <ChatActionTooltip
- key={`${tabValue}-${index}`}
- tooltip={tooltipContent}
- ariaLabel={tooltipAriaLabel}
- >
- <ConversationTabNav
- tabValue={tabValue}
- icon={icon}
- onClick={onClick}
- isActive={isActive}
- label={label}
- className={cn(tabClassName, "shrink-0")}
- suppressLayoutAnimation={isPanelResizing}
- />
- </ChatActionTooltip>
- ),
- )}
+ <div
+ // A narrow drawer can push every tab into the overflow menu,
+ // and a tablist owning no tabs is not a tablist.
+ role={inlineTabs.length > 0 ? "tablist" : undefined}
+ aria-label={t(I18nKey.CONVERSATION$TABS_LABEL)}
+ className="flex w-fit max-w-full min-w-0 flex-nowrap items-center gap-1.5 overflow-x-hidden"
+ >
+ {inlineTabs.map(
+ (
+ {
+ tabValue,
+ icon,
+ onClick,
+ isActive,
+ tooltipContent,
+ tooltipAriaLabel,
+ label,
+ className: tabClassName,
+ },
+ index,
+ ) => (
+ <ChatActionTooltip
+ key={`${tabValue}-${index}`}
+ tooltip={tooltipContent}
+ ariaLabel={tooltipAriaLabel}
+ >
+ <ConversationTabNav
+ tabValue={tabValue}
+ icon={icon}
+ onClick={onClick}
+ isActive={isActive}
+ isSelected={selectedTab === tabValue}
+ label={label}
+ className={cn(tabClassName, "shrink-0")}
+ suppressLayoutAnimation={isPanelResizing}
+ tabIndex={index === tabStopIndex ? 0 : -1}
+ onKeyDown={(event) => handleTabKeyDown(event, index)}
+ buttonRef={(node) => {
+ tabRefs.current[index] = node;
+ }}
+ />
+ </ChatActionTooltip>
+ ),
+ )}
</div>
</LayoutGroup>
<div ref={menuRef} className="relative shrink-0">
<EllipsisButton
ref={anchorRef}
onClick={() => setIsMenuOpen(!isMenuOpen)}
- ariaLabel={t(I18nKey.COMMON$MORE_OPTIONS)}
+ ariaLabel={t(I18nKey.CONVERSATION$CUSTOMIZE_TABS)}
iconClassName={
variant === "compact"
? mobileTopBarIconClassName
diff --git a/src/hooks/use-popover-fixed-placement.ts b/src/hooks/use-popover-fixed-placement.ts
index ef73ce3f2d..4ebb59ea91 100644
--- a/src/hooks/use-popover-fixed-placement.ts
+++ b/src/hooks/use-popover-fixed-placement.ts
@@ -6,6 +6,15 @@ export interface FixedPlacementBox {
width: number;
}
+/** Clamp a fixed popover's `left` so its `width` stays `gutter` px inside the viewport. */
+export function clampLeftToViewport(
+ left: number,
+ width: number,
+ gutter = 8,
+): number {
+ return Math.max(gutter, Math.min(left, window.innerWidth - gutter - width));
+}
+
/**
* Position a popover with `position: fixed`, anchored below the trigger and
* clamped within the viewport. Used by the conversation-panel "+ New
@@ -30,11 +39,7 @@ export function usePopoverFixedPlacement(
const r = el.getBoundingClientRect();
const gutter = 8;
const width = Math.min(targetWidth, window.innerWidth - gutter * 2);
- let left = r.right - width;
- if (left < gutter) left = gutter;
- if (left + width > window.innerWidth - gutter) {
- left = Math.max(gutter, window.innerWidth - gutter - width);
- }
+ const left = clampLeftToViewport(r.right - width, width, gutter);
setBox({ top: r.bottom + 4, left, width });
}, [triggerRef, targetWidth]);
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 0517f26070..2f2e722c30 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -38062,6 +38062,40 @@
"uk": "(без назви)",
"ca": "(sense títol)"
},
+ "CONVERSATION$TABS_LABEL": {
+ "en": "Conversation panels",
+ "zh-CN": "会话面板",
+ "zh-TW": "對話面板",
+ "de": "Konversationsbereiche",
+ "ko-KR": "대화 패널",
+ "no": "Samtalepaneler",
+ "it": "Pannelli della conversazione",
+ "pt": "Painéis da conversa",
+ "es": "Paneles de la conversación",
+ "ar": "لوحات المحادثة",
+ "fr": "Panneaux de la conversation",
+ "tr": "Konuşma panelleri",
+ "ja": "会話パネル",
+ "uk": "Панелі розмови",
+ "ca": "Panells de la conversa"
+ },
+ "CONVERSATION$CUSTOMIZE_TABS": {
+ "en": "Customize tabs",
+ "zh-CN": "自定义标签页",
+ "zh-TW": "自訂分頁",
+ "de": "Tabs anpassen",
+ "ko-KR": "탭 사용자 지정",
+ "no": "Tilpass faner",
+ "it": "Personalizza le schede",
+ "pt": "Personalizar abas",
+ "es": "Personalizar pestañas",
+ "ar": "تخصيص علامات التبويب",
+ "fr": "Personnaliser les onglets",
+ "tr": "Sekmeleri özelleştir",
+ "ja": "タブをカスタマイズ",
+ "uk": "Налаштувати вкладки",
+ "ca": "Personalitza les pestanyes"
+ },
"CONVERSATION$UNPIN_TAB": {
"en": "Unpin tab from bar",
"zh-CN": "从栏中取消固定标签页",