fix(web): focus the first field on every auth card #484
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-486-auth-card-autofocus"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Every single-purpose auth card in bunyip-web rendered with focus on the document body, so reaching the field meant tabbing through the whole site header and nav first (the nav precedes main in DOM order). On /login/2fa that is the worst case: the code input is the only thing on the card, the user already has a code in hand, and the data-otp-autosubmit path means that with focus in place the entire screen becomes "type six digits".
Uses the native autofocus attribute rather than a JS focus call, so it works with JavaScript disabled, needs no ordering coordination with htmx, and the browser resolves "only the first one wins" itself.
The shared helper
field_with_valuetakes anautofocus: bool(its one call site, the register email, passes true) andfieldkeeps its arity by delegating with false. A newfield_autofocuscovers the call sites that usedfield. The login email and the 2FA code input are written inline and take the attribute directly.Applied to the first editable field, and only the first, of the seven cards that are a single form: /login (email), /register (email), /magic-link (email), /password-reset (email), /password-reset/confirm (new password), /login/2fa (code), /invite/accept (password). The link-only confirmation and result cards keep default document focus, and no dashboard or admin form gains the attribute: those are one section of a longer page, where stealing focus would scroll past the rest.
Adds
autofocus_tests, which renders all seven cards (clean and error re-render) and asserts exactly one autofocus per card on the expected input, plus zero on the two link-only confirmation cards.#BUNYIP-486