-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(standards): add get-aria-roles-supporting-name-from-content and …
…deprecate aria/get-roles-with-name-from-content (#2363)
- Loading branch information
Showing
7 changed files
with
141 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import lookupTable from './lookup-table'; | ||
import getAriaRolesSupportingNameFromContent from '../standards/get-aria-roles-supporting-name-from-content'; | ||
|
||
/** | ||
* Get the roles that get name from the element's contents | ||
* @method getRolesWithNameFromContents | ||
* @memberof axe.commons.aria | ||
* @instance | ||
* @deprecated use standards/get-aria-roles-supporting-name-from-content | ||
* @return {Array} Array of roles that match the type | ||
*/ | ||
function getRolesWithNameFromContents() { | ||
return Object.keys(lookupTable.role).filter(function(r) { | ||
return ( | ||
lookupTable.role[r].nameFrom && | ||
lookupTable.role[r].nameFrom.indexOf('contents') !== -1 | ||
); | ||
}); | ||
return getAriaRolesSupportingNameFromContent(); | ||
} | ||
|
||
export default getRolesWithNameFromContents; |
22 changes: 22 additions & 0 deletions
22
lib/commons/standards/get-aria-roles-supporting-name-from-content.js
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,22 @@ | ||
import cache from '../../core/base/cache'; | ||
import standards from '../../standards'; | ||
|
||
/** | ||
* Return a list of aria roles which are name from content. | ||
* @return {String[]} List of all roles with name from content | ||
*/ | ||
function getAriaRolesSupportingNameFromContent() { | ||
if (cache.get('ariaRolesNameFromContent')) { | ||
return cache.get('ariaRolesNameFromContent'); | ||
} | ||
|
||
const contentRoles = Object.keys(standards.ariaRoles).filter(roleName => { | ||
return standards.ariaRoles[roleName].nameFromContent; | ||
}); | ||
|
||
cache.set('ariaRolesNameFromContent', contentRoles); | ||
|
||
return contentRoles; | ||
} | ||
|
||
export default getAriaRolesSupportingNameFromContent; |
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,28 @@ | ||
describe('aria.getRolesWithNameFromContents', function() { | ||
'use strict'; | ||
|
||
before(function() { | ||
axe._load({}); | ||
}); | ||
|
||
afterEach(function() { | ||
axe.reset(); | ||
}); | ||
|
||
it('should return array if nameFrom contents is found in the lookup table', function() { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
dogs: { | ||
type: 'things', | ||
nameFromContent: true | ||
}, | ||
cats: { | ||
type: 'stuff' | ||
} | ||
} | ||
} | ||
}); | ||
assert.include(axe.commons.aria.getRolesWithNameFromContents(), 'dogs'); | ||
}); | ||
}); |
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
84 changes: 84 additions & 0 deletions
84
test/commons/standards/get-aria-roles-supporting-name-from-content.js
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,84 @@ | ||
describe('standards.getAriaRolesSupportingNameFromContent', function() { | ||
var getAriaRolesSupportingNameFromContent = | ||
axe.commons.standards.getAriaRolesSupportingNameFromContent; | ||
|
||
before(function() { | ||
axe._load({}); | ||
}); | ||
|
||
after(function() { | ||
axe.reset(); | ||
}); | ||
|
||
it('should return a list of role names which are named from content', function() { | ||
// Source: https://www.w3.org/TR/wai-aria-1.1/#namefromcontent | ||
// Source: https://www.w3.org/TR/dpub-aria-1.0/ | ||
// Note: we have added roles in our spec. also note that | ||
// although "tree" is listed as supporting name from content | ||
// it's role definition does not list contents in the name from | ||
// section (it was removed from the list in WAI ARIA 1.2) | ||
var contentRoles = getAriaRolesSupportingNameFromContent(); | ||
assert.deepEqual(contentRoles, [ | ||
'button', | ||
'cell', | ||
'checkbox', | ||
'columnheader', | ||
'directory', | ||
'figure', | ||
'gridcell', | ||
'heading', | ||
'link', | ||
'listitem', | ||
'menuitem', | ||
'menuitemcheckbox', | ||
'menuitemradio', | ||
'option', | ||
'radio', | ||
'row', | ||
'rowgroup', | ||
'rowheader', | ||
'section', | ||
'sectionhead', | ||
'switch', | ||
'tab', | ||
'table', | ||
'term', | ||
'tooltip', | ||
'treeitem', | ||
'doc-backlink', | ||
'doc-biblioref', | ||
'doc-glossref', | ||
'doc-noteref' | ||
]); | ||
}); | ||
|
||
it('should return configured roles', function() { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
myRole: { | ||
nameFromContent: true | ||
} | ||
} | ||
} | ||
}); | ||
|
||
var contentRoles = getAriaRolesSupportingNameFromContent(); | ||
assert.include(contentRoles, 'myRole'); | ||
}); | ||
|
||
it('should not return role that is configured to not be of the type', function() { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
button: { | ||
nameFromContent: false | ||
} | ||
} | ||
} | ||
}); | ||
|
||
var contentRoles = getAriaRolesSupportingNameFromContent(); | ||
assert.notInclude(contentRoles, 'button'); | ||
}); | ||
}); |