presentational-role-evaluate.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { getExplicitRole, getRole } from '../../commons/aria';
  2. import { getGlobalAriaAttrs } from '../../commons/standards';
  3. import { isFocusable } from '../../commons/dom';
  4. function presentationalRoleEvaluate(node, options, virtualNode) {
  5. const role = getRole(virtualNode);
  6. const explicitRole = getExplicitRole(virtualNode);
  7. if (['presentation', 'none'].includes(role)) {
  8. this.data({ role });
  9. return true;
  10. }
  11. // if the user didn't intended to make this presentational we fail
  12. if (!['presentation', 'none'].includes(explicitRole)) {
  13. return false;
  14. }
  15. // user intended to make this presentational so inform them of
  16. // problems caused by role conflict resolution
  17. const hasGlobalAria = getGlobalAriaAttrs().some(attr =>
  18. virtualNode.hasAttr(attr)
  19. );
  20. const focusable = isFocusable(virtualNode);
  21. let messageKey;
  22. if (hasGlobalAria && !focusable) {
  23. messageKey = 'globalAria';
  24. } else if (!hasGlobalAria && focusable) {
  25. messageKey = 'focusable';
  26. } else {
  27. messageKey = 'both';
  28. }
  29. this.data({
  30. messageKey,
  31. role
  32. });
  33. return false;
  34. }
  35. export default presentationalRoleEvaluate;