fix(a11y): every sortable list speaks the user's language to a screen reader
dnd-kit's screen-reader text is hard-coded English and names an item by its id ("Draggable item
10357 was dropped", a role of "sortable"). Only the YouTube playlist replaced it; the Plex playlist,
the saved-views list and the side-panel groups read it out under a Hungarian UI — found while
checking the Plex playlist's keyboard reorder on localdev.
`ui/sortableA11y` is now the one place: `useSortableA11y` gives a DndContext its instructions and
announcements (HU/EN, `common.dnd.*`), `useSortableItem` announces the role. The YouTube playlist's
own announcements move onto it, which also fixes them: its lists reorder on drop, so reading the
dragged row's own index said "moved to position 1" at every step and "dropped at position 1"
wherever the row went. The place announced is now the slot the row would land in.
A `local/sortable-a11y` lint rule (with its contract test) refuses a DndContext without
`accessibility` and a direct `useSortable`.
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
} from "@dnd-kit/sortable";
|
||||
import type { PanelLayout } from "../../lib/panelLayout";
|
||||
import PanelGroup from "./PanelGroup";
|
||||
import { useSortableA11y } from "./sortableA11y";
|
||||
|
||||
export type PanelItem = {
|
||||
id: string;
|
||||
@@ -70,6 +71,11 @@ export default function PanelGroups({
|
||||
function toggleHidden(id: string) {
|
||||
setLayout({ ...layout, hidden: { ...layout.hidden, [id]: !layout.hidden[id] } });
|
||||
}
|
||||
const dndA11y = useSortableA11y((id) => ({
|
||||
title: byId.get(String(id))?.title ?? "",
|
||||
pos: renderedIds.indexOf(String(id)) + 1,
|
||||
total: renderedIds.length,
|
||||
}));
|
||||
function onDragEnd(e: DragEndEvent) {
|
||||
const { active, over } = e;
|
||||
if (!over || active.id === over.id) return;
|
||||
@@ -80,7 +86,12 @@ export default function PanelGroups({
|
||||
}
|
||||
|
||||
return (
|
||||
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={onDragEnd}>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={onDragEnd}
|
||||
accessibility={dndA11y}
|
||||
>
|
||||
<SortableContext items={renderedIds} strategy={verticalListSortingStrategy}>
|
||||
<div className="space-y-3">
|
||||
{renderedIds.map((id) => (
|
||||
|
||||
Reference in New Issue
Block a user