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

Method removeTreeNode

packages/react-aria/src/focus/FocusScope.tsx:1045–1078  ·  view source on GitHub ↗
(scopeRef: ScopeRef)

Source from the content-addressed store, hash-verified

1043 }
1044
1045 removeTreeNode(scopeRef: ScopeRef): void {
1046 // never remove the root
1047 if (scopeRef === null) {
1048 return;
1049 }
1050 let node = this.fastMap.get(scopeRef);
1051 if (!node) {
1052 return;
1053 }
1054 let parentNode = node.parent;
1055 // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing
1056 // if we are, then replace the siblings restore with the restore from the scope we're removing
1057 for (let current of this.traverse()) {
1058 if (
1059 current !== node &&
1060 node.nodeToRestore &&
1061 current.nodeToRestore &&
1062 node.scopeRef &&
1063 node.scopeRef.current &&
1064 isElementInScope(current.nodeToRestore, node.scopeRef.current)
1065 ) {
1066 current.nodeToRestore = node.nodeToRestore;
1067 }
1068 }
1069 let children = node.children;
1070 if (parentNode) {
1071 parentNode.removeChild(node);
1072 if (children.size > 0) {
1073 children.forEach(child => parentNode && parentNode.addChild(child));
1074 }
1075 }
1076
1077 this.fastMap.delete(node.scopeRef);
1078 }
1079
1080 // Pre Order Depth First
1081 *traverse(node: TreeNode = this.root): Generator<TreeNode> {

Callers 1

FocusScopeFunction · 0.80

Calls 5

traverseMethod · 0.95
isElementInScopeFunction · 0.85
addChildMethod · 0.80
deleteMethod · 0.80
removeChildMethod · 0.45

Tested by

no test coverage detected