Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
feat: Added role attributes to Table elements
Browse files Browse the repository at this point in the history
This is in preparation for responsive CSS changes
which will break table semantics as they'll change
the table elements' display values
  • Loading branch information
diondiondion committed Sep 18, 2019
1 parent 8b4ebf0 commit 9dbbead
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,58 @@ function Table({
<StyledTable
shadedHeader={shadedHeader}
rowMinHeight={rowMinHeight}
role="table"
{...otherProps}
>
<thead>
<tr>
{/* eslint-disable-next-line jsx-a11y/no-redundant-roles */}
<thead role="rowgroup">
<tr role="row">
{columns.map(column => {
const {name, width} = column;
return (
<th
hidden={hiddenColumns.includes(column.name)}
key={column.name}
hidden={hiddenColumns.includes(name)}
key={name}
scope="col"
style={
column.width
? {width: column.width}
: null
}
role="columnheader"
style={width ? {width} : null}
>
{headerRenderer(column)}
</th>
);
})}
</tr>
</thead>
<tbody>
{/* eslint-disable-next-line jsx-a11y/no-redundant-roles */}
<tbody role="rowgroup">
{data.map(item => (
<tr key={item.id}>
<tr key={item.id} role="row">
{columns.map(column => {
const elementToRender = column.isHeading
? 'th'
: 'td';
const isHidden = hiddenColumns.includes(
column.name
);
const {
allowLineBreaks,
cellRenderer,
isHeading,
name,
} = column;

const element = isHeading ? 'th' : 'td';
const isHidden = hiddenColumns.includes(name);
return (
<Box
key={column.name}
key={name}
hidden={isHidden}
as={elementToRender}
scope={column.isHeading ? 'row' : null}
as={element}
role={isHeading ? 'rowheader' : 'cell'}
scope={isHeading ? 'row' : null}
overflow={
column.allowLineBreaks
allowLineBreaks
? 'wrap'
: 'ellipsis'
}
>
{getCellContent(
item,
column.cellRenderer || column.name
cellRenderer || name
)}
</Box>
);
Expand Down

0 comments on commit 9dbbead

Please sign in to comment.