Eslint-plugin-jsx-a11y: Add 'table-has-role' rule to avoid interpreting tabular data as a layout by accident

Created on 28 Sep 2019  路  2Comments  路  Source: jsx-eslint/eslint-plugin-jsx-a11y

As Sara Soueidan has recently pointed out on Twitter, <table> elements may be interpreted as layout containers by mistake unless role="table" is specified. More details are available in the presentation of Paul Duncan.

The implementation could be similar to the html-has-lang rule.

help wanted new-rule

Most helpful comment

the crux of the issue is that if someone is building a table without proper column or row headings, or if the table has no accessible name, browsers will drop the semantics because there's no sensible structure to the content.

rather than a rule to auto-add a role=table (which would cause more issues than help) a rule should be written to warn authors that if there is no name to the table (caption, aria-label, or aria-labelledby) or table col/row headers (th elements) that they have created a layout table and should either add the appropriate elements necessary to make it a useful data table, or they should consider using different markup to layout their information.

Along with Adrian's post, also see this one by Steve Faulkner.

Edit:
The point of where injecting ARIA roles would be necessary would be if people were overwriting the CSS display values of the table and its cells, as these can be used by browsers as further pointers of whether the table is layout/actually tabular data. But in such an instance, just a single role=table to the container would not be enough. Again, more information by Adrian Roselli.

All 2 comments

In addition, an exception may be added for cases when table headers or captions are available, according to the tweet of Adrian Roselli.

the crux of the issue is that if someone is building a table without proper column or row headings, or if the table has no accessible name, browsers will drop the semantics because there's no sensible structure to the content.

rather than a rule to auto-add a role=table (which would cause more issues than help) a rule should be written to warn authors that if there is no name to the table (caption, aria-label, or aria-labelledby) or table col/row headers (th elements) that they have created a layout table and should either add the appropriate elements necessary to make it a useful data table, or they should consider using different markup to layout their information.

Along with Adrian's post, also see this one by Steve Faulkner.

Edit:
The point of where injecting ARIA roles would be necessary would be if people were overwriting the CSS display values of the table and its cells, as these can be used by browsers as further pointers of whether the table is layout/actually tabular data. But in such an instance, just a single role=table to the container would not be enough. Again, more information by Adrian Roselli.

Was this page helpful?
0 / 5 - 0 ratings