Skip to content

Commit

Permalink
fix(rule): Layout-table does not match presentation / none roles (#828)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
waabid authored and WilcoFiers committed Apr 11, 2018
1 parent d280c5f commit 5651ecc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/layout-table-matches.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
return !axe.commons.table.isDataTable(node);
var role = (node.getAttribute('role') || '').toLowerCase();

return !((role === 'presentation' || role === 'none') &&
!axe.commons.dom.isFocusable(node)) &&
!axe.commons.table.isDataTable(node);
52 changes: 52 additions & 0 deletions test/rule-matches/layout-table-matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
describe('layout-table-matches', function () {
'use strict';

var fixture = document.getElementById('fixture');
var fixtureSetup = axe.testUtils.fixtureSetup;
var rule;

beforeEach(function () {
rule = axe._audit.rules.find(function (rule) {
return rule.id === 'layout-table';
});
});

afterEach(function () {
fixture.innerHTML = '';
});

it('returns false for element that is not focusable and has presentation role', function () {
fixtureSetup('<table role="presentation"></table>');
var target = fixture.querySelector('table');

assert.isFalse(rule.matches(target));
});

it('returns false for element that is not focusable and has none role', function () {
fixtureSetup('<table role="none"></table>');
var target = fixture.querySelector('table');

assert.isFalse(rule.matches(target));
});

it('returns trie for element that is a table without presentation/none role', function () {
fixtureSetup('<table></table>');
var target = fixture.querySelector('table');

assert.isTrue(rule.matches(target));
});

it('returns true for element that is focusable and has none role', function () {
fixtureSetup('<table role="none" tabindex="0"></table>');
var target = fixture.querySelector('table');

assert.isTrue(rule.matches(target));
});

it('returns true for element that is focusable and has presentation role', function () {
fixtureSetup('<table role="presentation" tabindex="0"></table>');
var target = fixture.querySelector('table');

assert.isTrue(rule.matches(target));
});
});

0 comments on commit 5651ecc

Please sign in to comment.