Skip to content

Commit 5651ecc

Browse files
waabidWilcoFiers
authored andcommitted
fix(rule): Layout-table does not match presentation / none roles (#828)
* fix(layout-table): check for presentation, none roles and isfocusable for matches * fix(layout-table): tests for layout table matches for focusable and non-presentation/none tables
1 parent d280c5f commit 5651ecc

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

lib/rules/layout-table-matches.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
return !axe.commons.table.isDataTable(node);
1+
var role = (node.getAttribute('role') || '').toLowerCase();
2+
3+
return !((role === 'presentation' || role === 'none') &&
4+
!axe.commons.dom.isFocusable(node)) &&
5+
!axe.commons.table.isDataTable(node);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
describe('layout-table-matches', function () {
2+
'use strict';
3+
4+
var fixture = document.getElementById('fixture');
5+
var fixtureSetup = axe.testUtils.fixtureSetup;
6+
var rule;
7+
8+
beforeEach(function () {
9+
rule = axe._audit.rules.find(function (rule) {
10+
return rule.id === 'layout-table';
11+
});
12+
});
13+
14+
afterEach(function () {
15+
fixture.innerHTML = '';
16+
});
17+
18+
it('returns false for element that is not focusable and has presentation role', function () {
19+
fixtureSetup('<table role="presentation"></table>');
20+
var target = fixture.querySelector('table');
21+
22+
assert.isFalse(rule.matches(target));
23+
});
24+
25+
it('returns false for element that is not focusable and has none role', function () {
26+
fixtureSetup('<table role="none"></table>');
27+
var target = fixture.querySelector('table');
28+
29+
assert.isFalse(rule.matches(target));
30+
});
31+
32+
it('returns trie for element that is a table without presentation/none role', function () {
33+
fixtureSetup('<table></table>');
34+
var target = fixture.querySelector('table');
35+
36+
assert.isTrue(rule.matches(target));
37+
});
38+
39+
it('returns true for element that is focusable and has none role', function () {
40+
fixtureSetup('<table role="none" tabindex="0"></table>');
41+
var target = fixture.querySelector('table');
42+
43+
assert.isTrue(rule.matches(target));
44+
});
45+
46+
it('returns true for element that is focusable and has presentation role', function () {
47+
fixtureSetup('<table role="presentation" tabindex="0"></table>');
48+
var target = fixture.querySelector('table');
49+
50+
assert.isTrue(rule.matches(target));
51+
});
52+
});

0 commit comments

Comments
 (0)