invalidrole-evaluate.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { isValidRole } from '../../commons/aria';
  2. import { tokenList } from '../../core/utils';
  3. /**
  4. * Check that each role on an element is a valid ARIA role.
  5. *
  6. * Valid ARIA roles are listed in the `ariaRoles` standards object.
  7. *
  8. * ##### Data:
  9. * <table class="props">
  10. * <thead>
  11. * <tr>
  12. * <th>Type</th>
  13. * <th>Description</th>
  14. * </tr>
  15. * </thead>
  16. * <tbody>
  17. * <tr>
  18. * <td><code>String[]</code></td>
  19. * <td>List of all invalid roles</td>
  20. * </tr>
  21. * </tbody>
  22. * </table>
  23. *
  24. * @memberof checks
  25. * @return {Boolean} True if the element uses an invalid role. False otherwise.
  26. */
  27. function invalidroleEvaluate(node, options, virtualNode) {
  28. const allRoles = tokenList(virtualNode.attr('role'));
  29. const allInvalid = allRoles.every(
  30. role => !isValidRole(role, { allowAbstract: true })
  31. );
  32. /**
  33. * Only fail when all the roles are invalid
  34. */
  35. if (allInvalid) {
  36. this.data(allRoles);
  37. return true;
  38. }
  39. return false;
  40. }
  41. export default invalidroleEvaluate;