heading-matches.js 528 B

12345678910111213141516171819
  1. function headingMatches(node) {
  2. // Get all valid roles
  3. let explicitRoles;
  4. if (node.hasAttribute('role')) {
  5. explicitRoles = node
  6. .getAttribute('role')
  7. .split(/\s+/i)
  8. .filter(axe.commons.aria.isValidRole);
  9. }
  10. // Check valid roles if there are any, otherwise fall back to the inherited role
  11. if (explicitRoles && explicitRoles.length > 0) {
  12. return explicitRoles.includes('heading');
  13. } else {
  14. return axe.commons.aria.implicitRole(node) === 'heading';
  15. }
  16. }
  17. export default headingMatches;