Automations and webhooks for the AT Protocol airglow.run

fix(automation-form): keep focus in the form after removing a condition's branches #136

Closed tyb.there-hugo.dev
Closed opened by tyb.there-hugo.dev

Removing a condition step's branches drops keyboard focus to <body>. removeBranches in app/islands/AutomationForm.tsx sets the steps and clears the error, but never moves focus, unlike removeStep, which calls focusAfterRender(addFocusKey(slot)). The button that was pressed ("Remove else branch" or "Remove branches") is gone after the re-render, replaced by "+ Add else branch" or "+ Add then/else branches", so the focus it held falls to the page. This happens with or without the confirmation dialog (#115): the dialog hands focus back to the button, and the removal then unmounts it; with empty branches there is no dialog and the drop is immediate.

How I know: reading removeBranches (no focus call) and the condition body's markup around "Remove else branch", while wiring #115's dialog into it. The #115 test "asks before removing a branch with steps in it" shows the button is gone after the second press.

Where to start: give the "+ Add else branch" and "+ Add then/else branches" buttons a data-focus-key (as stepFocusKey does for the step tools) and call focusAfterRender with it at the end of removeBranches; add a test that checks document.activeElement after each removal.

Found by the loop while working on #115, rkey 115, branch loop/115, merged onto main as 6b04f989cb26.

Sign up or Sign in to add to the discussion.