Skip to content

v1.16.14: Keep keyboard focus inside the edit drawer while it's open - #37

Open
gitluis wants to merge 3 commits into
fix-account-order-after-importfrom
fix-drawer-focus
Open

gitluis wants to merge 3 commits into
fix-account-order-after-importfrom
fix-drawer-focus

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #36 (fix-account-order-after-import), in a chain of fixes on top of the Clarity redesign (#16 → #17 → #19 → #20 → #21). Merge in order: #16, #17, #19, #20, #21, then the fixes #24–#38 and #39–#50 in order, then #10, then #23. #18 is a separate patch on master (already merged).
This fix doesn't use any earlier fix's code; it is stacked only so versions and the CHANGELOG merge cleanly.

Summary

The shared edit drawer (#txDrawer) now behaves as a modal dialog. Focus moves onto its first field when it opens. Tab and Shift+Tab cycle inside it, and the page behind it can't be focused or clicked. Escape closes it, and focus goes back to the control that opened it, also after Save re-renders the screen. It looks the same as before.

Every edit form uses this one drawer, so all of them are fixed:

  • Transaction detail, from Overview, Transactions, Income and Spending (showTxDrawer())
  • Transfer detail, from Transfers (showTransferDrawer())
  • Edit bill, from Bills (showBillForm(i)). Add bill (showBillForm(-1)) uses it too, but no button calls it in v1.16.0: + Add bill opens an inline form.
  • Add budget category and Edit budget (editBudget())
  • Edit bucket (editBucket()). + New bucket is an inline form, not the drawer.
  • Add debt, Add debt from a card and Edit debt (editDebt())

No other screen opens a drawer. I checked every openDrawer() caller.

master has the same problem, and more. Checked in a browser on origin/master (v1.10.4):

  • Its drawer has no role, aria-modal or label.
  • Focus stays where it was when the drawer opens.
  • Tab from the drawer's last control leaves the page.
  • Nothing behind it is inert.
  • Its 25 controls stay focusable while it's closed and off-screen.
  • Transaction rows there can't be opened from the keyboard at all.

Escape does close it.

Cause

index.html gave the drawer role="dialog", aria-modal="true" and aria-labelledby="drawerTitle", but nothing in the code made it act like one:

  • Nothing was inert. The app bar, the page and the footer stayed in the Tab order. Shift+Tab from × went into the screen behind the drawer. Tab from the last button left the page for the browser's toolbar, because the drawer is the last thing in <body>.
  • Focus went to ×, after a setTimeout, not to the first field.
  • Save and Delete re-render the screen right after closeDrawer(). That replaced the button focus had just been returned to, so focus ended up on <body>.

Mouse clicks were already blocked: the drawer's scrim (z-index 49) covers the app bar (40) and the page.

What changed

All in js/ui.js. No markup, CSS or caller changed.

  • openDrawer():
    • Makes every other child of <body> inert: the app bar, the menu scrim, <main>, the footer and the hidden file inputs. It skips the drawer, its scrim (clicking it still closes the drawer) and <script> tags.
    • Records what it set, so closing lifts only that.
    • Closes any open app bar menu or popover (closeAppBarPopups()).
    • Focuses the first field (input, select or textarea that's visible, enabled and not read-only), or × when there is none.
    • Called while the drawer is open, it swaps the contents, focuses the new first field, and keeps the original opener and inert set.
  • Tab and Shift+Tab wrap: a keydown handler moves focus from the last control to × and back. If focus is outside the drawer, it moves focus to the first control (Tab) or the last (Shift+Tab). _drawerTabbables() lists the controls the browser would stop at: visible, enabled, not tabindex="-1", and one radio per group.
  • closeDrawer():
    • Lifts inert first, then returns focus to the opener.
    • When the opener has been replaced by a re-render (Save or Delete, or a render while the drawer was open), it focuses the new copy on the next tick. _drawerFocusKey() finds it by its id or data-* attributes. An opener with neither, like the Transfers row's button, is found by its position inside its tr[data-out][data-in].
    • After Delete, the copy is the row now in the deleted one's place.
    • Focus left on the closing drawer's own controls counts as lost: the drawer stays visible for the .25s it takes to slide out.
  • Unchanged: Escape (init.js already closed the drawer; it still closes an open app bar menu first), the scrim and ×, the drawer's look, and every form's fields, Save and Delete.
  • Version: v1.16.14 in CHANGELOG.md, the index.html footer, README.md (badge and footer line), js/views-settings.js and CLAUDE.md §1. CLAUDE.md §9 describes the drawer's modal behavior, and the "Last updated" line mentions it.

Not verified

  • Browsers other than headless Chromium, including desktop Edge and Chrome by hand, Firefox and Safari. inert needs Chrome/Edge 102+, Firefox 112+ or Safari 15.5+. Without it, Tab still wraps, but the page behind could be focused by script or a screen reader's virtual cursor.

  • Screen readers. The dialog's name was checked through Playwright's accessibility tree, not NVDA, JAWS or VoiceOver.

  • Escape while a native <select> list inside the drawer is open. Headless Chromium doesn't show the native list.

  • Phones and touch. Out of scope (desktop only); the existing phone checks in test-clarity.js still pass.

  • Focus after Delete or "Add debt from a card", where the opener may be gone:

    • After Delete, focus goes to the row now in the deleted one's place: the next bill, budget, bucket or debt.
    • When there's no such row, or after saving "Add debt from a card" (its button disappears once the card has a debt), focus falls to the page.

    Both are better than before, when focus always fell to the page, but neither is a designed destination.

Automated checks: earlier run, not re-run · 9768f6f

Moved unchanged from this PR's "Test results" comment on 2026-11-04; not re-run, so not in the new table format. Originally a description section titled "How it was tested".

Headless Chromium (Playwright) at 1280×900 against samples/ (257 transactions), with the pinned CDN libraries served from npm, on this branch's final commit 9768f6f, chained on #36. Each script ran as NODE_PATH=$(npm root -g) node <script> <repo> <outdir>, from one harness shared by every branch in the stack: the base suites, plus every test added by this PR or by a PR below it (cumulative regression).

Script Result on 9768f6f
test-clarity.js 55/55
test-insights.js 137/137
test-finances.js 126/126
test-plan.js 127/127
boot.js 257 transactions, 24 views, 0 errors
race.js 7 errors, all renderImportLog (the race #18 fixes on master; not in this stack)
test-clear-edits.js (from #24) 47/47
test-rebuild-folder.js (from #25) 57/57
test-partial-import.js (from #26) 47/47
test-json-import.js (from #27) 28/28
test-new-browser-copy.js (from #28) 10/10
test-json-export.js (from #29) 31/31
test-plan-links.js (from #30) 60/60
test-rule-flags.js (from #31, as updated by #32) 67/67
test-drawer-flags.js (from #32) 36/36
test-start-balance.js (from #33, as updated by #34) 193/193
test-ai-summary-period.js (from #34) 78/78
test-account-names.js (from #35) 40/40
test-account-order.js (from #36) 32/32
test-drawer-focus.js (new in this PR) 167/167

Measured before the chain

By the agent that wrote the fix, on 8a1cb63 (built on 70c7125, v1.16.0; then numbered v1.16.10).

Headless Chromium (Playwright) at 1280×900 against samples/. CDNs are served from npm by the harness. All scripts ran as NODE_PATH=$(npm root -g) node <script> <worktree> <outdir>.

New: test-drawer-focus.js. Each of the 13 drawer cases below opens from its real opener with the keyboard: focus the opener, then press Enter. The exception is Add bill, which opens from code because no button calls it.

  • Transaction detail ×4 (Transactions, Overview, Income, Spending)
  • Transfer detail, Edit bill, Add bill
  • Add budget category, Edit budget, Edit bucket
  • Add debt from a card, Add debt, Edit debt

Each case checks:

  • a modal dialog named by its title (Playwright's role query);
  • focus moves into it, onto the expected first field;
  • the app bar, <main> and the footer are inert, and calling focus() on each visible control behind it fails;
  • Tab and Shift+Tab go all the way round (5 to 22 stops) without leaving;
  • Tab on the last button wraps to ×, and Shift+Tab on × wraps back;
  • Escape closes it, focus is back on the opener, and no [inert] is left;
  • Save still saves, closes the drawer, leaves no inert, and puts focus back on the opener once the screen has re-rendered;
  • Delete (two clicks) still deletes, for bill, budget, bucket and debt.

It also checks:

  • a re-render while open: focus stays put, the new page behind it is inert, Tab still wraps, and Escape returns focus to the re-rendered opener;
  • a drawer opened over a drawer (transaction → transaction → budget form): contents swap, focus moves to each new first field, inert is unchanged, and × returns focus to the first opener;
  • an open accounts or date popover is closed when the drawer opens (from code and from the keyboard);
  • a mouse click on the Trends link behind the drawer hits the scrim: the drawer closes and the screen doesn't change;
  • no console errors.
Script Before (70c7125) After (8a1cb63)
test-drawer-focus.js (new) 85/167 167/167
test-clarity.js 55/55 55/55
test-finances.js 126/126 126/126
test-plan.js 127/127 127/127
test-insights.js (version check reads the footer) 137/137 137/137
boot.js 0 errors 0 errors
race.js 6 errors, all renderImportLog (#18) 6 errors, all renderImportLog (#18)

The 82 failures before are every "first field", "inert / can't take focus", "Tab cycles", "Shift+Tab cycles" and "wraps" check, and "focus back on the opener after Save" (body instead). On top of those: the re-render, drawer-over-drawer and popover-from-code checks.

No existing suite was edited. The existing check "Drawer: Escape closes it and focus returns" in test-finances.js still passes.

Looks unchanged: a screenshot of the open Transaction detail drawer, with focus removed, is byte-identical before and after (drawer-open.png).

master was checked with a separate probe (probe-master-drawer.js) in a temporary worktree, since removed.

How to reproduce the bug

Run this on the base branch, fix-account-order-after-import (#36). Master has the same problem, and more: its drawer doesn't move focus at all, and Tab leaves it.

  1. Do the Setup from the testing steps below, but check out fix-account-order-after-import instead of fix-drawer-focus. Load Try it with sample data.
  2. Open Transactions. Click once on an empty part of the page.
  3. Press Tab until a transaction's description (a link-style button in the Description column) is focused.
  4. Press Enter. The Transaction detail drawer opens.
  5. Note where focus is. Then press Shift+Tab once.
  6. Press Escape, reopen the drawer the same way, and press Tab until you pass Save changes.

What goes wrong:

  • At step 5, focus is on ×, not in Description.
  • Shift+Tab from × goes into the page behind the drawer.
  • Tab from Save changes leaves the page for the browser toolbar.
Manual QA steps

Setup

  1. git checkout fix-drawer-focus.
  2. Open index.html in Edge. Load data with Try it with sample data (or your usual folder: this PR doesn't change saving).
  3. Set the date range to All time (calendar icon in the app bar).
  4. For the Plan tests, have at least one budget, one bucket and one debt. If you have none: Plan → Budget → Use starter budget; Plan → Buckets → + New bucket, fill a name and save; Plan → Debt → + Add debt, fill it in and click Save debt.
  5. Use the keyboard for the opening steps. Click once on an empty part of the page first so focus is inside it.

1. Transaction detail opens with the cursor in Description

  1. Open Transactions.
  2. Press Tab until a transaction's description (a link-style button in the Description column) is focused.
  3. Press Enter.

Expected:

  • The Transaction detail drawer slides in.
  • The text cursor is in Description; typing changes the description.

Before this fix: focus went to × instead.

2. Tab and Shift+Tab stay inside the drawer

  1. With the drawer from test 1 open, press Tab repeatedly (about 15 times).
  2. Watch the focus ring. Note the last stop before it wraps.
  3. Press Shift+Tab repeatedly.

Expected:

  • Focus goes through Description, Category, Type, Also count it under other categories, the Bill / Recurring / Subscription boxes, Notes, the link fields (if you have plans), Cancel, Save changes, then back to ×.
  • Shift+Tab from × goes to Save changes.
  • Focus never lands on the app bar, the list behind, the footer or the browser toolbar.

Before this fix: Shift+Tab from × went into the page behind; Tab from Save changes left the page.

3. The page behind is inert

  1. With the drawer open, click a nav link in the app bar, e.g. Trends.
  2. Reopen the drawer (Tab to a description, Enter).
  3. Press F12 → Elements. Select <main class="main">.

Expected:

  • Step 1: the click only closes the drawer (it hits the dimmed scrim). You stay on Transactions.
  • Step 3: <header class="appbar">, <main>, <footer> and the hidden <input type="file"> elements carry an inert attribute. #txDrawer and #drawerScrim don't.

4. Escape and the scrim close it, and focus goes back

  1. With the drawer open, press Escape.
  2. Note where focus is.
  3. Open the drawer again from the keyboard. Click the dimmed area to the left of it.
  4. In Elements, search (Ctrl+F) for inert.

Expected:

  • After Escape, the focus ring is on the same description you opened.
  • Clicking the scrim closes the drawer too.
  • No element has inert left once the drawer is closed.

5. Save returns focus to the row after the re-render

  1. Tab to a transaction's description and press Enter.
  2. Tab to Notes, type focus test.
  3. Tab to Save changes and press Enter.
  4. Press Tab once.

Expected:

  • The drawer closes and the note shows under the row's description.
  • The focus ring is on that same description button (not lost at the top of the page). Step 4 moves to the next control in the row, not to the app bar's first link.

Before this fix: focus fell to the page (document.body), so Tab started from the top.

Remove the note afterwards if you like (open it, clear Notes, Save changes).

6. Other screens that open Transaction detail

  1. On Overview, Tab to a transaction in Largest card purchases and press Enter. Check the cursor is in Description, then Escape.
  2. Do the same from Income and Spending (filter pills at the top of Transactions).

Expected:

  • Same as tests 1 and 4 each time: cursor in Description, Escape returns focus to the row.

7. Transfer detail

  1. Click the Transfers pill on Transactions.
  2. Tab to a row in the transfers list (the "From → To" button) and press Enter.
  3. Tab round the drawer, then press Escape.

Expected:

  • Transfer detail opens with the cursor in the first leg's Description.
  • Tab wraps from Save changes to ×.
  • After Escape, focus is back on the row's button.

8. A Plan form: Edit budget, with Save and Delete

  1. Open Plan → Budget.
  2. Tab to a budget's name (the link in the Category column) and press Enter.
  3. Check the drawer is titled Edit budget and the cursor is in Name.
  4. Tab round: it wraps between × and Save budget.
  5. Change Monthly budget ($) and press Enter on Save budget.
  6. Check focus is on the same budget's name.
  7. Open it again, click Delete, then Click again to delete.

Expected:

  • Step 6: the drawer closes, the amount shows, and focus is on that budget's name.
  • Step 7: the budget is gone, and focus is on the budget now in its place (or on the page if it was the last one).

9. The other Plan drawers

For each, open with the keyboard, check the first field has the cursor, Tab round once, press Escape and check focus is back on the button you used:

  1. Plan → Budget → + Add category (title Add budget category, cursor in Name).
  2. Plan → Buckets → a bucket's pencil (Edit …) button (title Edit bucket).
  3. Plan → Debt → + Add debt (title Add debt) and a debt's pencil button (title Edit debt).
  4. Plan → Debt → an Add Bank Credit Card (…) button, if shown (adds a debt from a card).
  5. Transactions → Bills pill → a bill's pencil (Edit …) button (title Edit bill, cursor in Name).

Expected:

  • Each behaves like tests 1, 2 and 4.
  • Note: + New bucket and + Add bill open inline forms, not the drawer, so they don't change.

10. Opening the drawer closes an open popover

  1. On Transactions, Tab to the Accounts icon in the app bar and press Enter. Its popover opens.
  2. Without clicking, press Tab until focus reaches a transaction description in the list (the popover stays open while you Tab).
  3. Press Enter.
  4. Press Escape once.

Expected:

  • At step 3 the drawer opens and the Accounts popover closes.
  • One Escape closes the drawer, and focus returns to the description.

11. It looks the same

  1. Open Transaction detail in light theme. Then Settings → General → Theme → Dark and open it again.
  2. Press F12 → Console.

Expected:

  • The drawer looks as it did before (width, colours, scrim, slide-in).
  • No red errors in the Console.

Please check before merging

  • On Transactions, Tab to a description and press Enter: the drawer opens with the cursor in Description.
  • Tab and Shift+Tab repeatedly: focus stays in the drawer and wraps between × and Save changes.
  • With the drawer open, the app bar and the list behind it can't be reached with Tab.
  • Change a note and Save changes: the drawer closes and focus is back on the row you opened.
  • Escape closes the drawer; clicking the dimmed page closes it too.
  • Same for one Plan form (e.g. Budget → a budget's name → Edit budget, then Save, or Delete with two clicks).
  • The drawer looks the same as before in light and dark.
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

The shared drawer (#txDrawer) was marked as a modal dialog but didn't act like one:
Tab left it, the page behind could take focus, it opened on × instead of the first
field, and focus was lost after Save re-rendered the screen.

openDrawer() now makes every other child of <body> inert (the scrim stays live),
closes any open app bar popup and focuses the first field (× when there is none).
A keydown handler wraps Tab and Shift+Tab inside it. closeDrawer() lifts inert and
returns focus to the opener, or to its re-rendered copy (id or data-* attributes).

Version bumped in CHANGELOG, index.html, README, views-settings.js and CLAUDE.md §1;
CLAUDE.md §9 describes the drawer's modal behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
…-drawer-focus

Carries master's v1.10.3-v1.10.5 up the stack: declined answers (#14),
literal single "~" (#15) and the Import Logs race fix (#18), with
clarity-insights' port of #14 to the rebuilt AI tab.

One conflict: CLAUDE.md's "Last updated" line. Kept this branch's
line and added the v1.10.3-v1.10.5 history. The CHANGELOG merged cleanly.
Versions stay 1.16.14. renderImportLog() keeps #18's guards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
@gitluis gitluis added the bug Something isn't working label Nov 3, 2026 — with Claude
@gitluis gitluis added this to the Clarity stack (v1.12.0 → v1.18.1) milestone Nov 3, 2026 — with Claude
…) into fix-drawer-focus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBUZo6LRYpLthSp2PRi

# Conflicts:
#	js/views-settings.js
@gitluis gitluis changed the title v1.16.14: keep keyboard focus inside the edit drawer while it's open v1.16.14: Keep keyboard focus inside the edit drawer while it's open Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants