MCPcopy
hub / github.com/facebook/react / focusWithin

Function focusWithin

packages/react-reconciler/src/ReactTestSelectors.js:506–543  ·  view source on GitHub ↗
(
  hostRoot: Instance,
  selectors: Array<Selector>,
)

Source from the content-addressed store, hash-verified

504}
505
506export function focusWithin(
507 hostRoot: Instance,
508 selectors: Array<Selector>,
509): boolean {
510 if (!supportsTestSelectors) {
511 throw new Error('Test selector API is not supported by this renderer.');
512 }
513
514 const root = findFiberRootForHostRoot(hostRoot);
515 const matchingFibers = findPaths(root, selectors);
516
517 const stack = Array.from(matchingFibers);
518 let index = 0;
519 while (index < stack.length) {
520 const fiber = ((stack[index++]: any): Fiber);
521 const tag = fiber.tag;
522 if (isHiddenSubtree(fiber)) {
523 continue;
524 }
525 if (
526 tag === HostComponent ||
527 tag === HostHoistable ||
528 tag === HostSingleton
529 ) {
530 const node = fiber.stateNode;
531 if (setFocusIfFocusable(node)) {
532 return true;
533 }
534 }
535 let child = fiber.child;
536 while (child !== null) {
537 stack.push(child);
538 child = child.sibling;
539 }
540 }
541
542 return false;
543}
544
545const commitHooks: Array<Function> = [];
546

Callers 3

components.test.jsFile · 0.85
focusComponentSearchFunction · 0.85

Calls 5

isHiddenSubtreeFunction · 0.90
setFocusIfFocusableFunction · 0.90
findFiberRootForHostRootFunction · 0.85
findPathsFunction · 0.85
pushMethod · 0.65

Tested by 1

focusComponentSearchFunction · 0.68