diff --git a/frontend/js/setup.js b/frontend/js/setup.js index c87dd52..1cb62fe 100644 --- a/frontend/js/setup.js +++ b/frontend/js/setup.js @@ -87,6 +87,7 @@ export function jellyfinConnectAgain() { state.setupData.jellyfin_ticket = ''; state.setupData.jellyfin_connected = null; renderSetupStep(state.setupStep); + document.getElementById('s-jellyfin-url')?.focus(); // the button that was pressed is gone } // A radio change redraws the whole step; focus would fall to and the @@ -181,6 +182,7 @@ export async function startPlexConnect(btn) { state.setupData._plex_code = r.code; state.setupData._plex_login = {id: r.login_id, nonce: r.nonce}; renderSetupStep(state.setupStep); + document.getElementById('plex-connect-btn')?.focus(); // the redraw replaced the pressed button const until = Date.now() + (r.expires_in || 900) * 1000; stopPlexConnect(); _plexPoll = setInterval(async () => { @@ -220,6 +222,7 @@ export function plexConnectAgain() { Object.assign(state.setupData, {plex_ticket: '', plex_servers: null, plex_server_id: '', plex_account: '', _plex_code: null, _plex_login: null}); renderSetupStep(state.setupStep); + document.getElementById('plex-connect-btn')?.focus(); // the link that was pressed is gone } export function pickPlexServer(el) { diff --git a/tests/test_a11y_nav.py b/tests/test_a11y_nav.py index c02c822..98c5c1a 100644 --- a/tests/test_a11y_nav.py +++ b/tests/test_a11y_nav.py @@ -413,6 +413,39 @@ def test_setup_nav_focuses_step_heading(): '.setup-heading[tabindex="-1"]:focus' in styles()) +# ── 6. the wizard's "connect again" actions keep keyboard focus ────────────── + +def test_setup_connect_redraws_keep_focus(): + """Starting a Plex sign-in, "Use another Plex account" and "Connect + another server" redraw the step, replacing the control that was just + pressed; focus fell to (WCAG 2.4.3). Each now focuses the control + that took its place.""" + setup = _read("setup.js") + cases = [("startPlexConnect", "plex-connect-btn"), ("plexConnectAgain", "plex-connect-btn"), + ("jellyfinConnectAgain", "s-jellyfin-url")] + for name, want in cases: + fn = _fn(setup, name) + # Fakes: a drawn step swaps in a fresh element; only that one can be focused. + out = _node(""" +const state = {setupStep: 0, setupData: {}}; +let focusedId = null, drawn = 0; +globalThis.document = {getElementById: id => ({focus() { focusedId = drawn ? id : null; }})}; +globalThis.window = {open: () => null}; +const renderSetupStep = () => { drawn++; }; +const stopPlexConnect = () => {}, btnBusy = () => {}, btnDone = () => {}, t = k => k, toast = () => {}; +const api = async () => ({code: 'C', auth_url: 'x', login_id: '1', nonce: 'n'}); +let _plexPoll = null; const setInterval = () => 0; +%s +(async () => { + await %s(%s); + console.log(JSON.stringify({drawn, focusedId})); +})(); +""" % (fn, name, "{}" if name == "startPlexConnect" else "")) if fn else {} + if out is not None: + check("%s redraws, then focuses #%s" % (name, want), + out.get("drawn") == 1 and out.get("focusedId") == want) + + if __name__ == "__main__": for name, fn in list(globals().items()): if name.startswith("test_") and callable(fn):