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:
@@ -0,0 +1,35 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { ESLint } from "eslint";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
// `local/sortable-a11y` (eslint.config.js): every sortable list speaks the user's language to a
|
||||
// screen reader, through ui/sortableA11y. Three of four lists had shipped dnd-kit's English
|
||||
// defaults. A rule that matches nothing looks exactly like a clean codebase, so this asserts it fires.
|
||||
const RULE = "local/sortable-a11y";
|
||||
const FRONTEND = fileURLToPath(new URL("../../", import.meta.url));
|
||||
|
||||
async function hits(source: string, filePath = "src/components/__probe.tsx"): Promise<number> {
|
||||
const eslint = new ESLint({ cwd: FRONTEND });
|
||||
const [result] = await eslint.lintText(source, { filePath });
|
||||
return (result?.messages ?? []).filter((m) => m.ruleId === RULE).length;
|
||||
}
|
||||
|
||||
describe("a sortable list", () => {
|
||||
it("is refused without translated screen-reader text", async () => {
|
||||
expect(await hits(`export const A = () => <DndContext onDragEnd={() => {}} />;\n`)).toBe(1);
|
||||
expect(
|
||||
await hits(`import { useSortable } from "@dnd-kit/sortable";\nexport { useSortable };\n`),
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("is fine through ui/sortableA11y, which alone may wrap dnd-kit's hook", async () => {
|
||||
expect(await hits(`export const B = ({ a }) => <DndContext accessibility={a} />;\n`)).toBe(0);
|
||||
expect(
|
||||
await hits(
|
||||
`import { useSortable } from "@dnd-kit/sortable";\nexport { useSortable };\n`,
|
||||
"src/components/ui/sortableA11y.ts",
|
||||
),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user