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

Function acceptNode

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

Source from the content-addressed store, hash-verified

906 // Create a TreeWalker, ensuring the root is an Element or Document
907 let walker = createShadowTreeWalker(doc, root || doc, NodeFilter.SHOW_ELEMENT, {
908 acceptNode(node) {
909 // Skip nodes inside the starting node.
910 if (nodeContains(opts?.from, node)) {
911 return NodeFilter.FILTER_REJECT;
912 }
913
914 if (
915 opts?.tabbable &&
916 (node as Element).tagName === 'INPUT' &&
917 (node as HTMLInputElement).getAttribute('type') === 'radio'
918 ) {
919 // If the radio is in a form, we can get all the other radios by name
920 if (!isTabbableRadio(node as HTMLInputElement)) {
921 return NodeFilter.FILTER_REJECT;
922 }
923 // If the radio is in the same group as the current node and none are selected, we can skip it
924 if (
925 (walker.currentNode as Element).tagName === 'INPUT' &&
926 (walker.currentNode as HTMLInputElement).type === 'radio' &&
927 (walker.currentNode as HTMLInputElement).name === (node as HTMLInputElement).name
928 ) {
929 return NodeFilter.FILTER_REJECT;
930 }
931 }
932
933 if (
934 filter(node as Element) &&
935 (!scope || isElementInScope(node as Element, scope)) &&
936 (!opts?.accept || opts.accept(node as Element))
937 ) {
938 return NodeFilter.FILTER_ACCEPT;
939 }
940
941 return NodeFilter.FILTER_SKIP;
942 }
943 });
944
945 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