Skip to content

improve(ui): keep the focus ring to keyboard input - #190535

Merged
vyctorbrzezowski merged 3 commits into
mainfrom
brzezowski/menu-focus-ring-pointer
Nov 2, 2026
Merged

vyctorbrzezowski merged 3 commits into
mainfrom
brzezowski/menu-focus-ring-pointer

Conversation

@vyctorbrzezowski

@vyctorbrzezowski vyctorbrzezowski commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Opening a menu with a mouse or finger could paint the thick accent focus ring on its first item, and the ring could move to the trigger afterwards. It looked random: the same menu showed it on the first open after a page load and not on the second.

Menus focus their first item from script, and their triggers cancel pointerdown, so the click itself moves no focus. Both Chromium and Safari then decide :focus-visible for script focus from how focus last moved. A page load with no earlier focus gives a ring; an earlier click that focused something, such as main, gives none. The result depended on what had been clicked before, not on the menu. Measured on current main, real Safari and Chromium agree: first open after load shows the ring on Automations and Usage, and a second open after clicking elsewhere does not.

/ask has the same cause: its question panel takes focus from script on load, so the whole panel showed the ring until the first tap.

User Impact

Mouse and touch no longer show the ring when a menu opens, when focus returns to its trigger, or when /ask loads or collapses its question. Keyboard users keep it: opening with Enter, Space or arrows shows the ring on the first item, and Escape returns to a ringed trigger. Any key press in a mouse-opened menu shows the ring on the current row, including Home on the first row and a one-item menu; modifier keys alone don't. After a full page load /ask has no input to go on, so a keyboard user sees its ring on the first key press; arriving by keyboard from inside the app shows it at once.

Why This Change Was Made

Focus still moves to the same elements, so keyboard behavior doesn't change. A key press that leaves focus where a pointer put it refocuses that element once to paint the ring, after the page's own key handlers have run, and a screen reader can announce it again at that moment. A small helper records whether the last input was a key or a pointer and passes focusVisible to focus(), which Chromium and Safari both honored here. Because the browser's own state changes, every existing :focus-visible rule follows it and no CSS or per-page override is needed. Text fields keep their native indication.

It is applied in the shared Menu and overlay return focus, so every page gets it. Pages don't need pointerFocus="trigger" to avoid the ring. Outlines aren't removed anywhere.

Left alone:

  • Modals: Cancel in a confirm dialog still shows the ring after a mouse open in Safari, and so does the trigger after dialog.close() restores focus. Both are native dialog focus, not script, so this helper doesn't reach them. Changing that means changing how every modal opens, so it needs its own decision.
  • Search autofocus ring: handled in improve(ui): refine shared controls at phone width #190370.
  • Rings that follow Tab or arrow keys: these are the keyboard behavior being kept.

Evidence

Real clicks and keys against the mock's data, with no DOM changes. Safari 27.0.1 images use real OS clicks; no keys were sent to Safari.

Before, Safari, Absolutely dark, first click:

After, Safari, Absolutely dark, first click:

After, Safari, CRT, first click:

After, Chromium, Absolutely light, first click:

After, Chromium, Absolutely dark, 390px, tap on Usage Export:

Keyboard, Chromium, Absolutely light, Tab then Enter keeps the ring:

/ask before, Safari, Absolutely light, on load:

/ask after, Safari, Absolutely light, on load:

Local checks: oxfmt, oxlint, tsgo:ui, menu, overlay, modal, question and sidebar menu tests, and ui:check-performance:base.

@vyctorbrzezowski vyctorbrzezowski self-assigned this Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR makes programmatic menu and question-panel focus rings follow keyboard or pointer input.

Example: First mouse click on an Automations row menu in Safari.

  • Before: The “Run if due” item receives a thick accent focus ring.
  • After: The item retains focus without the ring; keyboard opening still shows it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong visual evidence supports a focused improvement, with two narrow validation repairs remaining.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected Safari menu and /ask before/after screenshots and Chromium pointer and keyboard screenshots exercise the actual UI with mock data, showing suppressed pointer rings and preserved keyboard rings.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Mouse-opened menus and initial question panels can show inconsistent keyboard-style focus rings.
Reason: The maintainer-authored direction addresses demonstrated visual inconsistency while retaining keyboard focus; native-dialog behavior is explicitly outside scope.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: the visual improvement is supported by browser screenshots, but the listener ratchet and an affected theme test need focused repairs.

Priority: P3
Reviewed head: d6ce951cfccca46391917e764befe050d185e209

Before merge

  • Use the shared listener primitive for modality tracking (P2) - The new direct window.addEventListener call adds one counted call in a file with no allowance in config/control-ui-addEventListener-baseline.txt. The UI’s shrink-only guard therefore rejects this source. Register these document-lifetime listeners through the existing listen helper rather than increasing the baseline.
  • Update the theme fixture to establish keyboard-visible focus (P2) - The existing theme test pointer-opens a submenu whose only row is Child, then presses Home and expects a visible outline. With this change, Home leaves focus on that same row and preserves the suppressed ring, producing the exact Chromium failure recorded by CI at line 136. Change the fixture to enter or move focus through keyboard navigation before checking theme ring styles; preserve the outline assertions.

