Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> and the
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 33 additions & 0 deletions tests/test_a11y_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> (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):
Expand Down
Loading