In our web application we use multiple "responsive" HTML tables — they can be scrolled horizontally if their content gets too wide (CSS rules: width:100%; overflow-x: auto;
). This allows to show all the necessary information in the table without breaking the layout and making the whole page horizontally scrollable.
In our case, this is relevant only for small screens (on resized browser windows or if the user increases the font-size by over 200%) as our tables aren't that big (note that the application is internal and will only be used on laptop/desktop screens).
Unfortunately, making content horizontally scrollable with overflow-x
isn't accessible for keyboard users — the only way to scroll through the content would be with the mouse; using the arrow keys only works if the whole page is scrollable or if the element has focus.
So, in order to make our tables controllable with the keyboard, I was thinking about adding tabindex="0"
to them and thus allowing to use the arrow keys. This seems to work fine if the table is scrollable, but also means that a non-interactive element (the table on a big screen) can receive focus, which might result in confusion in keyboard users.
Here is a little example (made with Bootstrap to spare writing some CSS). Resize the browser window to test it:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<h1>Some heading</h1>
<a href="#">First link (for tabbing purposes)</a>
<table class="table table-responsive" tabindex="0">
<thead>
<tr>
<th scole="col">Column 1</th>
<th scole="col">Column 2</th>
<th scole="col">Column 3</th>
<th scole="col">Column 4</th>
<th scole="col">Column 5</th>
<th scole="col">Column 6</th>
<th scole="col">Column 7</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
</tr>
</tbody>
</table>
<a href="#">Second link (for tabbing purposes)</a>
Do you think that this solution might be a problem for accessibility and does anyone have a better idea how I can solve it? Thanks