Skip to content

Commit

Permalink
accessibility fixes + live announce area added to handle announcement…
Browse files Browse the repository at this point in the history
… of sorting columns and other filtering updates in the future
  • Loading branch information
gregnb committed Dec 29, 2017
1 parent 0debb9b commit 8dba3f7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ node_js:
- "node"

script:
- npm run -s build
- npm run -s lint
- npm run -s test

after_success:
- npm run coverage
- npm run -s coverage
- npm run -s build
27 changes: 25 additions & 2 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ const defaultTableStyles = {
display: "block",
overflowX: "auto",
},
caption: {
position: "absolute",
left: "-1000px",
},
liveAnnounce: {
border: "0",
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: "0",
position: "absolute",
width: "1px",
},
};

class MUIDataTable extends React.Component {
Expand Down Expand Up @@ -47,6 +61,7 @@ class MUIDataTable extends React.Component {

state = {
open: false,
announceText: null,
data: [],
displayData: [],
page: 0,
Expand Down Expand Up @@ -211,8 +226,12 @@ class MUIDataTable extends React.Component {
}
}

const orderLabel = columns[index].sort === "asc" ? "ascending" : "descending";
const announceText = `Table now sorted by ${columns[index].name} : ${orderLabel}`;

return {
columns: columns,
announceText: announceText,
displayData: this.sortTable(displayData, index, order),
};
});
Expand Down Expand Up @@ -299,7 +318,7 @@ class MUIDataTable extends React.Component {

render() {
const { className, classes, title } = this.props;
const { data, displayData, columns, page, filterData, filterList, searchText } = this.state;
const { announceText, data, displayData, columns, page, filterData, filterList, searchText } = this.state;

const rowsPerPage = this.state.rowsPerPage ? this.state.rowsPerPage : this.options.rowsPerPage;

Expand All @@ -324,7 +343,8 @@ class MUIDataTable extends React.Component {
toggleViewColumn={this.toggleViewColumn}
/>
<MUIDataTableFilterList options={this.options} filterList={filterList} filterUpdate={this.filterUpdate} />
<Table ref={el => (this.tableRef = el)}>
<Table ref={el => (this.tableRef = el)} tabIndex={"0"} role={"grid"} aria-readonly={"true"}>
<caption className={tableStyles.caption}>{title}</caption>
<MUIDataTableHead columns={columns} toggleSort={this.toggleSortColumn} options={this.options} />
<MUIDataTableBody
data={this.state.displayData}
Expand All @@ -348,6 +368,9 @@ class MUIDataTable extends React.Component {
false
)}
</Table>
<div className={tableStyles.liveAnnounce} aria-live={"polite"} ref={el => (this.announceRef = el)}>
{announceText}
</div>
</Paper>
)}
</DataStyles>
Expand Down
1 change: 0 additions & 1 deletion src/MUIDataTableHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class MUIDataTableHead extends React.Component {
key={index}
index={index}
classes={cellStyles}
sortAria={activeColumn === index ? column.sort : null}
sortDirection={column.sort}
toggleSort={this.handleToggleColumn}
options={options}>
Expand Down
13 changes: 7 additions & 6 deletions src/MUIDataTableHeadCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class MUIDataTableHeadCell extends React.Component {
options: PropTypes.object.isRequired,
/** Current sort direction */
sortDirection: PropTypes.string,
/** Current aria-sort direction */
sortAria: PropTypes.string,
/** Callback to trigger column sort */
toggleSort: PropTypes.func.isRequired,
};
Expand All @@ -24,18 +22,21 @@ class MUIDataTableHeadCell extends React.Component {
};

render() {
const { children, classes, index, options, sortDirection, sortAria } = this.props;
const { children, classes, index, options, sortDirection } = this.props;

let sortName = "descending";
if (sortDirection === "desc" || sortDirection === null) sortName = "ascending";

return (
<TableCell className={classes.root} sortDirection={sortAria}>
<TableCell className={classes.root} scope={"col"} sortDirection={sortDirection}>
{options.sort ? (
<Tooltip
title="Sort"
placement={"bottom-end"}
className={classes.tooltip}
enterDelay={300}
onClick={this.handleSortClick}>
<span>
<span role="button" tabIndex={0}>
<div className={classes.data}>{children}</div>
<div className={classes.sortAction}>
<span
Expand Down Expand Up @@ -66,7 +67,7 @@ class MUIDataTableHeadCell extends React.Component {
</span>
</Tooltip>
) : (
children
<span tabIndex={0}>{children}</span>
)}
</TableCell>
);
Expand Down
10 changes: 5 additions & 5 deletions src/MUIDataTablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const defaultPaginationStyles = {
"@media screen and (max-width: 400px)": {
toolbar: {
"& span:nth-child(2)": {
display: "none"
}
display: "none",
},
},
selectRoot: {
marginRight: "8px"
}
marginRight: "8px",
},
},
};

Expand Down Expand Up @@ -61,7 +61,7 @@ class MUIDataTablePagination extends React.Component {
classes={{
caption: paginationStyles.caption,
toolbar: paginationStyles.toolbar,
selectRoot: paginationStyles.selectRoot
selectRoot: paginationStyles.selectRoot,
}}
count={count}
rowsPerPage={rowsPerPage}
Expand Down
4 changes: 2 additions & 2 deletions src/MUIDataTableToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ class MUIDataTableToolbar extends React.Component {
name="MUIDataTableToolbar"
styles={getStyle(options, "table.toolbar")}>
{toolbarStyles => (
<Toolbar className={toolbarStyles.root}>
<Toolbar className={toolbarStyles.root} role={"toolbar"} aria-label={"Table Toolbar"}>
<div className={toolbarStyles.left}>
{showSearch === true ? (
<MUIDataTableSearch onSearch={searchTextUpdate} onHide={this.hideSearch} options={options} />
) : (
<div className={toolbarStyles.titleRoot}>
<div className={toolbarStyles.titleRoot} aria-hidden={"true"}>
<Typography type="title" className={toolbarStyles.titleText}>
{title}
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion src/MUIDataTableViewCol.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MUIDataTableViewCol extends React.Component {
const { classes, columns, options, viewColStyles } = this.props;

return (
<FormControl component={"fieldset"} className={viewColStyles.root}>
<FormControl component={"fieldset"} className={viewColStyles.root} aria-label="Show/Hide Table Columns">
<Typography type="caption" className={viewColStyles.title}>
Show Columns
</Typography>
Expand Down

0 comments on commit 8dba3f7

Please sign in to comment.