Skip to content

Commit 5548b89

Browse files
author
Michael Jordan
authored
fix(#4382): [Accessibility] TableView: Screen Readers do not work in Firefox (#6465)
[Accessibility] TableView: Screen Readers in Firefox
1 parent 9a6869b commit 5548b89

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/@react-spectrum/table/src/TableViewBase.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ function TableViewBase<T extends object>(props: TableBaseProps<T>, ref: DOMRef<H
291291
<TableRowGroup
292292
key={reusableView.key}
293293
layoutInfo={reusableView.layoutInfo}
294-
parent={parent?.layoutInfo}>
294+
parent={parent?.layoutInfo}
295+
// Override the default role="rowgroup" with role="presentation",
296+
// in favor or adding role="rowgroup" to the ScrollView with
297+
// ref={bodyRef} in the TableVirtualizer below.
298+
role="presentation">
295299
{renderChildren(children)}
296300
</TableRowGroup>
297301
);
@@ -332,7 +336,7 @@ function TableViewBase<T extends object>(props: TableBaseProps<T>, ref: DOMRef<H
332336
</TableHeaderRow>
333337
);
334338
}
335-
339+
336340
return (
337341
<TableCellWrapper
338342
key={reusableView.key}
@@ -448,7 +452,7 @@ function TableViewBase<T extends object>(props: TableBaseProps<T>, ref: DOMRef<H
448452
);
449453

450454
return (
451-
<TableContext.Provider
455+
<TableContext.Provider
452456
value={{
453457
state,
454458
dragState,
@@ -491,7 +495,7 @@ function TableViewBase<T extends object>(props: TableBaseProps<T>, ref: DOMRef<H
491495
styleProps.className
492496
)
493497
}
494-
// This should be `tableLayout` rather than `layout` so it doesn't
498+
// This should be `tableLayout` rather than `layout` so it doesn't
495499
// change objects and invalidate virtualizer.
496500
layout={tableLayout}
497501
collection={state.collection}
@@ -617,7 +621,6 @@ function TableVirtualizer(props) {
617621
{state.visibleViews[0]}
618622
</div>
619623
<ScrollView
620-
role="presentation"
621624
className={
622625
classNames(
623626
styles,
@@ -635,6 +638,11 @@ function TableVirtualizer(props) {
635638
)
636639
)
637640
}
641+
// Firefox and Chrome make generic elements using CSS overflow 'scroll' or 'auto' tabbable,
642+
// including them within the accessibility tree, which breaks the table structure in Firefox.
643+
// Using tabIndex={-1} prevents the ScrollView from being tabbable, and using role="rowgroup"
644+
// here and role="presentation" on the table body content fixes the table structure.
645+
role="rowgroup"
638646
tabIndex={isVirtualDragging ? null : -1}
639647
style={{
640648
flex: 1,

packages/@react-spectrum/table/test/Table.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,7 @@ export let tableTests = () => {
41904190
);
41914191

41924192
let body = tree.getAllByRole('rowgroup')[1];
4193-
let scrollView = body.parentNode.parentNode;
4193+
let scrollView = body;
41944194

41954195
let rows = within(body).getAllByRole('row');
41964196
expect(rows).toHaveLength(34); // each row is 41px tall. table is 1000px tall. 25 rows fit. + 1/3 overscan

0 commit comments

Comments
 (0)