MCPcopy Create free account
hub / github.com/adobe/react-spectrum / acceptNode

Function acceptNode

packages/react-aria/src/focus/FocusScope.tsx:854–888  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

852 // Create a TreeWalker, ensuring the root is an Element or Document
853 let walker = createShadowTreeWalker(doc, root || doc, NodeFilter.SHOW_ELEMENT, {
854 acceptNode(node) {
855 // Skip nodes inside the starting node.
856 if (nodeContains(opts?.from, node)) {
857 return NodeFilter.FILTER_REJECT;
858 }
859
860 if (
861 opts?.tabbable &&
862 (node as Element).tagName === 'INPUT' &&
863 (node as HTMLInputElement).getAttribute('type') === 'radio'
864 ) {
865 // If the radio is in a form, we can get all the other radios by name
866 if (!isTabbableRadio(node as HTMLInputElement)) {
867 return NodeFilter.FILTER_REJECT;
868 }
869 // If the radio is in the same group as the current node and none are selected, we can skip it
870 if (
871 (walker.currentNode as Element).tagName === 'INPUT' &&
872 (walker.currentNode as HTMLInputElement).type === 'radio' &&
873 (walker.currentNode as HTMLInputElement).name === (node as HTMLInputElement).name
874 ) {
875 return NodeFilter.FILTER_REJECT;
876 }
877 }
878
879 if (
880 filter(node as Element) &&
881 (!scope || isElementInScope(node as Element, scope)) &&
882 (!opts?.accept || opts.accept(node as Element))
883 ) {
884 return NodeFilter.FILTER_ACCEPT;
885 }
886
887 return NodeFilter.FILTER_SKIP;
888 }
889 });
890
891 if (opts?.from) {

Callers

nothing calls this directly

Calls 4

nodeContainsFunction · 0.90
isTabbableRadioFunction · 0.85
isElementInScopeFunction · 0.85
filterFunction · 0.50

Tested by

no test coverage detected