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(layout-table): check for presentation, none roles and isfocusable for matches #828

Merged
merged 3 commits into from
Apr 11, 2018
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
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));
});
});