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

Method removeTreeNode

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

Source from the content-addressed store, hash-verified

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