no-naming-method-matches.js 744 B

123456789101112131415161718192021222324
  1. import { getExplicitRole } from '../commons/aria';
  2. import { querySelectorAll } from '../core/utils';
  3. import getElementSpec from '../commons/standards/get-element-spec';
  4. /**
  5. * Filter out elements that have a naming method (i.e. img[alt], table > caption, etc.)
  6. */
  7. function noNamingMethodMatches(node, virtualNode) {
  8. const { namingMethods } = getElementSpec(virtualNode);
  9. if (namingMethods && namingMethods.length !== 0) {
  10. return false;
  11. }
  12. // Additionally, ignore combobox that get their name from a descendant input:
  13. if (
  14. getExplicitRole(virtualNode) === 'combobox' &&
  15. querySelectorAll(virtualNode, 'input:not([type="hidden"])').length
  16. ) {
  17. return false;
  18. }
  19. return true;
  20. }
  21. export default noNamingMethodMatches;