has-descendant-evaluate.js 611 B

1234567891011121314151617181920
  1. import { querySelectorAllFilter } from '../../core/utils';
  2. import { isVisible } from '../../commons/dom';
  3. function hasDescendant(node, options, virtualNode) {
  4. if (!options || !options.selector || typeof options.selector !== 'string') {
  5. throw new TypeError(
  6. 'has-descendant requires options.selector to be a string'
  7. );
  8. }
  9. const matchingElms = querySelectorAllFilter(
  10. virtualNode,
  11. options.selector,
  12. vNode => isVisible(vNode.actualNode, true)
  13. );
  14. this.relatedNodes(matchingElms.map(vNode => vNode.actualNode));
  15. return matchingElms.length > 0;
  16. }
  17. export default hasDescendant;