Findings

  • [P2] Use the shared listener primitive for modality tracking — ui/src/lib/programmatic-focus.ts:5-8
  • [P2] Update the theme fixture to establish keyboard-visible focus — ui/src/components/solid/overlay-style.browser.test.tsx:102-106

Tests

  • Low-value test ui/src/components/solid/menu-focus-visibility.browser.test.tsx: Remove the final generic-button helper test: pointer suppression and keyboard restoration are already exercised through the real menu; retain the distinct native text-field case.
  • Missing end-to-end proof: The supplied checks do not establish that the added regression tests fail on the base for the intended reason.
Agent review details

How this fits together

The Control UI’s shared menu and overlay owners move DOM focus; the new helper supplies input modality to the browser’s existing focus-visible styling.

flowchart LR
  A[Keyboard and pointer events] --> B[Input modality helper]
  C[Menu navigation] --> B
  D[Overlay focus return] --> B
  E[Question panel] --> B
  B --> F[Browser focus and ring]
Loading

Technical review

Best possible solution:

Retain the shared modality helper and existing focus owners, use the supported listener primitive, and make the theme test establish keyboard focus explicitly.

Do we have a high-confidence way to reproduce the issue?

Current-main script focus and cancelled trigger pointerdown support the reported first-open behavior, corroborated by the supplied Safari before screenshot; no target code was executed.

Is this the best way to solve the issue?

The shared helper is a small, coherent fix that preserves real focus and existing styling; the recorded same-row keyboard limitation does not require broader machinery.

Full review comments:

  • [P2] Use the shared listener primitive for modality tracking — ui/src/lib/programmatic-focus.ts:5-8
    The new direct window.addEventListener call adds one counted call in a file with no allowance in config/control-ui-addEventListener-baseline.txt. The UI’s shrink-only guard therefore rejects this source. Register these document-lifetime listeners through the existing listen helper rather than increasing the baseline.
    Confidence: 0.99
  • [P2] Update the theme fixture to establish keyboard-visible focus — ui/src/components/solid/overlay-style.browser.test.tsx:102-106
    The existing theme test pointer-opens a submenu whose only row is Child, then presses Home and expects a visible outline. With this change, Home leaves focus on that same row and preserves the suppressed ring, producing the exact Chromium failure recorded by CI at line 136. Change the fixture to enter or move focus through keyboard navigation before checking theme ring styles; preserve the outline assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9c62fce8a37d.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:control-ui-controllers
  • pnpm --dir ui test src/components/solid/menu-focus-visibility.browser.test.tsx src/components/solid/overlay-style.browser.test.tsx
  • git diff --check

What I checked:

  • Pinned introduction and current main: The introduced diff centralizes focus visibility without changing focus destinations; the affected production files on fetched main retain the original behavior. (ui/src/lib/programmatic-focus.ts:18, d6ce951cfccc)
  • Inspected visual proof: Inspected downloaded Safari before/after and Chromium pointer screenshots, plus the linked Chromium keyboard and Safari /ask before/after images; they show the intended ring differences with synthetic content. (d6ce951cfccc)
  • Listener policy violation: The new direct addEventListener call has no per-file allowance; the UI policy and source guard enforce shrink-only counts, and the existing listen helper provides the supported registration path. (scripts/check-control-ui-controllers.mts:596, d6ce951cfccc)
  • Diff-caused browser test failure: The Chromium CI annotation reports outlineStyle none at overlay-style.browser.test.tsx:136; that test pointer-opens a one-row submenu and presses Home without moving focus, matching the PR’s documented limitation. (ui/src/components/solid/overlay-style.browser.test.tsx:136, d6ce951cfccc)
  • CI inspection limit: check-lint failed during changed lint and the aggregate gate reports the lint/UI failures; detailed job logs redirect to a blocked Azure host, so the exact lint diagnostic was unavailable. (d6ce951cfccc)
  • Feature history and policy: History traces the native overlay, deferred menu navigation, and subsequent menu styling work; root and UI AGENTS.md were applied, no maintainer-notes directory exists, and the installed Solid cheatsheet is unavailable. (ui/AGENTS.md:3, 9c62fce8a37d)

Likely related people:

  • Vyctor H. Brzezowski: Raw commit 3da32db adds ui/src/components/solid/menu.tsx:55 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3da32db83c71; files: ui/src/components/solid/menu.tsx)

PR surface

Source +37, Tests +74. Total +111 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 8 50 13 +37
Tests 1 74 0 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 124 13 +111

Labels

Label changes:

  • add P3: This is visual focus polish with existing navigation and focus destinations preserved.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P3: This is visual focus polish with existing navigation and focus destinations preserved.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 1, 2026, 12:10 PM ET / 17:10 UTC.

@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
* improve(ui): keep the focus ring to keyboard input

* improve(ui): show the ring on any key in a pointer-opened menu

* fix(ui): repaint the ring after a key's own handlers run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant