Skip to content
Open
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
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h1 class="sr-only" id="setup-title" data-i18n="setup.view.title">Curatarr setup
</div>

<!-- PROACTIVE MESSAGES PANEL -->
<div id="msg-panel">
<div id="msg-panel" role="region" aria-label="Notifications" data-i18n-aria-label="top.notifications">
<div class="mp-header">
<span data-i18n="top.notifications">Notifications</span>
<button class="btn-plain" data-action="toggleMsgPanel" aria-label="Close notifications" data-i18n-aria-label="bell.close">×</button>
Expand Down
12 changes: 11 additions & 1 deletion frontend/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body>
}

// 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() {
Expand All @@ -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();
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/test_a11y_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body>
(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'<div id="msg-panel" role="region" aria-label="[^"]+" data-i18n-aria-label="top.notifications"', markup()) is not None)
src = _read("notifications.js")
fns = "\n".join(_fn(src, n) for n in ("_focusPanel", "toggleMsgPanel", "skipMessage"))
out = _node("""
let focused = null, open = false, ids = {};
const mk = (name, conn) => ({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):
Expand Down