Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
[Issue #214] react-a11y-role-has-required-aria-props - updated docume…
Browse files Browse the repository at this point in the history
…ntation

closes #214
  • Loading branch information
HamletDRC committed Sep 2, 2016
1 parent e229e4e commit cecbbcf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Rule Name | Description | Since
`react-a11y-lang` | For accessibility of your website, HTML elements must have a lang attribute and the attribute must be a valid language code.<br/>References:<br/>* [H58: Using language attributes to identify changes in the human language](https://www.w3.org/TR/WCAG20-TECHS/H58.html)<br/>* [lang attribute must have a valid value](https://dequeuniversity.com/rules/axe/1.1/valid-lang)<br/>[List of ISO 639-1 codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) | 2.0.11
`react-a11y-meta` | For accessibility of your website, HTML meta elements must not have http-equiv="refresh". | 2.0.11
`react-a11y-props` | For accessibility of your website, enforce all `aria-*` attributes are valid. Elements cannot use an invalid `aria-*` attribute. This rule will fail if it finds an `aria-*` attribute that is not listed in [WAI-ARIA states and properties](https://www.w3.org/TR/wai-aria/states_and_properties#state_prop_def). | 2.0.11
`react-a11y-role-has-required-aria-props` | For accessibility of your website, elements with aria roles must have all required attributes according to the role. | 2.0.11
`react-a11y-role-has-required-aria-props` | For accessibility of your website, elements with aria roles must have all required attributes according to the role. <br/>References:<br/>[ARIA Definition of Roles](https://www.w3.org/TR/wai-aria/roles#role_definitions)<br/>[WCAG Rule 90: Required properties and states should be defined](http://oaa-accessibility.org/wcag20/rule/90/)<br/>[WCAG Rule 91: Required properties and states must not be empty](http://oaa-accessibility.org/wcag20/rule/91/)<br/>| 2.0.11
`react-a11y-role-supports-aria-props` | For accessibility of your website, enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. Many aria attributes (states and properties) can only be used on elements with particular roles. Some elements have implicit roles, such as `<a href='hrefValue' />`, which will be resolved to `role='link'`. A reference for the implicit roles can be found at [Default Implicit ARIA Semantics](https://www.w3.org/TR/html-aria/#sec-strong-native-semantics). | 2.0.11
`react-a11y-role` | For accessibility of your website, elements with aria roles must use a **valid**, **non-abstract** aria role. A reference to role defintions can be found at [WAI-ARIA roles](https://www.w3.org/TR/wai-aria/roles#role_definitions). | 2.0.11
`react-a11y-tabindex-no-positive` | For accessibility of your website, enforce tabindex value is **not greater than zero**. Avoid positive tabindex attribute values to synchronize the flow of the page with keyboard tab order.<br/>References:<br/>[WCAG 2.4.3 - Focus Order](https://www.w3.org/TR/2008/REC-WCAG20-20081211/#navigation-mechanisms-focus-order)<br/>[Audit Rules - tabindex-usage](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#tabindex-usage)<br/>[Avoid positive integer values for tabIndex](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_03) | 2.0.11
Expand Down
16 changes: 8 additions & 8 deletions src/reactA11yRoleHasRequiredAriaPropsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { IRole, IRoleSchema } from './utils/attributes/IRole';
import { IAria } from './utils/attributes/IAria';

// tslint:disable-next-line:no-require-imports no-var-requires
const roleSchema: IRoleSchema = require('./utils/attributes/roleSchema.json');
const roles: IRole[] = roleSchema.roles;
const ROLES_SCHEMA: IRoleSchema = require('./utils/attributes/roleSchema.json');
const ROLES: IRole[] = ROLES_SCHEMA.roles;


// tslint:disable-next-line:no-require-imports no-var-requires
const ariaAttributes: { [attributeName: string]: IAria } = require('./utils/attributes/ariaSchema.json');
const roleString: string = 'role';
const ARIA_ATTRIBUTES: { [attributeName: string]: IAria } = require('./utils/attributes/ariaSchema.json');
const ROLE_STRING: string = 'role';

export function getFailureStringForNotImplicitRole(
roleNamesInElement: string[],
Expand Down Expand Up @@ -75,13 +75,13 @@ class A11yRoleHasRequiredAriaPropsWalker extends Lint.RuleWalker {

private checkJsxElement(node: ts.JsxOpeningElement): void {
const attributesInElement: { [propName: string]: ts.JsxAttribute } = getJsxAttributesFromJsxElement(node);
const roleProp: ts.JsxAttribute = attributesInElement[roleString];
const roleProp: ts.JsxAttribute = attributesInElement[ROLE_STRING];

// If role attribute is specified, get the role value. Otherwise get the implicit role from tag name.
const roleValue: string = roleProp ? getStringLiteral(roleProp) : getImplicitRole(node);
const isImplicitRole: boolean = !roleProp && !!roleValue;
const normalizedRoles: string[] = (roleValue || '').toLowerCase().split(' ')
.filter((role: string) => !!roles[role]);
.filter((role: string) => !!ROLES[role]);

if (normalizedRoles.length === 0) {
return;
Expand All @@ -90,11 +90,11 @@ class A11yRoleHasRequiredAriaPropsWalker extends Lint.RuleWalker {
let requiredAttributeNames: string[] = [];

normalizedRoles.forEach((role: string) => {
requiredAttributeNames = requiredAttributeNames.concat(roles[role].requiredProps || []);
requiredAttributeNames = requiredAttributeNames.concat(ROLES[role].requiredProps || []);
});

const attributeNamesInElement: string[] = Object.keys(attributesInElement)
.filter((attributeName: string) => !!ariaAttributes[attributeName.toLowerCase()]);
.filter((attributeName: string) => !!ARIA_ATTRIBUTES[attributeName.toLowerCase()]);

// Get the list of missing required aria-* attributes in current element.
const missingAttributes: string[] = requiredAttributeNames
Expand Down

0 comments on commit cecbbcf

Please sign in to comment.