get-tabbable-elements.js 800 B

1234567891011121314151617181920212223242526
  1. import { querySelectorAll } from '../../core/utils';
  2. /**
  3. * Get all elements (including given node) that are part of the tab order
  4. * @method getTabbableElements
  5. * @memberof axe.commons.dom
  6. * @instance
  7. * @param {Object} virtualNode The virtualNode to assess
  8. * @return {Boolean}
  9. */
  10. function getTabbableElements(virtualNode) {
  11. const nodeAndDescendents = querySelectorAll(virtualNode, '*');
  12. const tabbableElements = nodeAndDescendents.filter(vNode => {
  13. const isFocusable = vNode.isFocusable;
  14. let tabIndex = vNode.actualNode.getAttribute('tabindex');
  15. tabIndex =
  16. tabIndex && !isNaN(parseInt(tabIndex, 10)) ? parseInt(tabIndex) : null;
  17. return tabIndex ? isFocusable && tabIndex >= 0 : isFocusable;
  18. });
  19. return tabbableElements;
  20. }
  21. export default getTabbableElements;