Skip to content

Commit

Permalink
Fix grid roles for accessbility (#1624)
Browse files Browse the repository at this point in the history
* Fix grid roles for accessbility

* Add test for gridcell role
  • Loading branch information
asnewman authored May 17, 2021
1 parent d365098 commit abe0530
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit abe0530

Please sign in to comment.