-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(td-headers-attr): ignore table elements with their role changed (#…
…3687) * fix(td-headers-attr): ignore table elements with their role changed * add aria-hidden test * revert hidden cell code
- Loading branch information
1 parent
0fe4a00
commit 902d07c
Showing
6 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getRole } from '../commons/aria'; | ||
|
||
export default function tableOrGridRoleMatches(_, vNode) { | ||
const role = getRole(vNode); | ||
return ['treegrid', 'grid', 'table'].includes(role); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/integration/rules/td-headers-attr/td-headers-attr.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<table id="pass1"> | ||
<th>Hello</th> | ||
<td>World</td> | ||
</table> | ||
|
||
<table id="pass2" role="grid"> | ||
<th id="p2h">Hello</th> | ||
<td headers="p2h">World</td> | ||
</table> | ||
|
||
<table id="pass3" role="treegrid"> | ||
<th id="p3h1">Hello</th> | ||
<th id="p3h2">Hello</th> | ||
<td headers="p3h1 p3h2">World</td> | ||
</table> | ||
|
||
<table id="fail1"> | ||
<th id="f1h1">Hello</th> | ||
<td headers="f1h1 non-existing">World</td> | ||
</table> | ||
|
||
<table id="fail2" role="table"> | ||
<td id="self" headers="self">World</td> | ||
</table> | ||
|
||
<table id="fail3" role="none" tabindex="0"> | ||
<td id="self" headers="self">World</td> | ||
</table> | ||
|
||
<table id="inapplicable1" role="none"> | ||
<td id="self" headers="self">World</td> | ||
</table> | ||
|
||
<table id="inapplicable2" role="presentation"> | ||
<td id="self" headers="self">World</td> | ||
</table> | ||
|
||
<table id="inapplicable3" role="region"> | ||
<td id="self" headers="self">World</td> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"description": "td-headers-attr test", | ||
"rule": "td-headers-attr", | ||
"violations": [["#fail1"], ["#fail2"], ["#fail3"]], | ||
"passes": [["#pass1"], ["#pass2"], ["#pass3"]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
describe('table-or-grid-role-matches', () => { | ||
const { queryFixture } = axe.testUtils; | ||
const rule = axe.utils.getRule('td-headers-attr'); | ||
|
||
it(`returns true for tables without role`, () => { | ||
const vNode = queryFixture(`<table id="target"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isTrue(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
|
||
['table', 'grid', 'treegrid'].forEach(role => { | ||
it(`returns true for tables with role=${role}`, () => { | ||
const vNode = queryFixture(`<table id="target" role="${role}"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isTrue(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
}); | ||
|
||
['region', 'presentation', 'none'].forEach(role => { | ||
it(`returns false for tables with role=${role}`, () => { | ||
const vNode = queryFixture(`<table id="target" role="${role}"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isFalse(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
}); | ||
|
||
it(`returns true for tables with an invalid role`, () => { | ||
const vNode = queryFixture(`<table id="target" role="invalid-aria-role"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isTrue(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
|
||
it(`returns true for focusable tables with role=none`, () => { | ||
const vNode = queryFixture(`<table id="target" role="none" tabindex="0"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isTrue(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
|
||
it(`returns true for tables with role=none but with a global ARIA attribute`, () => { | ||
const vNode = | ||
queryFixture(`<table id="target" role="none" aria-live="assertive"> | ||
<th id="h">foo</th> <td headers="h">bar</td> | ||
</table>`); | ||
assert.isTrue(rule.matches(vNode.actualNode, vNode)); | ||
}); | ||
}); |