landmark-is-top-level-evaluate.js 890 B

12345678910111213141516171819202122232425262728293031
  1. import { getRole, implicitRole } from '../../commons/aria';
  2. import { getAriaRolesByType } from '../../commons/standards';
  3. import { getComposedParent } from '../../commons/dom';
  4. function landmarkIsTopLevelEvaluate(node) {
  5. var landmarks = getAriaRolesByType('landmark');
  6. var parent = getComposedParent(node);
  7. var nodeRole = getRole(node);
  8. this.data({ role: nodeRole });
  9. while (parent) {
  10. var role = parent.getAttribute('role');
  11. if (!role && parent.nodeName.toUpperCase() !== 'FORM') {
  12. role = implicitRole(parent);
  13. }
  14. // allow aside inside main
  15. // @see https://github.com/dequelabs/axe-core/issues/2651
  16. if (
  17. role &&
  18. landmarks.includes(role) &&
  19. !(role === 'main' && nodeRole === 'complementary')
  20. ) {
  21. return false;
  22. }
  23. parent = getComposedParent(parent);
  24. }
  25. return true;
  26. }
  27. export default landmarkIsTopLevelEvaluate;