feat(a11y): give the context menu a keyboard, and the app a voice
The context menu was the only route to Play, Add to Queue, Play Next, Add to Playlist, Favourite and Track Details, and it opened on right-click alone: the panel had no role=menu, so its six menuitems were orphaned, nothing moved focus into it, and nothing handled arrows or Escape (a11y.3). Phase 1 deferred this deliberately so it would land with the dialogs, as one focus-management implementation. MenuKeyboard is that model. It is standalone rather than part of ContextMenuController because playlist-view renders a menu without the controller, and the only thing worse than a menu with no keyboard model is two menus with two of them. Shift+F10 and the ContextMenu key open it from a focused row, anchored to that row, and focus returns there. Three lists had no focused row to open it from, so they gained a roving tab stop (utils/roving-rows.ts, written once rather than three times). track-list keeps its own: it predates this, carries selection semantics the other three do not have, and is pinned by its own tests. Also the ARIA tail this is one story with: aria-sort on the column headers (role=columnheader arrived in Phase 1 without it), listbox and option on the four selectable grids — aria-selected on role=button is invalid and was being dropped, so the state the whole ctrl/shift interaction exists to produce was invisible — and live regions on the four async surfaces that changed in silence. Two things a reproduction taught that reading could not: the wa-dropdown-items have not set their role when the host's updateComplete resolves, so querying by role then finds nothing and the menu opens without taking focus; and focus() on a popup that has not positioned itself is a silent no-op.
This commit is contained in:
@@ -46,7 +46,10 @@ import {
|
||||
emitDragActive,
|
||||
} from '@utils/drag-controller';
|
||||
import type { DragPayload } from '@utils/drag-controller';
|
||||
import { ContextMenuController } from '@utils/context-menu-controller.js';
|
||||
import {
|
||||
ContextMenuController,
|
||||
isContextMenuKey,
|
||||
} from '@utils/context-menu-controller.js';
|
||||
import type { ContextMenuHost } from '@utils/context-menu-controller.js';
|
||||
import { FavoritesController } from '@store/controllers/favorites-controller';
|
||||
import { artistLink, exploreLinkStyles } from '../../utils/explore-link';
|
||||
@@ -1050,6 +1053,26 @@ export class CoverGrid
|
||||
private onGridAlbumKeydown = (
|
||||
e: KeyboardEvent,
|
||||
) => {
|
||||
if (isContextMenuKey(e)) {
|
||||
const target = this.resolveAlbumFromEvent(e);
|
||||
const card =
|
||||
e.composedPath().find(
|
||||
(el): el is HTMLElement =>
|
||||
el instanceof HTMLElement &&
|
||||
el.classList.contains('album-card'),
|
||||
);
|
||||
|
||||
if (!target || !card) return;
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.contextMenuAlbumId = target.album.ID;
|
||||
this.contextMenuTarget = { kind: 'album' };
|
||||
this.ctxMenu.openFrom(card);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.key !== 'Enter' && e.key !== ' ') return;
|
||||
|
||||
const hit = this.resolveAlbumFromEvent(e);
|
||||
@@ -1679,7 +1702,8 @@ export class CoverGrid
|
||||
class=${classes}
|
||||
tabindex=${this.roving.tabIndexFor(index)}
|
||||
@focus=${() => this.roving.noteFocus(index)}
|
||||
role="button"
|
||||
role="option"
|
||||
aria-selected=${this.selectedAlbums.has(album.ID)}
|
||||
data-index=${index}
|
||||
aria-label="${album.Name} by ${album.ArtistName}"
|
||||
draggable="true"
|
||||
@@ -1780,6 +1804,9 @@ export class CoverGrid
|
||||
return html`
|
||||
<lit-virtualizer
|
||||
id="grid-single"
|
||||
role="listbox"
|
||||
aria-label="Albums"
|
||||
aria-multiselectable="true"
|
||||
.items=${this.buildGridEntries()}
|
||||
.renderItem=${this.renderGridEntry}
|
||||
.keyFunction=${(entry: GridEntry) => entry.album.ID}
|
||||
@@ -1877,7 +1904,7 @@ export class CoverGrid
|
||||
>
|
||||
${ctxMenu.contextMenuOpen
|
||||
? html`
|
||||
<div class="context-menu-panel">
|
||||
<div class="context-menu-panel" role="menu" aria-label="Album actions">
|
||||
<wa-dropdown-item
|
||||
@click=${() =>
|
||||
this.onContextMenuAction(
|
||||
|
||||
Reference in New Issue
Block a user