hidden-explicit-label-evaluate.js 816 B

123456789101112131415161718192021222324252627282930
  1. import { getRootNode, isVisible } from '../../commons/dom';
  2. import { accessibleTextVirtual } from '../../commons/text';
  3. import { escapeSelector } from '../../core/utils';
  4. function hiddenExplicitLabelEvaluate(node, options, virtualNode) {
  5. if (virtualNode.hasAttr('id')) {
  6. if (!virtualNode.actualNode) {
  7. return undefined;
  8. }
  9. const root = getRootNode(node);
  10. const id = escapeSelector(node.getAttribute('id'));
  11. const label = root.querySelector(`label[for="${id}"]`);
  12. if (label && !isVisible(label, true)) {
  13. let name;
  14. try {
  15. name = accessibleTextVirtual(virtualNode).trim();
  16. } catch (e) {
  17. return undefined;
  18. }
  19. const isNameEmpty = name === '';
  20. return isNameEmpty;
  21. }
  22. }
  23. return false;
  24. }
  25. export default hiddenExplicitLabelEvaluate;