Skip to content

fix(sidebar): give an asked-for filter's focus to a row that takes it, and keep it open for the sidebar's own menus - #2141

Merged
devswha merged 2 commits into
mainfrom
fix/sidebar-filter-focus-dismissal
Oct 28, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/sidebar-filter-focus-dismissal

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Closes #2079 (follow-up to #2073).

What it fixes for the user

With Settings → Appearance → Sidebar filter off, the command palette's Filter workspaces and agents opens the
filter field for a filter's time. Three edges of that field were still broken on main:

  1. Closing it could leave the focus on nothing. When what opened the field is gone (for example the
    Settings switch, after turning the setting off while the field held words), Close filter / Escape fell back to
    the list's first button. That skipped the workspace row itself (a div[role=button]) and landed on the row's
    ⋯, which a desktop does not draw, so the focus stayed on <body>. Now it tries the opener, then each row
    control that is drawn, not inert and takes the focus, and checks that the focus actually landed before stopping.
  2. A row's menu counted as "outside" the sidebar. The menu is drawn through a portal, so opening a row's menu
    from the keyboard closed the empty field (and the menu was then drawn one row out of place), and a click on a
    menu item closed the field before the click landed. Now the sidebar counts a menu or sheet as its own when the
    menu's button is inside it: RowMenu records each open menu's button (rowMenuAnchor). A tab's menu, or any
    other one, still takes the empty field, as before.
  3. A late blur check could clear newer words. An empty field's blur to nowhere is decided a frame later. That
    frame is now cancelled when the field stops being closable or unmounts, and it rechecks that the field is still
    empty. Also, a press from the field's last close no longer makes its next blur ignored (pressedInside is reset
    when the field opens).

Design: the focus return follows the same pattern as useFocusTrap's return (lib/useFocusTrap.ts) and the
WAI-ARIA dialog practice, which VS Code's and Zed's quick-pick filters also follow: focus goes back to the opener,
or to the nearest sensible control, never to the document.

Tests

scripts/sidebar-declutter-demo-regression.ts gets a desktop filterEdges case (a new flat=1 fixture param
takes the worktrees off the demo's workspaces, so a row's first button is its undrawn ⋯):

  • the opener is gone → Close filter puts the focus on a visible row (fails on main: focus on <body>);
  • a row's menu opened from the keyboard keeps the field, sits under its row, and a click on its item keeps the field
    (fails on main);
  • an empty field's blur to nowhere closes it right after the press that closed it last (fails without the
    pressedInside reset);
  • a tab's menu takes the empty field (fails if every .row-menu counted as the sidebar);
  • words typed after a blur and before its frame survive (fails without the recheck).

Each case was checked failing with its fix reverted and passing with it. The full script passes (desktop and
phone, light and dark). bun run check fast is green.

Reviews

  • omo-native-code-reviewer: PASS, 4 LOW (one, "any .row-menu counts", also raised by Codex and fixed here).
  • Codex Sol 6.1 Fast xhigh: BLOCK on c5b0e58 (MEDIUM: a tab's menu kept the field; LOW: the late-blur test
    could pass without its fix). Both fixed in fe5a42e; re-review PASS with no findings.

…, and keep it open for a row's menu

Follow-up to #2073 (closes #2079):

- Close filter and Escape return the focus to what opened the field, else to the first row control that
  is drawn and takes it (a desktop draws no row ⋯, and a workspace row is a div[role=button]); each
  candidate is checked to hold the focus.
- A row's menu or sheet, drawn outside the sidebar, counts as the sidebar for the field's outside-press
  and focus-out handling.
- The deferred blur check is cancelled when the field stops being closable or unmounts, and rechecks
  that the field is still empty; a press from before the field opened no longer suppresses its first blur.
- scripts/sidebar-declutter-demo-regression.ts covers the three cases on a desktop.
Codex review of the previous commit: every .row-menu on the page counted as the sidebar, so a tab's
menu kept the empty asked-for filter open. RowMenu now records each open menu's button
(rowMenuAnchor), and the sidebar counts a menu as its own only when that button is inside it.

The regression also checks that a tab's menu takes the field, and that an empty field's blur to
nowhere takes it right after the press that closed it last (the pressedInside reset).
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between c5d9555 and fe5a42e.

Files selected for processing: 4
  • changelog.d/sidebar-filter-focus-edges.md
  • scripts/sidebar-declutter-demo-regression.ts
  • src/components/MachineSidebar.tsx
  • src/components/RowMenu.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Merging fe5a42e: omo-native-code-reviewer and Codex both pass this head, and the required checks are green, including the sidebar browser regression. CodeRabbit did not review this head. The LOW notes go to a follow-up issue.

@devswha
devswha merged commit 124e9b9 into main Oct 28, 2026
11 checks passed
@devswha
devswha deleted the fix/sidebar-filter-focus-dismissal branch October 28, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sidebar: asked-for filter focus and dismissal edge cases (follow-up to #2073)

1 participant