-
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.
feat(matches): add explicitRole, implicitRole, and semanticRole match…
…es functions (#2286)
- Loading branch information
Showing
12 changed files
with
298 additions
and
25 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,24 @@ | ||
import fromPrimative from './from-primative'; | ||
import getRole from '../aria/get-role'; | ||
|
||
/** | ||
* Check if a virtual node matches an explicit role(s) | ||
*`` | ||
* Note: matches.explicitRole(vNode, matcher) can be indirectly used through | ||
* matches(vNode, { explicitRole: matcher }) | ||
* | ||
* Example: | ||
* ```js | ||
* matches.explicitRole(vNode, ['combobox', 'textbox']); | ||
* matches.explicitRole(vNode, 'combobox'); | ||
* ``` | ||
* | ||
* @param {VirtualNode} vNode | ||
* @param {Object} matcher | ||
* @returns {Boolean} | ||
*/ | ||
function explicitRole(vNode, matcher) { | ||
return fromPrimative(getRole(vNode, { noImplicit: true }), matcher); | ||
} | ||
|
||
export default explicitRole; |
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,24 @@ | ||
import fromPrimative from './from-primative'; | ||
import getImplicitRole from '../aria/implicit-role'; | ||
|
||
/** | ||
* Check if a virtual node matches an implicit role(s) | ||
*`` | ||
* Note: matches.implicitRole(vNode, matcher) can be indirectly used through | ||
* matches(vNode, { implicitRole: matcher }) | ||
* | ||
* Example: | ||
* ```js | ||
* matches.implicitRole(vNode, ['combobox', 'textbox']); | ||
* matches.implicitRole(vNode, 'combobox'); | ||
* ``` | ||
* | ||
* @param {VirtualNode} vNode | ||
* @param {Object} matcher | ||
* @returns {Boolean} | ||
*/ | ||
function implicitRole(vNode, matcher) { | ||
return fromPrimative(getImplicitRole(vNode.actualNode), matcher); | ||
} | ||
|
||
export default implicitRole; |
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,24 @@ | ||
import fromPrimative from './from-primative'; | ||
import getRole from '../aria/get-role'; | ||
|
||
/** | ||
* Check if a virtual node matches an semantic role(s) | ||
*`` | ||
* Note: matches.semanticRole(vNode, matcher) can be indirectly used through | ||
* matches(vNode, { semanticRole: matcher }) | ||
* | ||
* Example: | ||
* ```js | ||
* matches.semanticRole(vNode, ['combobox', 'textbox']); | ||
* matches.semanticRole(vNode, 'combobox'); | ||
* ``` | ||
* | ||
* @param {VirtualNode} vNode | ||
* @param {Object} matcher | ||
* @returns {Boolean} | ||
*/ | ||
function semanticRole(vNode, matcher) { | ||
return fromPrimative(getRole(vNode), matcher); | ||
} | ||
|
||
export default semanticRole; |
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,41 @@ | ||
describe('matches.explicitRole', function() { | ||
var explicitRole = axe.commons.matches.explicitRole; | ||
var fixture = document.querySelector('#fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
|
||
beforeEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true if explicit role matches', function() { | ||
var virtualNode = queryFixture('<span id="target" role="textbox"></span>'); | ||
assert.isTrue(explicitRole(virtualNode, 'textbox')); | ||
}); | ||
|
||
it('should return true if explicit role matches array', function() { | ||
var virtualNode = queryFixture('<span id="target" role="textbox"></span>'); | ||
assert.isTrue(explicitRole(virtualNode, ['combobox', 'textbox'])); | ||
}); | ||
|
||
it('should return false if explicit role does not match', function() { | ||
var virtualNode = queryFixture('<span id="target" role="main"></span>'); | ||
assert.isFalse(explicitRole(virtualNode, 'textbox')); | ||
}); | ||
|
||
it('should return false if matching implicit role', function() { | ||
var virtualNode = queryFixture('<ul><li id="target"></li></ul>'); | ||
assert.isFalse(explicitRole(virtualNode, 'listitem')); | ||
}); | ||
|
||
// TODO: will only work when get-role works exclusively with virtual | ||
// nodes | ||
it.skip('works with SerialVirtualNode', function() { | ||
var serialNode = new axe.SerialVirtualNode({ | ||
nodeName: 'span', | ||
attributes: { | ||
role: 'textbox' | ||
} | ||
}); | ||
assert.isTrue(explicitRole(serialNode, 'textbox')); | ||
}); | ||
}); |
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,43 @@ | ||
describe('matches.implicitRole', function() { | ||
var implicitRole = axe.commons.matches.implicitRole; | ||
var fixture = document.querySelector('#fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
|
||
beforeEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true if implicit role matches', function() { | ||
var virtualNode = queryFixture('<ul><li id="target"></li></ul>'); | ||
assert.isTrue(implicitRole(virtualNode, 'listitem')); | ||
}); | ||
|
||
it('should return true if implicit role matches array', function() { | ||
var virtualNode = queryFixture('<ul><li id="target"></li></ul>'); | ||
assert.isTrue(implicitRole(virtualNode, ['textbox', 'listitem'])); | ||
}); | ||
|
||
it('should return false if implicit role does not match', function() { | ||
var virtualNode = queryFixture('<ul><li id="target"></li></ul>'); | ||
assert.isFalse(implicitRole(virtualNode, 'textbox')); | ||
}); | ||
|
||
it('should return false if matching explicit role', function() { | ||
var virtualNode = queryFixture( | ||
'<ul role="menu"><li id="target" role="menuitem"></li></ul>' | ||
); | ||
assert.isFalse(implicitRole(virtualNode, 'menuitem')); | ||
}); | ||
|
||
// TODO: will only work when get-role works exclusively with virtual | ||
// nodes | ||
it.skip('works with SerialVirtualNode', function() { | ||
var serialNode = new axe.SerialVirtualNode({ | ||
nodeName: 'span', | ||
attributes: { | ||
role: 'textbox' | ||
} | ||
}); | ||
assert.isTrue(implicitRole(serialNode, 'textbox')); | ||
}); | ||
}); |
Oops, something went wrong.