no-explicit-name-required-matches.js 640 B

12345678910111213141516171819202122
  1. import { isFocusable } from '../commons/dom';
  2. import { getExplicitRole } from '../commons/aria';
  3. import ariaRoles from '../standards/aria-roles';
  4. /**
  5. * Filter out elements with an explicit role that does not require an accessible name and is not focusable
  6. */
  7. function noExplicitNameRequired(node, virtualNode) {
  8. const role = getExplicitRole(virtualNode);
  9. if (!role || ['none', 'presentation'].includes(role)) {
  10. return true;
  11. }
  12. const { accessibleNameRequired } = ariaRoles[role] || {};
  13. if (accessibleNameRequired || isFocusable(virtualNode)) {
  14. return true;
  15. }
  16. return false;
  17. }
  18. export default noExplicitNameRequired;