From 18be128accdedf699eb42e08236b06cb229c6f6f Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:46:36 -0600 Subject: [PATCH] fix(app): remove the focus rings around the timeline and composer (#65690) --- .opencode/skills/focus-states/SKILL.md | 16 ++-- .../app/component-tests/focus-rescue.spec.ts | 16 +++- packages/app/e2e/regression/composer.spec.ts | 7 +- packages/app/e2e/regression/home.spec.ts | 8 +- .../focus-visibility.stories.tsx | 93 +------------------ packages/app/src/composer/editor/editor.css | 6 -- packages/app/src/composer/editor/editor.tsx | 27 +++--- .../app/src/composer/editor/interaction.ts | 14 +-- packages/app/src/home/sessions/view.css | 4 - packages/app/src/home/sessions/view.tsx | 15 +-- packages/app/src/index.css | 17 ---- packages/app/src/new-session/commands.tsx | 5 +- packages/app/src/new-session/screen.tsx | 2 +- .../app/src/session/composer/controller.ts | 5 +- packages/app/src/session/composer/focus.tsx | 3 +- packages/app/src/session/composer/region.tsx | 6 +- packages/ui/src/components/scroll-view.css | 5 - packages/ui/src/context/dialog.tsx | 26 ++---- packages/ui/src/context/field-focus.tsx | 76 --------------- packages/ui/src/context/focus-rescue.tsx | 14 +-- 20 files changed, 71 insertions(+), 294 deletions(-) delete mode 100644 packages/ui/src/context/field-focus.tsx diff --git a/.opencode/skills/focus-states/SKILL.md b/.opencode/skills/focus-states/SKILL.md index fb255243cf4..a858add4192 100644 --- a/.opencode/skills/focus-states/SKILL.md +++ b/.opencode/skills/focus-states/SKILL.md @@ -9,7 +9,7 @@ Use one default ring when someone navigates focus to a control, not when they cl ## The ring -- Use `:focus-visible` for the ring. Don’t use `:focus` to decide whether to show it. The only exception is a custom field that combines `:focus` with its own ring state, as the composer and Home search do (see Text fields). `base.css` supplies `outline: 2px solid var(--v2-border-border-focus); outline-offset: 2px` and a 4px radius for links. +- Use `:focus-visible` for the ring. Don’t use `:focus` to decide whether to show it. `base.css` supplies `outline: 2px solid var(--v2-border-border-focus); outline-offset: 2px` and a 4px radius for links. - Offset: `2px` outward by default. `-2px` inset for full-width rows and for controls flush against an edge that clips or scrolls (segmented items, split buttons, titlebar buttons, clear buttons). No other offsets. - Follow the control’s radius; give a square text action or link 4px where appropriate. Use a wrapper with `:has(> trigger:focus-visible)` when the wrapper owns the visible shape or the trigger’s ring would clip, as with tabs and Settings project cards. - Outline only. Don't draw focus with `box-shadow`: Windows High Contrast removes shadows, so the ring disappears, and shadow rings looked different from every other ring. @@ -18,15 +18,13 @@ Use one default ring when someone navigates focus to a control, not when they cl - Inline rename inputs rely on the caret and editing state. The timeline's Jump to latest stays in the Tab order with the shared ring, since it's the only quick way back down from the keyboard; its container is `inert` while it's hidden. Loading alone doesn’t add a ring. If a busy button keeps keyboard focus, keep the ring and show the busy state separately with `aria-busy`, a disabled state, or loading text; the ring alone doesn’t say whether the button can be activated. - These ring rules do not replace normal field borders or validation feedback. Those can respond to click focus and have their own inset treatment. -## Text fields +## Text fields and scroll areas -Editable fields can match `:focus-visible` after a click, so fields with a custom frame ring (the composer and Home search) decide when focus arrives. Use `packages/ui/src/context/field-focus.tsx`, not a global input tracker. +Chromium matches `:focus-visible` on every focused text field, and on anything that has focus once a key is pressed. A ring on a large surface then shows after a click, when the app moves focus there, and on returning to the window. -- Ring by default. Suppress the ring for direct pointer focus and for the composer’s explicit initial autofocus when a session or draft opens, including when it was opened with the keyboard. -- Tab, shortcuts like Find, and assistive technology moving DOM focus show the ring. Moving a screen reader’s reading cursor alone does not move DOM focus. -- When a dialog returns focus to a custom field, `packages/ui/src/context/dialog.tsx` restores the field's own ring state; ordinary controls use the browser's `:focus-visible` state. The overlay rules below apply. -- A `pointerdown` inside a field that already shows the ring clears it immediately; no new focus event fires. Typing never changes the decision, and blur clears it. -- A click shows the field's normal focused border or background and the caret, with no ring. +- A text field never draws the ring, the composer and Home search included. Focus shows as the caret and the field's focused border or background. Don't add ring state or pointer tracking to a field. +- A scroll area (the timeline, Home's list) takes focus so the keyboard can scroll it, and draws no ring. Show focus on the items inside it instead. +- Moving a screen reader’s reading cursor alone does not move DOM focus. ## Rows @@ -63,7 +61,7 @@ Editable fields can match `:focus-visible` after a click, so fields with a custo - Follow logical reading and interaction order, including in RTL. Fix DOM order rather than using positive `tabindex`. Use native buttons for actions and links for navigation; use established widget primitives or keyboard patterns for tabs, trees, sliders, and resize handles. - Move focus in response to a user action or to recover focus when its target disappears. Background updates, streamed output, toasts, and incoming prompts must not steal focus. - If a focused item is closed or deleted, move focus to the next place the user can continue the same task: the next or previous item in the same list, or a stable fallback such as the list heading or the control that opened it. Use the visually nearest control only when it serves that task. Don’t leave focus on `
`. -- Chromium drops focus to `` without an event when the focused element is removed, disabled, or stops being editable. `packages/ui/src/context/focus-rescue.tsx` (installed in `AppBaseProviders`) recovers it inside a `data-focus-scope`: the next item, or the previous after the last, widening to the enclosing scope when the inner one is empty, and back to what had focus before when nothing is left. Mark a new list, strip, chip row or panel with `data-focus-scope` rather than adding per-feature focus code. Rescue never moves focus into a `role="tablist"`, because Kobalte tabs select themselves on focus, so don't mark a tab list as a scope. Items in an overlay leave the return to the overlay; rescue steps in only when the overlay's opener is gone too. Move focus explicitly when the task has a better target than the neighbour, such as the composer after the last chip. +- Chromium drops focus to `` without an event when the focused element is removed, disabled, or stops being editable. `packages/ui/src/context/focus-rescue.tsx` (installed in `AppBaseProviders`) recovers it inside a `data-focus-scope`: the next item, or the previous after the last, widening to the enclosing scope when the inner one is empty, and back to what had focus before when nothing is left. The control it moves focus to shows its ring only when Tab or an arrow key last moved focus; typing, shortcuts and a key pressed on a clicked control don't count. Mark a new list, strip, chip row or panel with `data-focus-scope` rather than adding per-feature focus code. Rescue never moves focus into a `role="tablist"`, because Kobalte tabs select themselves on focus, so don't mark a tab list as a scope. Items in an overlay leave the return to the overlay; rescue steps in only when the overlay's opener is gone too. Move focus explicitly when the task has a better target than the neighbour, such as the composer after the last chip. ## Verify diff --git a/packages/app/component-tests/focus-rescue.spec.ts b/packages/app/component-tests/focus-rescue.spec.ts index f8e97d1f791..8508f66fe0d 100644 --- a/packages/app/component-tests/focus-rescue.spec.ts +++ b/packages/app/component-tests/focus-rescue.spec.ts @@ -20,7 +20,9 @@ story.describe("scopes", () => { story("moves focus to the next item, or to the previous one after the last", async ({ page }) => { const list = page.getByTestId("list") - await list.getByRole("button", { name: "Two" }).focus() + // Tab moves focus to the item, so the item that takes over shows its ring. + await list.getByRole("button", { name: "One" }).press("Tab") + await expect(list.getByRole("button", { name: "Two" })).toBeFocused() await page.keyboard.press("Enter") await expect(list.getByRole("button", { name: "Three" })).toBeFocused() expect(await ringed(list.getByRole("button", { name: "Three" }))).toBe(true) @@ -29,6 +31,17 @@ story.describe("scopes", () => { await expect(list.getByRole("button", { name: "One" })).toBeFocused() }) + story("leaves the item that takes over without a ring when no key moved focus there", async ({ page }) => { + const list = page.getByTestId("list") + + // Typing and Enter are not navigation, and the item got focus from code. + await page.keyboard.press("a") + await list.getByRole("button", { name: "Two" }).focus() + await page.keyboard.press("Enter") + await expect(list.getByRole("button", { name: "Three" })).toBeFocused() + expect(await ringed(list.getByRole("button", { name: "Three" }))).toBe(false) + }) + story("returns focus to what had it before when a scope is left empty", async ({ page }) => { await page.getByTestId("opener").focus() await page.getByTestId("toasts").getByRole("button", { name: "Toast" }).focus() @@ -65,7 +78,6 @@ for (const action of ["Steer", "Remove"]) { const editor = root.locator('[data-component="session-composer-dock"] [contenteditable="true"]') await expect(editor).toBeFocused() - await expect(editor).not.toHaveAttribute("data-keyboard-focus") }, ) } diff --git a/packages/app/e2e/regression/composer.spec.ts b/packages/app/e2e/regression/composer.spec.ts index d319ad0f6da..0169df1fbd3 100644 --- a/packages/app/e2e/regression/composer.spec.ts +++ b/packages/app/e2e/regression/composer.spec.ts @@ -5,7 +5,7 @@ import { mockPluginsActivating, type MockServerConfig } from "../utils/mock-serv test.use({ permissions: ["clipboard-read", "clipboard-write"] }) -test("the composer preserves its ring on dialog return and leaves autofocus and clicks quiet", async ({ page }) => { +test("the composer shows its caret, never a focus ring, however focus arrives", async ({ page }) => { const view = await openSession(page, { name: "ComposerKeyboardFocus" }) const frame = page.locator('[data-component="composer"]').filter({ has: view.editor }) @@ -17,7 +17,8 @@ test("the composer preserves its ring on dialog return and leaves autofocus and await expect(view.editor).not.toBeFocused() await page.keyboard.press("Tab") await expect(view.editor).toBeFocused() - await expect(frame).toHaveCSS("outline-style", "solid") + await expect(frame).toHaveCSS("outline-style", "none") + await expect(view.editor).toHaveCSS("outline-style", "none") const modifier = await page.evaluate(() => (/Mac/i.test(navigator.platform) ? "Meta" : "Control")) @@ -27,7 +28,7 @@ test("the composer preserves its ring on dialog return and leaves autofocus and await expect(dialog.getByRole("combobox")).toBeFocused() await page.keyboard.press("Escape") await expect(view.editor).toBeFocused() - await expect(frame).toHaveCSS("outline-style", "solid") + await expect(frame).toHaveCSS("outline-style", "none") await view.editor.click() await expect(view.editor).toBeFocused() diff --git a/packages/app/e2e/regression/home.spec.ts b/packages/app/e2e/regression/home.spec.ts index a5015696b78..b240e4e4948 100644 --- a/packages/app/e2e/regression/home.spec.ts +++ b/packages/app/e2e/regression/home.spec.ts @@ -73,11 +73,9 @@ test("Home projects, utility rows, search and recent sessions show keyboard focu const field = page.locator('[data-slot="home-session-search-field"]') + // A text field shows its caret and background, not a ring. await page.keyboard.press("Tab") await expect(search).toBeFocused() - await expect(field).toHaveCSS("outline-style", "solid") - await search.click() - await expect(search).toBeFocused() await expect(field).toHaveCSS("outline-style", "none") const recent = page.getByRole("region", { name: "Recent sessions" }) @@ -95,8 +93,9 @@ test("Home projects, utility rows, search and recent sessions show keyboard focu await expect(viewport).toHaveAttribute("tabindex", "0") await viewport.press("Shift+Tab") await page.keyboard.press("Tab") + // The list takes focus so the keyboard can scroll it, without a ring around the whole area. await expect(viewport).toBeFocused() - await expect(viewport).toHaveCSS("outline-offset", "-2px") + await expect(viewport).toHaveCSS("outline-style", "none") }) test("Home keeps the session list in every interface mode", async ({ page }) => { @@ -333,7 +332,6 @@ test("tabbing out of session search closes its results, and tabbing back reopens await page.keyboard.press(`${modifier}+f`) await expect(search).toBeFocused() - await expect(page.locator('[data-slot="home-session-search-field"]')).toHaveCSS("outline-style", "solid") await expect(panel.getByRole("option")).toContainText(earlier.title) }) diff --git a/packages/app/src/components-lab/focus-visibility.stories.tsx b/packages/app/src/components-lab/focus-visibility.stories.tsx index 099d4ee7a52..a6545aaa878 100644 --- a/packages/app/src/components-lab/focus-visibility.stories.tsx +++ b/packages/app/src/components-lab/focus-visibility.stories.tsx @@ -36,7 +36,6 @@ import { Tabs } from "@opencode/ui/tabs" import { TextInput } from "@opencode/ui/text-input" import { createEffect, createSignal, createUniqueId, For, onCleanup, onMount, Show, type JSX } from "solid-js" import { createTabStripScroll } from "@/runtime/plugin/tab-strip-scroll" -import { createFieldFocus } from "@opencode/ui/context/field-focus" import { createOverlayFocus } from "@opencode/ui/context/overlay-focus" import { installFocusRescue } from "@opencode/ui/context/focus-rescue" import { useDialog } from "@opencode/ui/context/dialog" @@ -248,16 +247,6 @@ const surfaces: Surface[] = [ ), }, - { - name: "Composer editor: caret is the only focus cue", - failure: "Invisible", - target: '[data-component="composer-editor"]', - keys: "Focus the preceding button, then press Tab into the prompt. Click inside the prompt to see the ring go away.", - sizing: "The editor sits inside a masked scroll viewport.", - source: "app/src/composer/editor/editor.css, ui/src/context/field-focus.tsx, context/dialog.tsx", - fix: "Draw an inset ring on focus entry except for click-to-type and session autofocus. Returning from a dialog restores the previous ring state.", - render: (forced) =>