get-owned-virtual.js 778 B

123456789101112131415161718192021222324252627
  1. import idrefs from '../dom/idrefs';
  2. /**
  3. * Get an element's owned elements
  4. *
  5. * @param {VirtualNode} element
  6. * @return {VirtualNode[]} Owned elements
  7. */
  8. function getOwnedVirtual(virtualNode) {
  9. const { actualNode, children } = virtualNode;
  10. if (!children) {
  11. throw new Error('getOwnedVirtual requires a virtual node');
  12. }
  13. // TODO: Check that the element has a role
  14. // TODO: Descend into children with role=presentation|none
  15. // TODO: Exclude descendents owned by other elements
  16. if (virtualNode.hasAttr('aria-owns')) {
  17. const owns = idrefs(actualNode, 'aria-owns')
  18. .filter(element => !!element)
  19. .map(element => axe.utils.getNodeFromTree(element));
  20. return [...children, ...owns];
  21. }
  22. return [...children];
  23. }
  24. export default getOwnedVirtual;