-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-allowed-role): allow title, aria-label and aria-labelledby o…
…n a img element with a supported role (#3224)
- Loading branch information
Showing
16 changed files
with
307 additions
and
13 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
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,25 @@ | ||
import accessibleTextVirtual from '../text/accessible-text-virtual'; | ||
import fromPrimative from './from-primative'; | ||
|
||
/** | ||
* Check if a virtual node has a non-empty accessible name | ||
*`` | ||
* Note: matches.hasAccessibleName(vNode, true) can be indirectly used through | ||
* matches(vNode, { hasAccessibleName: boolean }) | ||
* | ||
* Example: | ||
* ```js | ||
* matches.hasAccessibleName(vNode, true); | ||
* matches.hasAccessibleName(vNode, false); | ||
* | ||
* ``` | ||
* | ||
* @param {VirtualNode} vNode | ||
* @param {Object} matcher | ||
* @returns {Boolean} | ||
*/ | ||
function hasAccessibleName(vNode, matcher) { | ||
return fromPrimative(!!accessibleTextVirtual(vNode), matcher); | ||
} | ||
|
||
export default hasAccessibleName; |
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
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
describe('matches.accessibleName', function() { | ||
var hasAccessibleName = axe.commons.matches.hasAccessibleName; | ||
var fixture = document.querySelector('#fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
|
||
beforeEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true when text has an accessible name', function() { | ||
var virtualNode = queryFixture('<button id="target">hello world</button>'); | ||
assert.isTrue(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return true when aria-label has an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-label="hello world"></button>' | ||
); | ||
assert.isTrue(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return true when aria-labelledby has an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-labelledby="foo"></button><div id="foo">hello world</div' | ||
); | ||
assert.isTrue(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return true when title has an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" title="hello world"></button>' | ||
); | ||
assert.isTrue(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return true when label has an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<label>hello world<input id="target"></label>' | ||
); | ||
assert.isTrue(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when text does not have an accessible name', function() { | ||
var virtualNode = queryFixture('<button id="target"></button>'); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when aria-label does not have an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-label=""></button>' | ||
); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when aria-labelledby does not have an accessible name', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-labelledby=""></button><div id="foo">hello world</div' | ||
); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when aria-labelledby references an element that does not exist', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-labelledby="bar"></button><div id="foo">hello world</div' | ||
); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when aria-labelledby references an elm that does not exist', function() { | ||
var virtualNode = queryFixture( | ||
'<button id="target" aria-labelledby="bar"></button><div id="foo">hello world</div' | ||
); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when title does not have an accessible name', function() { | ||
var virtualNode = queryFixture('<button id="target" title=""></button>'); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('should return false when label does not have an accessible name', function() { | ||
var virtualNode = queryFixture('<label><input id="target"></label>'); | ||
assert.isFalse(hasAccessibleName(virtualNode, true)); | ||
}); | ||
|
||
it('works with SerialVirtualNode', function() { | ||
var serialNode = new axe.SerialVirtualNode({ | ||
nodeName: 'button', | ||
attributes: { | ||
role: 'button', | ||
'aria-label': 'hello world' | ||
} | ||
}); | ||
assert.isTrue(hasAccessibleName(serialNode, true)); | ||
}); | ||
}); |
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
Oops, something went wrong.