Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grid roles for accessbility #1624

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ describe('Grid', () => {
});
});

describe('styles, classNames, and ids', () => {
describe('styles, classNames, ids, and roles', () => {
it('should use the expected global CSS classNames', () => {
const rendered = findDOMNode(render(getMarkup()));
expect(rendered.className).toEqual('ReactVirtualized__Grid');
Expand Down Expand Up @@ -1132,6 +1132,12 @@ describe('Grid', () => {
.style.backgroundColor,
).toEqual('red');
});

it('should have the gridcell role', () => {
const containerStyle = {backgroundColor: 'red'};
const rendered = findDOMNode(render(getMarkup({containerStyle})));
expect(rendered.querySelectorAll('[role="gridcell"]').length).toEqual(20);
});
});

describe('onScroll', () => {
Expand Down
2 changes: 1 addition & 1 deletion source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class Grid extends React.PureComponent<Props, State> {
autoHeight: false,
autoWidth: false,
cellRangeRenderer: defaultCellRangeRenderer,
containerRole: 'rowgroup',
containerRole: 'row',
containerStyle: {},
estimatedColumnSize: 100,
estimatedRowSize: 30,
Expand Down
5 changes: 5 additions & 0 deletions source/Grid/defaultCellRangeRenderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @flow */

import type {CellRangeRendererParams} from './types';
import React from 'react';

/**
* Default implementation of cellRangeRenderer used by Grid.
Expand Down Expand Up @@ -138,6 +139,10 @@ export default function defaultCellRangeRenderer({
warnAboutMissingStyle(parent, renderedCell);
}

if (!renderedCell.props.role) {
renderedCell = React.cloneElement(renderedCell, {role: 'gridcell'});
}

renderedCells.push(renderedCell);
}
}
Expand Down