Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Thread pill: a quiet pill that opens the bot's threads as a list (#8267)
Milind Soni139ddb9784ff
diff --git a/DESIGN.md b/DESIGN.mdindex efd1e6202f..d437ba709f 100644--- a/DESIGN.md+++ b/DESIGN.md@@ -48,7 +48,8 @@ where they belong instead of adding new places.header in both modes, because starting a thread is an everyday action peoplelook for at the top. With Thread tabs on, the bot's threads take the pill'splace in the header as tabs, with the plus at their end. With it off, Simple- mode's pill opens a bot's threads once it has two, and the plus sits at their end.+ mode's pill opens a bot's threads in a menu under it once it has two, with+ New thread as the menu's last row.- **No count badges and no "needs you" summaries** above the sidebar list orin the header. A status mark on the row it belongs to is fine.- **Settings for one bot live in its bot panel.** App-wide settings live indiff --git a/src/components/ChatView.controls.test.ts b/src/components/ChatView.controls.test.tsindex 4ceaafd152..2c7a2f5870 100644--- a/src/components/ChatView.controls.test.ts+++ b/src/components/ChatView.controls.test.ts@@ -151,15 +151,16 @@ describe("the Simple header", () => {const simple = renderToStaticMarkup(createElement(ChatView, { bot: busyElsewhere }));const identity = simple.slice(simple.indexOf("data-chathead-identity"), simple.indexOf("data-chathead-controls"));const pill = identity.match(/<button[^>]*data-chathead-pill="true"[^>]*>([\s\S]*?)<\/button>/)!;- const threads = identity.match(/<button[^>]*data-chathead-threads="true"[^>]*>([\s\S]*?)<\/button>/)!;+ const threads = identity.slice(identity.indexOf("data-chathead-threads"));const shell = identity.match(/<div[^>]*data-chathead-switch="closed"[^>]*>/)!;expect(pill[1]).toContain(">Pepper</span>");expect(pill[1]).toContain('data-chathead-elsewhere="true"');expect(shell[0].match(/class="([^"]*)"/)![1]!.split(" ")).toEqual(expect.arrayContaining(["rounded-full", "bg-composer", "ring-[0.5px]", "shadow-(--shadow-float)", "p-[5.5px]"]));- // A bot with two threads names the one on screen beside it, which opens the others.- expect(threads[0]).toContain('aria-expanded="false"');- expect(threads[1]).toContain("data-chathead-conversation");- expect(identity.replace(pill[0], "").replace(threads[0], "").replace(/<span role="status"[^>]*>[^<]*<\/span>/, "")).not.toMatch(/<(button|a|span)[\s>]/);+ // A bot with two threads names the one on screen beside it, which opens the others in a menu.+ expect(threads).toContain("data-chathead-conversation");+ const switcher = fixture.menus.find((menu) => menu.ariaLabel === "Pepper threads")!;+ expect(switcher.items.map((item) => item.key)).toEqual(busyElsewhere.tasks!.map((task) => `thread:${task.threadId}`).concat("new-thread"));+ expect(identity.replace(pill[0], "")).not.toMatch(/<(button|a)[\s>]/);for (const gone of ["data-chathead-role", "data-background-activity", "data-chathead-back", 'data-testid="chat-more"']) {expect(simple, gone).not.toContain(gone);}diff --git a/src/components/ThreadSwitcherPill.dom.test.ts b/src/components/ThreadSwitcherPill.dom.test.tsindex 1ad16066b8..88993d80ff 100644--- a/src/components/ThreadSwitcherPill.dom.test.ts+++ b/src/components/ThreadSwitcherPill.dom.test.ts@@ -25,14 +25,17 @@ function Header({ bot }: { bot: Bot }) {useThreadCycleKeys();return createElement(ChatHeadPill, { bot, avatar: {} as never, privacy: null, onToggle, switcher: true });}-const render = (bot: Bot) => {- store.state = { settingsOpen: false, pendingQueued: {}, bots: [bot], selectedId: bot.id, activeView: "chat", shortcutsOpen: false, newChat: null };+const render = (bot: Bot, settingsOpen = false) => {+ store.state = { settingsOpen, pendingQueued: {}, bots: [bot], selectedId: bot.id, activeView: "chat", shortcutsOpen: false, newChat: null };if (!root) root = createRoot(document.body.appendChild(document.createElement("div")));act(() => root!.render(createElement(Header, { bot })));};const q = <T extends Element = HTMLElement>(selector: string) => document.querySelector<T & HTMLElement>(selector);-const chips = () => [...document.querySelectorAll<HTMLElement>("[role=option]")];+const trigger = () => q("[data-chathead-threads]")!.closest("button")!;+const rows = () => [...document.querySelectorAll<HTMLElement>("[role=menuitemradio]")];const sent = () => dispatch.mock.calls.map(([action]) => action as Action);+const nextFrame = () => act(() => new Promise<void>((done) => requestAnimationFrame(() => done())));+const press = (key: string) => act(() => { document.activeElement!.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true })); });beforeEach(() => { dispatch.mockClear(); onToggle.mockClear(); });afterEach(() => { act(() => root?.unmount()); root = null; document.body.innerHTML = ""; });@@ -43,60 +46,120 @@ describe("the pill's thread switcher", () => {expect(q("[data-chathead-conversation]")?.textContent).toBe("Launch plan");act(() => q("[data-chathead-pill]")!.click());expect(onToggle).toHaveBeenCalledOnce();- expect(q("[role=listbox]")).toBeNull();+ expect(q("[role=menu]")).toBeNull();});- it("opens on a click, never on hover, into the threads: pinned first, the open one selected", () => {+ it("opens on a click, never on hover, into a menu under the pill: pinned first, the open one checked", () => {render(pepper(THREADS, "launch"));- act(() => { q("[data-chathead-threads]")!.dispatchEvent(new MouseEvent("mouseover", { bubbles: true })); });- expect(q("[role=listbox]")).toBeNull();- act(() => q("[data-chathead-threads]")!.click());- expect(chips().map((chip) => chip.textContent)).toEqual(["Launch plan", "Weekly sales", "Berlin trip"]);- expect(chips()[0].getAttribute("aria-selected")).toBe("true");- expect(chips()[1].querySelector('[aria-label="Working"]')).not.toBeNull();- expect(chips()[0].querySelector('[aria-label="Pinned"]')).not.toBeNull();+ act(() => { trigger().dispatchEvent(new MouseEvent("mouseover", { bubbles: true })); });+ expect(q("[role=menu]")).toBeNull();+ act(() => trigger().click());+ expect(trigger().getAttribute("aria-expanded")).toBe("true");+ expect(q("[role=menu]")!.getAttribute("aria-label")).toBe("Pepper threads");+ expect(rows().map((row) => row.title)).toEqual(["Launch plan", "Weekly sales", "Berlin trip"]);+ expect(rows().map((row) => row.getAttribute("aria-checked"))).toEqual(["true", "false", "false"]);+ expect(rows()[1]!.querySelector('[aria-label="Working"]')).not.toBeNull();+ expect(rows()[0]!.querySelector('[aria-label="Pinned"]')).not.toBeNull();+ expect(rows()[2]!.textContent).toMatch(/ago|yesterday|\//);});- it("switches to a picked thread and folds back", () => {+ it("switches to a picked thread and closes; the open one only closes", () => {render(pepper(THREADS, "launch"));- act(() => q("[data-chathead-threads]")!.click());- act(() => chips()[2].click());+ act(() => trigger().click());+ act(() => rows()[2]!.click());expect(sent()).toEqual([{ type: "switchTask", botId: "pepper", threadId: "trip" }]);- expect(q("[role=listbox]")).toBeNull();+ expect(trigger().getAttribute("aria-expanded")).toBe("false");+ act(() => trigger().click());+ act(() => rows()[0]!.click());+ expect(sent()).toHaveLength(1);+ expect(trigger().getAttribute("aria-expanded")).toBe("false");});- it("moves between threads with the arrow keys, and folds back on Escape", () => {- render(pepper(THREADS, "launch"));- act(() => q("[data-chathead-threads]")!.click());- act(() => chips()[0].focus());- act(() => { chips()[0].dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true })); });- expect(document.activeElement).toBe(chips()[1]);- act(() => { chips()[1].dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); });- expect(q("[role=listbox]")).toBeNull();+ it("opens from the keyboard on the open thread, moves with the arrows, and Escape hands focus back to the pill", async () => {+ render(pepper(THREADS, "trip"));+ act(() => trigger().focus());+ act(() => trigger().click());+ await nextFrame();+ expect(document.activeElement).toBe(rows()[2]);+ press("ArrowUp");+ expect(document.activeElement).toBe(rows()[1]);+ press("Home");+ expect(document.activeElement).toBe(rows()[0]);+ press("Escape");+ expect(q("[role=menu]")?.hasAttribute("inert") ?? true).toBe(true);+ expect(document.activeElement).toBe(trigger());expect(sent()).toEqual([]);});- it("starts a new thread from its plus", () => {+ it("steps from the pill into a menu the mouse opened, at the open thread", () => {+ render(pepper(THREADS, "sales"));+ act(() => trigger().focus());+ act(() => { trigger().dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 })); });+ expect(document.activeElement).toBe(trigger());+ press("ArrowDown");+ expect(document.activeElement).toBe(rows()[1]);+ });++ it("finds the open thread while the bot panel is open beside it", async () => {+ const panel = document.body.appendChild(document.createElement("div"));+ panel.id = "bot-panel";+ panel.innerHTML = '<button type="button" role="switch" aria-checked="true">Setting</button>';+ render(pepper(THREADS, "sales"), true);+ expect(q("[data-chathead-pill]")!.getAttribute("aria-controls")).toBeTruthy();+ act(() => trigger().focus());+ act(() => trigger().click());+ await nextFrame();+ expect(document.activeElement).toBe(rows()[1]);+ press("Escape");+ act(() => { trigger().dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 })); });+ press("ArrowDown");+ expect(document.activeElement).toBe(rows()[1]);+ });++ it("starts a new thread from the menu's last row, which a view-only person does not get", () => {render(pepper(THREADS, "launch"));- act(() => q("[data-chathead-threads]")!.click());- act(() => q("[data-thread-chip-new]")!.click());+ act(() => trigger().click());+ const start = q('[data-menu-key="new-thread"]')!;+ expect(start.textContent).toContain("New thread");+ act(() => start.click());expect(sent()).toEqual([{ type: "newTask", botId: "pepper" }]);+ act(() => root?.unmount()); root = null; document.body.innerHTML = "";+ render({ ...pepper(THREADS, "launch"), yourAccess: "view" } as Bot);+ act(() => trigger().click());+ expect(q('[data-menu-key="new-thread"]')).toBeNull();+ expect(rows()).toHaveLength(3);+ });++ it("hides the focus ring after a pointer opens it, and shows it again once a key moves focus", () => {+ render(pepper(THREADS, "launch"));+ const pill = () => q("[data-chathead-switch]")!;+ act(() => { trigger().dispatchEvent(new PointerEvent("pointerdown", { bubbles: true })); });+ act(() => trigger().click());+ expect(pill().hasAttribute("data-pointer-used")).toBe(true);+ act(() => rows()[1]!.focus());+ press("a");+ press("Shift");+ expect(pill().hasAttribute("data-pointer-used")).toBe(true);+ press("ArrowDown");+ expect(pill().hasAttribute("data-pointer-used")).toBe(false);+ expect(document.activeElement).toBe(rows()[2]);});it("shows for a bot whose second open thread another bot opened, beside its main thread", () => {const lead = { botId: "lead", name: "Lead", at: 1 };render(pepper([task("sales", "Weekly sales", 5), task("brief", "Launch brief", 3, { openedBy: lead })], "sales"));- act(() => q("[data-chathead-threads]")!.click());- expect(chips().map((chip) => chip.textContent)).toEqual(["Weekly sales", "Launch brief"]);+ act(() => trigger().click());+ expect(rows().map((row) => row.title)).toEqual(["Weekly sales", "Launch brief"]);});- it("Ctrl+Tab walks the threads in the order the pill lists them, wrapping", () => {+ it("Ctrl+Tab walks the threads in the order the menu lists them, wrapping", () => {const helper = task("brief", "Launch brief", 4, { openedBy: { botId: "lead", name: "Lead", at: 1 } });const threads = [...THREADS, helper];render(pepper(threads, "launch"));- act(() => q("[data-chathead-threads]")!.click());- const order = chips().map((chip) => chip.dataset.threadChip!);+ act(() => trigger().click());+ const order = rows().map((row) => row.dataset.menuKey!.replace("thread:", ""));expect(order).toEqual(["launch", "sales", "brief", "trip"]);+ press("Escape");const visited: string[] = [];let open = order[0]!;for (let step = 0; step < order.length; step += 1) {diff --git a/src/components/ThreadSwitcherPill.tsx b/src/components/ThreadSwitcherPill.tsxindex de2b0dcc58..5b4638118d 100644--- a/src/components/ThreadSwitcherPill.tsx+++ b/src/components/ThreadSwitcherPill.tsx@@ -1,172 +1,129 @@-import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";-import { ChevronDown, Pin, Plus } from "lucide-react";+import { useEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";+import { Check, ChevronDown, Pin, SquarePen } from "lucide-react";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";+import { useSharedClock } from "@/lib/shared-clock";import { localizedTaskTitle } from "@/lib/task-title";import type { Bot } from "@/state/store";import { useStoreDispatch } from "@/state/store-select";import { BOT_PANEL_ID } from "./bot-panel/side-panel";-import { ELEVATED_FLOAT } from "./elevated";-import { edgeFade } from "./HeaderThreadTabs";-import { reducedMotion } from "./MenuMotion";+import { ELEVATED_FLOAT, ELEVATED_OPEN, ELEVATED_TINT } from "./elevated";+import { ShortcutHint } from "./ShortcutHint";+import { threadRecency, threadUpdatedLabel } from "./SidebarThreadRow";+import { SidebarPopoverMenu, type SidebarMenuItem } from "./SidebarPopoverMenu";import { openTabId, type ThreadTab } from "./thread-tabs";-const RESIZE_MS = 240;-const LIST_FADE = 40;-const CLEAR_OF_CONTROLS = 24;-const WIDEST = 720;-const EASE = "cubic-bezier(0.22, 1, 0.36, 1)";-const PART = "flex h-full min-w-0 items-center rounded-full outline-none transition-colors duration-[120ms] hover:bg-ink/[0.06] active:bg-ink/[0.08] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";-const CHIP = "flex h-7 max-w-42 shrink-0 items-center gap-1.5 rounded-full px-3 text-[13px] leading-[18px] outline-none transition-colors duration-[120ms] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";+const PART = "flex h-full min-w-0 items-center rounded-full outline-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus";+const NAVIGATION_KEYS = new Set(["Tab", "Enter", " ", "Escape", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"]);-/** The widest the open pill may be while staying centred in the header and clear of the controls on either side. */-function centredRoom(pill: HTMLElement): number {- const row = pill.closest("[data-chathead-row]");- const centre = row ? row.getBoundingClientRect().left + row.getBoundingClientRect().width / 2 : 0;- let half = row ? row.getBoundingClientRect().width / 2 : WIDEST / 2;- for (const side of row?.querySelectorAll<HTMLElement>("[data-chathead-controls]") ?? []) {- const box = side.getBoundingClientRect();- if (box.width === 0) continue;- half = Math.min(half, box.left >= centre ? box.left - centre : centre - box.right);- }- return Math.max(0, Math.min(WIDEST, 2 * (half - CLEAR_OF_CONTROLS)));+export const tabTitle = (tab: ThreadTab): string => (tab.draft ? t("task.newShort") : !tab.title || tab.title === "New thread" ? t("task.untitledChat") : localizedTaskTitle(tab.title));++/**+ * Whether the pill was last used with a pointer, which hides its focus ring until a key moves or presses something.+ * Chrome (158) matches :focus-visible on a scripted focus that follows an element showing its ring, and on any key,+ * Shift or a letter included, pressed while an element has focus: without this, the pill focused again after a pick+ * would show the ring to someone who only clicked.+ */+function usePointerUse() {+ const [pointer, setPointer] = useState(false);+ useEffect(() => {+ if (!pointer) return;+ const key = (event: KeyboardEvent) => { if (NAVIGATION_KEYS.has(event.key)) setPointer(false); };+ document.addEventListener("keydown", key, true);+ return () => document.removeEventListener("keydown", key, true);+ }, [pointer]);+ return { pointer, onPointerDown: () => setPointer(true) };}-export const tabTitle = (tab: ThreadTab): string => (tab.draft ? t("task.newShort") : !tab.title || tab.title === "New thread" ? t("task.untitledChat") : localizedTaskTitle(tab.title));+function ThreadMark({ tab }: { tab: ThreadTab }) {+ if (tab.working) return <span role="img" aria-label={t("chat.activity.working")} className="size-1.5 shrink-0 animate-pulse rounded-full bg-success motion-reduce:animate-none" />;+ if (tab.pinned) return <span className="flex"><Pin size={12} role="img" aria-label={t("task.pinned")} className="text-ink-tertiary" /></span>;+ return null;+}++/** The open thread's row in the pill's open menu. */+function openThreadRow(pill: HTMLElement | null) {+ const id = pill?.querySelector('[aria-haspopup="menu"]')?.getAttribute("aria-controls");+ const menu = id ? document.getElementById(id) : null;+ const row = menu?.querySelector<HTMLElement>('[aria-checked="true"]');+ return menu && row ? { menu, row } : null;+}-/** The pill's width glides from what it was to what its new content needs, then lets go. */-function useGlidingWidth(key: unknown) {- const box = useRef<HTMLDivElement>(null);- const last = useRef<number | null>(null);- useLayoutEffect(() => {- const element = box.current;- if (!element) return;- element.style.transition = "";- element.style.width = "";- const to = element.getBoundingClientRect().width;- const from = last.current;- last.current = to;- if (from === null || Math.abs(from - to) < 1 || reducedMotion()) return;- element.style.width = `${from}px`;- void element.offsetWidth;- element.style.transition = `width ${RESIZE_MS}ms ${EASE}`;- element.style.width = `${to}px`;- const done = window.setTimeout(() => { element.style.transition = ""; element.style.width = ""; }, RESIZE_MS);- return () => { window.clearTimeout(done); element.style.transition = ""; element.style.width = ""; };- }, [key]);- return box;+/** Kept in view on opening; a keyboard opening lands on it rather than the menu's first row. */+function landOnOpenThread(pill: HTMLElement | null) {+ const open = openThreadRow(pill);+ if (!open) return;+ open.row.scrollIntoView?.({ block: "nearest" });+ if (open.menu.contains(document.activeElement)) open.row.focus({ preventScroll: true });}/*** Simple mode's pill for a bot with two threads or more: its face and name open the bot panel as ever, and the open- * thread's name beside them widens the pill in place into the bot's threads, to pick one or start one. A pick, Escape- * or a click elsewhere folds it back.+ * thread's name beside them opens the bot's threads in a menu under the pill, to pick one or start one.*/export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle }: {bot: Bot; tabs: ThreadTab[]; head: ReactNode; label: string; panelOpen: boolean; onToggle: () => void;}) {const dispatch = useStoreDispatch();const [open, setOpen] = useState(false);- const [room, setRoom] = useState(WIDEST);- const box = useGlidingWidth(open);- const list = useRef<HTMLDivElement>(null);- const toggle = useRef<HTMLButtonElement>(null);- const [fade, setFade] = useState<string | undefined>();+ const pill = useRef<HTMLDivElement>(null);+ const now = useSharedClock(30_000, open);const active = openTabId(bot);const current = tabs.find((tab) => tab.threadId === active);const canWrite = bot.yourAccess !== "view";+ const { pointer, onPointerDown } = usePointerUse();- const close = (refocus: boolean) => {- setOpen(false);- if (refocus) requestAnimationFrame(() => toggle.current?.focus());- };- useEffect(() => {- if (!open) return;- const away = (event: PointerEvent) => { if (!box.current?.contains(event.target as Node)) setOpen(false); };- const resize = () => { if (box.current) setRoom(centredRoom(box.current)); };- document.addEventListener("pointerdown", away);- window.addEventListener("resize", resize);- return () => { document.removeEventListener("pointerdown", away); window.removeEventListener("resize", resize); };- }, [open]);- useLayoutEffect(() => {- if (!open || !list.current) return;- const row = list.current;- row.scrollLeft = 0;- const chip = row.querySelector<HTMLElement>('[aria-selected="true"]') ?? row.querySelector<HTMLElement>("[role=option]");- chip?.focus({ preventScroll: true });- const settle = window.setTimeout(() => {- chip?.scrollIntoView?.({ block: "nearest", inline: "nearest" });- setFade(edgeFade(row, LIST_FADE));- }, reducedMotion() ? 0 : RESIZE_MS);- return () => window.clearTimeout(settle);- }, [open]);+ const items: SidebarMenuItem[] = tabs.map((tab) => {+ const selected = tab.threadId === active;+ const task = tab.draft ? undefined : bot.tasks?.find((each) => each.threadId === tab.threadId);+ const at = task ? threadRecency(task) : 0;+ return {+ key: `thread:${tab.threadId}`,+ label: tabTitle(tab),+ title: tabTitle(tab),+ checked: selected,+ icon: selected ? <Check size={16} aria-hidden="true" /> : <ThreadMark tab={tab} />,+ value: at ? threadUpdatedLabel(at, now) : undefined,+ trailing: selected && (tab.working || tab.pinned) ? <ThreadMark tab={tab} /> : undefined,+ onSelect: () => { if (!selected) dispatch({ type: "switchTask", botId: bot.id, threadId: tab.threadId }); },+ };+ });+ if (canWrite) {+ items.push({ key: "new-thread", separatorBefore: true, label: t("task.newShort"), icon: <SquarePen size={16} />,+ trailing: <ShortcutHint id="new-thread" />, onSelect: () => dispatch({ type: "newTask", botId: bot.id }) });+ }- const pick = (tab: ThreadTab) => {- if (tab.threadId !== active) dispatch({ type: "switchTask", botId: bot.id, threadId: tab.threadId });- close(true);+ const onOpenChange = (next: boolean) => {+ setOpen(next);+ if (next) requestAnimationFrame(() => landOnOpenThread(pill.current));};- const onKey = (event: ReactKeyboardEvent<HTMLDivElement>) => {- if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); close(true); return; }- const chips = Array.from(list.current?.querySelectorAll<HTMLElement>("[role=option]") ?? []);- const at = chips.indexOf(document.activeElement as HTMLElement);- if (at < 0) return;- const rtl = getComputedStyle(event.currentTarget).direction === "rtl";- const step = event.key === "ArrowRight" ? (rtl ? -1 : 1) : event.key === "ArrowLeft" ? (rtl ? 1 : -1) : 0;- const to = step ? Math.min(Math.max(at + step, 0), chips.length - 1) : event.key === "Home" ? 0 : event.key === "End" ? chips.length - 1 : null;- if (to === null) return;+ // A menu opened with the mouse leaves focus on the pill: an arrow then steps into it, at the open thread.+ const intoMenu = (event: ReactKeyboardEvent) => {+ if (!open || (event.key !== "ArrowDown" && event.key !== "ArrowUp") || (event.target as HTMLElement).getAttribute("aria-haspopup") !== "menu") return;+ const row = openThreadRow(pill.current)?.row;+ if (!row) return;event.preventDefault();- chips[to]?.focus();+ row.focus();};return (- <div ref={box} data-chathead-switch={open ? "open" : "closed"} onKeyDown={open ? onKey : undefined}- className={cn("flex h-[39px] min-w-0 items-center overflow-hidden rounded-full p-[5.5px] text-ink", ELEVATED_FLOAT, !open && "max-w-full")} style={open ? { maxWidth: room } : undefined}>- {open ? (- <div key="open" className="flex min-w-0 animate-fade-in items-center gap-1 motion-reduce:animate-none">- <button type="button" data-chathead-pill data-tour="bot-pill" onClick={onToggle} title={t("chat.openBotPanel")} aria-label={label}- aria-expanded={panelOpen} aria-controls={panelOpen ? BOT_PANEL_ID : undefined} className={cn(PART, "shrink-0")}>- {head}- </button>- <div ref={list} role="listbox" aria-label={t("task.namedList", { name: bot.name })} aria-orientation="horizontal"- onScroll={(event) => setFade(edgeFade(event.currentTarget, LIST_FADE))} style={{ maskImage: fade, WebkitMaskImage: fade }}- className="flex min-w-0 items-center gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">- {tabs.map((tab) => {- const selected = tab.threadId === active;- const title = tabTitle(tab);- return (- <button key={tab.threadId} type="button" role="option" aria-selected={selected} tabIndex={selected ? 0 : -1} title={title}- data-thread-chip={tab.threadId} onClick={() => pick(tab)}- className={cn(CHIP, selected ? "bg-ink/[0.1] text-ink" : "text-ink-secondary hover:bg-ink/[0.06] hover:text-ink")}>- {tab.working ? <span role="img" aria-label={t("chat.activity.working")} className="size-1.5 shrink-0 animate-pulse rounded-full bg-success motion-reduce:animate-none" />- : tab.pinned ? <Pin size={12} role="img" aria-label={t("task.pinned")} className="shrink-0 text-ink-tertiary" /> : null}- <span dir="auto" className="min-w-0 truncate">{title}</span>- </button>- );- })}- </div>- {canWrite && (- <button type="button" data-thread-chip-new aria-label={t("task.newShort")} title={t("task.newShort")}- onClick={() => { dispatch({ type: "newTask", botId: bot.id }); close(false); }}- className={cn(PART, "size-7 shrink-0 justify-center text-ink-secondary hover:text-ink")}>- <Plus size={16} aria-hidden="true" />- </button>- )}- </div>- ) : (- <div key="closed" className="flex min-w-0 items-center">- <button type="button" data-chathead-pill data-tour="bot-pill" onClick={onToggle} title={t("chat.openBotPanel")} aria-label={label}- aria-expanded={panelOpen} aria-controls={panelOpen ? BOT_PANEL_ID : undefined} className={cn(PART, "shrink-0")}>- {head}- </button>- <button ref={toggle} type="button" data-chathead-threads aria-haspopup="listbox" aria-expanded={false}- aria-label={t("task.namedList", { name: bot.name })} onClick={() => { if (box.current) setRoom(centredRoom(box.current)); setOpen(true); }}- className={cn(PART, "gap-1.5 pe-2.5 ps-1.5 text-[14px] font-medium leading-5 text-ink-secondary hover:text-ink")}>- <span aria-hidden="true" className="text-ink-tertiary">·</span>- <span data-chathead-conversation dir="auto" className="min-w-0 max-w-[180px] truncate">{current ? tabTitle(current) : ""}</span>- <ChevronDown size={12} aria-hidden="true" className="shrink-0 text-ink-tertiary" />- </button>- </div>- )}+ <div ref={pill} data-chathead-switch={open ? "open" : "closed"} data-pointer-used={pointer ? "" : undefined} onPointerDown={onPointerDown} onKeyDown={intoMenu}+ className={cn("group/pill flex h-[39px] min-w-0 max-w-full items-center rounded-full p-[5.5px] text-ink", ELEVATED_FLOAT, open ? ELEVATED_OPEN : ELEVATED_TINT)}>+ <button type="button" data-chathead-pill data-tour="bot-pill" onClick={onToggle} title={t("chat.openBotPanel")} aria-label={label}+ aria-expanded={panelOpen} aria-controls={panelOpen ? BOT_PANEL_ID : undefined} className={cn(PART, "shrink")}>+ {head}+ </button>+ <SidebarPopoverMenu items={items} ariaLabel={t("task.namedList", { name: bot.name })} onOpenChange={onOpenChange}+ triggerClassName={cn(PART, "group/threads pe-2 ps-1 text-[14px] font-medium leading-5 transition-colors duration-[120ms] motion-reduce:transition-none",+ open ? "text-ink" : "text-ink-secondary hover:text-ink")}+ renderTrigger={({ open: shown }) => (+ <span data-chathead-threads className="flex min-w-0 items-center gap-1">+ <span data-chathead-conversation dir="auto" className="min-w-0 max-w-[180px] truncate max-md:max-w-[120px]">{current ? tabTitle(current) : ""}</span>+ <ChevronDown size={12} aria-hidden="true"+ className={cn("shrink-0 text-ink-tertiary transition-[opacity,rotate] duration-[120ms] ease-out motion-reduce:transition-none",+ shown ? "rotate-180 opacity-100" : "opacity-0 group-hover/pill:opacity-100 group-focus-visible/threads:opacity-100 touch:opacity-100")} />+ </span>+ )} /></div>);}diff --git a/src/components/touch-actions.test.ts b/src/components/touch-actions.test.tsindex b6213b0c6d..bad9e63e72 100644--- a/src/components/touch-actions.test.ts+++ b/src/components/touch-actions.test.ts@@ -25,6 +25,7 @@ const notActions: Array<{ file: string; snippet: string; why: string }> = [{ file: "components/bot-panel/PanelHero.tsx", snippet: "whitespace-nowrap rounded-md border border-hairline bg-menu", why: "\"Edit avatar\" tooltip; the avatar button itself is the tap target" },{ file: "components/ChatView.tsx", snippet: "-ml-2.5 w-0 shrink-0 text-ink-secondary", why: "decorative chevron in the Simple bot pill; the whole pill is the tap target" },{ file: "components/ChatHeadPill.tsx", snippet: "-ml-2 flex w-0 shrink-0 overflow-hidden opacity-0", why: "decorative chevron in the Simple bot badge; the whole badge is the tap target" },+ { file: "components/ThreadSwitcherPill.tsx", snippet: "opacity-0 group-hover/pill:opacity-100 group-focus-visible/threads:opacity-100", why: "decorative chevron in the Simple thread pill, shown on keyboard focus too; the thread's name is the tap target" },{ file: "components/RoomHeader.tsx", snippet: "-ml-1 w-0 shrink-0 text-ink-secondary", why: "decorative chevron on the Simple room name; the whole name is the tap target" },{ file: "components/SidebarConnectApps.tsx", snippet: "opacity-60 grayscale", why: "decorative app logos, already visible at 60% without hover; the whole Apps row is the tap target" },{ file: "components/SidebarThreadLabels.tsx", snippet: "pointer-events-none absolute end-1 flex size-6", why: "hiding a thread on a touch screen goes through the bot panel's thread list; a ✕ on every sub-row would crowd the sidebar" },diff --git a/src/lib/control-focus.test.ts b/src/lib/control-focus.test.tsindex 2862cbc197..d30a121807 100644--- a/src/lib/control-focus.test.ts+++ b/src/lib/control-focus.test.ts@@ -50,6 +50,10 @@ describe("keyboard focus on form controls", () => {expect(fieldRule).toContain("input");});+ it("takes the ring off only inside a control last used with a pointer", () => {+ expect(outlineRemovers).toContain("[data-pointer-used] :focus-visible");+ });+it.each(CONTROLS)("never takes the outline off a %s input", (type) => {for (const selector of outlineRemovers) {for (const [compound] of selector.matchAll(/(?<![\w-])input(?![\w-])(?::not\((?:[^()]|\([^()]*\))*\))?/g)) {diff --git a/src/styles.css b/src/styles.cssindex f94c2a3f97..d158c77d06 100644--- a/src/styles.css+++ b/src/styles.css@@ -2229,6 +2229,10 @@ body {outline: 2px solid var(--color-focus);outline-offset: 2px;}+/* Inside a control last used with a pointer, focus that script moves, or a key that moves nothing, draws no ring. */+[data-pointer-used] :focus-visible {+ outline: none;+}/* Settings: nav items, identity rows, search results and whole-row buttons (link, fold and card rows) take an insetring, so it is never clipped by the card or drawn into the nav's edge. */[data-settings-look] :is([data-settings-page], [data-settings-hit], [data-settings-key-result], [data-settings-rows] > button, [data-settings-rows] > * > button[aria-expanded], [data-settings-fold] > button, [data-settings-rows] > button[data-pair-with-cloud]):focus-visible {