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

Function getSelectedAncestors

packages/@react-spectrum/s2/src/SideNav.tsx:748–766  ·  view source on GitHub ↗
(state: TreeState<unknown>, selectedRoute: string)

Source from the content-addressed store, hash-verified

746
747// The set of collection keys that are ancestors of the item matching `selectedRoute`.
748function getSelectedAncestors(state: TreeState<unknown>, selectedRoute: string): Set<Key> {
749 let {collection} = state;
750 let cached = selectedAncestorsCache.get(collection);
751 if (cached && cached.selection === selectedRoute) {
752 return cached.ancestors;
753 }
754
755 let matchKey = findKeyForRoute(collection, selectedRoute);
756
757 let ancestors = new Set<Key>();
758 let node = matchKey != null ? collection.getItem(matchKey) : null;
759 while (node?.parentKey != null && !ancestors.has(node.parentKey)) {
760 ancestors.add(node.parentKey);
761 node = collection.getItem(node.parentKey);
762 }
763
764 selectedAncestorsCache.set(collection, {selection: selectedRoute, ancestors});
765 return ancestors;
766}
767
768// Whether the row `id` is an ancestor of the item matching `selectedRoute`, i.e. it has a
769// selected descendant. Used to keep a collapsed parent styled when its selected child is hidden.

Callers 1

hasSelectedDescendantFunction · 0.85

Calls 5

findKeyForRouteFunction · 0.85
getItemMethod · 0.65
hasMethod · 0.65
addMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected