-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
87fa280
commit 80ef961
Showing
7 changed files
with
76 additions
and
8 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
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,13 @@ | ||
// Get all valid roles | ||
let explicitRoles; | ||
if (node.hasAttribute('role')) { | ||
explicitRoles = node.getAttribute('role').split(/\s+/i) | ||
.filter(axe.commons.aria.isValidRole); | ||
} | ||
|
||
// Check valid roles if there are any, otherwise fall back to the inherited role | ||
if (explicitRoles && explicitRoles.length > 0) { | ||
return explicitRoles.includes('heading'); | ||
} else { | ||
return axe.commons.aria.implicitRole(node) === 'heading'; | ||
} |
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
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 |
---|---|---|
|
@@ -13,8 +13,6 @@ | |
["#pass4"], | ||
["#pass5"], | ||
["#pass6"], | ||
["#pass7"], | ||
["#pass8"], | ||
["#pass9"] | ||
["#pass7"] | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
describe('heading-matches', function () { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var rule; | ||
|
||
beforeEach(function () { | ||
rule = axe._audit.rules.find(function (rule) { | ||
return rule.id === 'empty-heading'; | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('is a function', function () { | ||
assert.isFunction(rule.matches); | ||
}); | ||
|
||
it('should return false on elements that are not headings', function () { | ||
var div = document.createElement('div'); | ||
assert.isFalse(rule.matches(div)); | ||
}); | ||
|
||
it('should return true on elements with "heading" in the role', function () { | ||
var div = document.createElement('div'); | ||
div.setAttribute('role', 'heading'); | ||
assert.isTrue(rule.matches(div)); | ||
|
||
div.setAttribute('role', 'slider heading'); | ||
assert.isTrue(rule.matches(div)); | ||
}); | ||
|
||
it('should return true on regular headings without roles', function () { | ||
var h1 = document.createElement('h1'); | ||
var h2 = document.createElement('h2'); | ||
var h3 = document.createElement('h3'); | ||
assert.isTrue(rule.matches(h1)); | ||
assert.isTrue(rule.matches(h2)); | ||
assert.isTrue(rule.matches(h3)); | ||
}); | ||
|
||
it('should return false on headings with their role changes', function () { | ||
var h1 = document.createElement('h1'); | ||
h1.setAttribute('role', 'banner'); | ||
assert.isFalse(rule.matches(h1)); | ||
}); | ||
|
||
it('should return true on headings with their role changes to an invalid role', function () { | ||
var h1 = document.createElement('h1'); | ||
h1.setAttribute('role', 'bruce'); | ||
assert.isTrue(rule.matches(h1)); | ||
}); | ||
}); |