focusable-not-tabbable-evaluate.js 843 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { isModalOpen } from '../../commons/dom';
  2. function focusableNotTabbableEvaluate(node, options, virtualNode) {
  3. const elementsThatCanBeDisabled = [
  4. 'BUTTON',
  5. 'FIELDSET',
  6. 'INPUT',
  7. 'SELECT',
  8. 'TEXTAREA'
  9. ];
  10. const tabbableElements = virtualNode.tabbableElements;
  11. if (!tabbableElements || !tabbableElements.length) {
  12. return true;
  13. }
  14. const relatedNodes = tabbableElements.reduce((out, { actualNode: el }) => {
  15. const nodeName = el.nodeName.toUpperCase();
  16. // populate nodes that cannot be disabled
  17. if (!elementsThatCanBeDisabled.includes(nodeName)) {
  18. out.push(el);
  19. }
  20. return out;
  21. }, []);
  22. this.relatedNodes(relatedNodes);
  23. if (relatedNodes.length > 0 && isModalOpen()) {
  24. return true;
  25. }
  26. return relatedNodes.length === 0;
  27. }
  28. export default focusableNotTabbableEvaluate;