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

Function closestVisibleKey

packages/@react-spectrum/s2/src/SideNav.tsx:724–739  ·  view source on GitHub ↗
(
  collection: Collection<Node<unknown>>,
  expandedKeys: Set<Key>,
  key: Key
)

Source from the content-addressed store, hash-verified

722// are expanded). Returns `key` unchanged when it is already visible. A collapsed ancestor hides
723// everything beneath it, so the highest collapsed ancestor is the closest visible row.
724function closestVisibleKey(
725 collection: Collection<Node<unknown>>,
726 expandedKeys: Set<Key>,
727 key: Key
728): Key {
729 let target = key;
730 let node = collection.getItem(key);
731 while (node?.parentKey != null) {
732 let parent = collection.getItem(node.parentKey);
733 if (parent?.type === 'item' && !expandedKeys.has(node.parentKey)) {
734 target = node.parentKey;
735 }
736 node = parent;
737 }
738 return target;
739}
740
741// Cache so each row doesn't have to walk up the tree every time
742let selectedAncestorsCache = new WeakMap<

Callers 1

useRouteFocusSyncFunction · 0.85

Calls 2

getItemMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected