atlassian / react-beautiful-dnd

Beautiful and accessible drag and drop for lists with React
https://react-beautiful-dnd.netlify.app
Other
33.16k stars 2.53k forks source link

a11y and i18n: Simpler API for customising/translating screen reader instructions #2330

Open diondiondion opened 2 years ago

diondiondion commented 2 years ago

Description

Customising the library's screen reader instructions is pretty complex and requires a detailed understanding of the library's API and inner workings (see screen reader guide). It also requires hooking into the onDrag[Start|Update|End] callbacks which can easily get messy, and requires re-implementing existing functionality (a hidden text container for the item descriptions).

It would be nice if it was possible to:

E.g., the DragDropContext component could have a a11yMessages prop which could be an object of functions that each return a specific screen reader message:

<DragDropContext
    a11yMessages={{
        itemDescription: () => 'Press space bar to start a drag. [...]',
        dragStart: ({startPosition}) => `You have lifted an item in position ${startPosition}.`,
        dragUpdateSuccess: ({startPosition, endPosition}) => `You have moved the item from position ${startPosition} to position ${endPosition}`,
        dragUpdateNoTarget: () => `You are currently not dragging over a droppable area`,
        // ...
    }}
/>

To make this even easier, the information passed to each message function could be tailored to what's needed for UI copy, e.g. the index could be passed as a position instead of a 0-based index.

sandroLT commented 1 month ago

+1 for this.