Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(implicit-role): return gridcell for td child of grid or treegrid #2501

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/commons/standards/implicit-html-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import isRowHeader from '../table/is-row-header';
import sanitize from '../text/sanitize';
import isFocusable from '../dom/is-focusable';
import { closest } from '../../core/utils';
import getExplicitRole from '../aria/get-explicit-role';

const sectioningElementSelector =
getElementsByContentType('sectioning')
Expand Down Expand Up @@ -156,7 +157,12 @@ const implicitHtmlRoles = {
summary: 'button',
table: 'table',
tbody: 'rowgroup',
td: 'cell',
td: vNode => {
const table = closest(vNode, 'table');
const role = getExplicitRole(table);

return ['grid', 'treegrid'].includes(role) ? 'gridcell' : 'cell';
},
textarea: 'textbox',
tfoot: 'rowgroup',
th: vNode => {
Expand Down
14 changes: 14 additions & 0 deletions test/commons/aria/implicit-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ describe('aria.implicitRole', function() {
assert.equal(implicitRole(node), 'cell');
});

it('should return gridcell for "td" with grid parent', function() {
fixture.innerHTML = '<table role="grid"><td id="target"></td></table>';
var node = fixture.querySelector('#target');
flatTreeSetup(fixture);
assert.equal(implicitRole(node), 'gridcell');
});

it('should return gridcell for "td" with treegrid parent', function() {
fixture.innerHTML = '<table role="treegrid"><td id="target"></td></table>';
var node = fixture.querySelector('#target');
flatTreeSetup(fixture);
assert.equal(implicitRole(node), 'gridcell');
});

it('should return rowheader for "th[scope=row]"', function() {
fixture.innerHTML = '<table><th id="target" scope="row"></th></table>';
var node = fixture.querySelector('#target');
Expand Down
12 changes: 12 additions & 0 deletions test/integration/rules/aria-allowed-attr/passes.html
Original file line number Diff line number Diff line change
Expand Up @@ -1893,3 +1893,15 @@

<span role="radio" id="pass75" aria-checked="false">I am RED!</span>
<span role="radio" id="pass76" aria-checked="true">I am GREEN!</span>

<table role="grid">
<td aria-selected="false" tabindex="0" id="pass77">
target 1
</td>
</table>

<table role="treegrid">
<td aria-selected="false" tabindex="0" id="pass78">
target 1
</td>
</table>
4 changes: 3 additions & 1 deletion test/integration/rules/aria-allowed-attr/passes.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
["#pass73"],
["#pass74"],
["#pass75"],
["#pass76"]
["#pass76"],
["#pass77"],
["#pass78"]
]
}