From 938b752ee97f3a694b55aae7c491be4a9bef8ca0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 02:15:20 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20notification=20panel?= =?UTF-8?q?=20takes=20focus=20when=20opened=20and=20after=20Skip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014GBDVC1k1qRH9wN8eno2UU --- frontend/index.html | 2 +- frontend/js/notifications.js | 12 ++++++++++- tests/test_a11y_nav.py | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index 6eea329c..da394f51 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -96,7 +96,7 @@

Curatarr setup -
+
Notifications diff --git a/frontend/js/notifications.js b/frontend/js/notifications.js index db3f1fa1..5ce49f73 100644 --- a/frontend/js/notifications.js +++ b/frontend/js/notifications.js @@ -158,6 +158,16 @@ export async function skipMessage(id, btn) { await api(`/api/messages/${encodeURIComponent(id)}/read`, 'POST') .catch(e => console.warn('[bell] skip (mark-read) failed', id, e)); await loadUnreadMessages(true); // panel still open: the next one is shown + if (!btn.isConnected) _focusPanel(); // the list was redrawn: Skip is gone, focus would fall to +} + +// Keyboard users: the panel precedes the bell in the DOM, so opening it left +// focus on the bell with the panel's buttons behind it. Land on the first +// action, or on the close button when the list is empty. +function _focusPanel() { + const p = document.getElementById('msg-panel'); + if (!p?.classList.contains('open')) return; + (p.querySelector('#msg-list button') || p.querySelector('.mp-header button'))?.focus(); } export function toggleMsgPanel() { @@ -168,7 +178,7 @@ export function toggleMsgPanel() { // Refresh on open so the list is never the boot-time snapshot — shadow // principles land in the background long after the page loaded. if (opening) { - loadUnreadMessages(true); + loadUnreadMessages(true).then(_focusPanel); _armPanelClose(); } } diff --git a/tests/test_a11y_nav.py b/tests/test_a11y_nav.py index 5336edd7..105f0f98 100644 --- a/tests/test_a11y_nav.py +++ b/tests/test_a11y_nav.py @@ -498,6 +498,47 @@ def test_setup_connect_redraws_keep_focus(): out.get("drawn") == 1 and out.get("focusedId") == want) +# ── 7. the bell panel takes focus when opened and keeps it after Skip ─────── + +def test_bell_panel_focus(): + """#msg-panel precedes #msg-bell in the DOM and nothing moved focus, so a + keyboard user who opened it stayed on the bell with the Respond/Skip + buttons behind them; Skip then redrew the list and focus fell to + (WCAG 2.4.3). The panel is a labelled region, opening focuses its first + action, and a redraw after Skip refocuses.""" + check("panel is a labelled region", + re.search(r'
({name, isConnected: conn, focus() { focused = name; }, setAttribute() {}, textContent: '', disabled: false}); +let listBtn = mk('respond', true), closeBtn = mk('close', true); +const panel = {classList: {contains: () => open, toggle() { open = !open; }}, + querySelector: s => s === '#msg-list button' ? listBtn : closeBtn}; +globalThis.document = {getElementById: id => id === 'msg-panel' ? panel : id === 'msg-bell' ? mk('bell', true) : null}; +const api = async () => ({}), encodeURIComponent = x => x, _armPanelClose = () => {}; +async function loadUnreadMessages() { return; } +%s +(async () => { + toggleMsgPanel(); await new Promise(r => setTimeout(r, 0)); + const afterOpen = focused; + listBtn = null; focused = null; // empty list: close button + await _focusPanel(); const empty = focused; + listBtn = mk('next', true); focused = null; + await skipMessage(1, mk('skip', false)); const gone = focused; // pressed button was redrawn away + focused = null; + await skipMessage(1, mk('skip', true)); const kept = focused; // still in the DOM: leave focus alone + console.log(JSON.stringify({afterOpen, empty, gone, kept})); +})(); +""" % fns) if fns.strip() else {} + if out is not None: + check("opening focuses the first action", out.get("afterOpen") == "respond") + check("empty panel focuses the close button", out.get("empty") == "close") + check("Skip redraw refocuses the panel", out.get("gone") == "next") + check("Skip leaves focus alone when its button survives", out.get("kept") is None) + + if __name__ == "__main__": for name, fn in list(globals().items()): if name.startswith("test_") and callable(fn):