feat(data-grid): add cell/row accessibility prop callbacks - #1196
Open
hovoaep wants to merge 1 commit into
Open
Conversation
Add getCellAccessibilityProps and getRowAccessibilityProps to spread custom HTML attributes onto the hidden a11y <td>/<tr> elements, threaded through DataGridDnd, ScrollingDataGrid, DataGridSearch, and DataEditor. Caller-supplied props are placed after built-ins so they can override defaults like aria-readonly/aria-rowindex. Also fix custom cell a11y string: CustomRenderer.getAccessibilityString is used when defined, falling back to cell.copyData otherwise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The hidden accessibility
<table>tree rendered alongside the canvas (used by screen readers) offered no way to customize its markup per cell/row, and had an unrelated correctness bug for custom cells:<td>/<tr>elements in the accessibility tree only ever got the grid's built-in attributes (role,aria-selected,aria-readonly,aria-rowindex, etc.). There was no way for consumers to add supplementalaria-*attributes (e.g.aria-label,aria-describedby) to a specific cell or row.getRowDataspecial-casedGridCellKind.Customto always returncell.copyData, without ever asking the resolvedCustomRendererfor a proper accessible description — andCustomRendererdidn't even expose agetAccessibilityStringfield to ask for.Repro
CustomRendererwith agetAccessibilityStringimplementation and render aCustomcell → the accessibility<td>text content is alwayscopyData, the renderer's string is silently ignored.aria-labelto an individual cell or row → no prop exists for it;DataGridPropsonly exposes grid-wide callbacks (getCellContent,getRowThemeOverride, etc.), none scoped to a11y markup.Fix
getCellAccessibilityProps?: (cell: Item) => React.TdHTMLAttributes<HTMLTableCellElement>andgetRowAccessibilityProps?: (row: number) => React.HTMLAttributes<HTMLTableRowElement>toDataGridProps, threaded through the full render chain:DataGridDnd→ScrollingDataGrid→DataGridSearch→DataEditor.role,aria-selected,aria-readonly,aria-rowindex) so consumers can override defaults, while props required for grid interactivity (id,onClick,onFocusCapture,ref,tabIndex) stay locked in after the spread.getAccessibilityString?: (cell: T) => stringto theCustomRendererinterface.getRowDatanow resolves the renderer first and uses itsgetAccessibilityStringwhen defined, falling back tocell.copyDataotherwise.Test
New tests in
test/data-grid.test.tsx:getCellAccessibilityPropsadds custom attributes and overrides a built-in (aria-readonly) on the a11y<td>.getRowAccessibilityPropsadds custom attributes and overrides a built-in (aria-rowindex) on the a11y<tr>.getAccessibilityStringwhen provided.copyDatawhen the renderer has nogetAccessibilityString.