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:
@@ -122,8 +122,39 @@ const literalA11yText = {
|
||||
};
|
||||
},
|
||||
};
|
||||
// dnd-kit's screen-reader text is hard-coded English and names an item by its id; three of the four
|
||||
// sortable lists shipped it that way under a Hungarian UI. `ui/sortableA11y` is the one place that
|
||||
// replaces it, and this is what keeps the next sortable list from skipping it.
|
||||
const sortableA11y = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
messages: {
|
||||
context: "A <DndContext> needs `accessibility={useSortableA11y(...)}` (ui/sortableA11y).",
|
||||
item: "Use `useSortableItem` from ui/sortableA11y: it announces the role in the user's language.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
const own = context.filename.split("\\").join("/").endsWith("components/ui/sortableA11y.ts");
|
||||
return {
|
||||
JSXOpeningElement(node) {
|
||||
if (node.name.type !== "JSXIdentifier" || node.name.name !== "DndContext") return;
|
||||
if (
|
||||
!node.attributes.some((a) => a.type === "JSXAttribute" && a.name.name === "accessibility")
|
||||
)
|
||||
context.report({ node, messageId: "context" });
|
||||
},
|
||||
ImportDeclaration(node) {
|
||||
if (own || node.source.value !== "@dnd-kit/sortable") return;
|
||||
for (const sp of node.specifiers)
|
||||
if (sp.type === "ImportSpecifier" && sp.imported.name === "useSortable")
|
||||
context.report({ node: sp, messageId: "item" });
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
const localRules = {
|
||||
rules: {
|
||||
"sortable-a11y": sortableA11y,
|
||||
"jsx-comment-text": jsxCommentText,
|
||||
"focus-safe-disabled": focusSafeDisabled,
|
||||
"literal-a11y-text": literalA11yText,
|
||||
@@ -158,6 +189,7 @@ export default tseslint.config(
|
||||
"local/jsx-comment-text": "error",
|
||||
"local/focus-safe-disabled": "error",
|
||||
"local/literal-a11y-text": "error",
|
||||
"local/sortable-a11y": "error",
|
||||
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
|
||||
// tsc already enforces these under strict + noUnusedLocals/Parameters — let it own them so a
|
||||
// finding is reported once, by one tool, and this config stays about hooks + refresh safety.
|
||||
|
||||
Reference in New Issue
Block a user