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

Method removeTreeNode

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

Source from the content-addressed store, hash-verified

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