is-valid-role.js 765 B

12345678910111213141516171819202122
  1. import standards from '../../standards';
  2. import isUnsupportedRole from './is-unsupported-role';
  3. /**
  4. * Check if a given role is valid
  5. * @method isValidRole
  6. * @memberof axe.commons.aria
  7. * @instance
  8. * @param {String} role The role to check
  9. * @param {Object} options Use `allowAbstract` if you want abstracts, and `flagUnsupported: true` to report unsupported roles
  10. * @return {Boolean}
  11. */
  12. function isValidRole(role, { allowAbstract, flagUnsupported = false } = {}) {
  13. const roleDefinition = standards.ariaRoles[role];
  14. const isRoleUnsupported = isUnsupportedRole(role);
  15. if (!roleDefinition || (flagUnsupported && isRoleUnsupported)) {
  16. return false;
  17. }
  18. return allowAbstract ? true : roleDefinition.type !== 'abstract';
  19. }
  20. export default isValidRole;