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

Function TreeInner

packages/react-aria-components/src/Tree.tsx:407–665  ·  view source on GitHub ↗
({props, collection, treeRef: ref}: TreeInnerProps<T>)

Source from the content-addressed store, hash-verified

405}
406
407function TreeInner<T>({props, collection, treeRef: ref}: TreeInnerProps<T>) {
408 const {dragAndDropHooks} = props;
409 let {direction} = useLocale();
410 let collator = useCollator({usage: 'search', sensitivity: 'base'});
411 let hasDragHooks = !!dragAndDropHooks?.useDraggableCollectionState;
412 let hasDropHooks = !!dragAndDropHooks?.useDroppableCollectionState;
413 let dragHooksProvided = useRef(hasDragHooks);
414 let dropHooksProvided = useRef(hasDropHooks);
415
416 useEffect(() => {
417 if (dragHooksProvided.current !== hasDragHooks) {
418 console.warn(
419 'Drag hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.'
420 );
421 }
422 if (dropHooksProvided.current !== hasDropHooks) {
423 console.warn(
424 'Drop hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.'
425 );
426 }
427 }, [hasDragHooks, hasDropHooks]);
428 let {
429 selectionMode = 'none',
430 expandedKeys: propExpandedKeys,
431 defaultExpandedKeys: propDefaultExpandedKeys,
432 onExpandedChange,
433 disabledBehavior = 'all'
434 } = props;
435 let {
436 CollectionRoot,
437 isVirtualized,
438 layoutDelegate,
439 dropTargetDelegate: ctxDropTargetDelegate
440 } = useContext(CollectionRendererContext);
441
442 // Kinda annoying that we have to replicate this code here as well as in useTreeState, but don't want to add
443 // flattenCollection stuff to useTreeState. Think about this later
444 let [expandedKeys, setExpandedKeys] = useControlledState(
445 propExpandedKeys ? new Set(propExpandedKeys) : undefined,
446 propDefaultExpandedKeys ? new Set(propDefaultExpandedKeys) : new Set(),
447 onExpandedChange
448 );
449
450 let [lastCollection, setLastCollection] = useState(collection);
451 let [lastExpandedKeys, setLastExpandedKeys] = useState(expandedKeys);
452 let [flattenedCollection, setFlattenedCollection] = useState(() =>
453 collection.withExpandedKeys(lastExpandedKeys, expandedKeys)
454 );
455
456 // if the lastExpandedKeys is not the same as the currentExpandedKeys or the collection has changed, then run this
457 if (!areSetsEqual(lastExpandedKeys, expandedKeys) || collection !== lastCollection) {
458 setFlattenedCollection(collection.withExpandedKeys(lastExpandedKeys, expandedKeys));
459 setLastCollection(collection);
460 setLastExpandedKeys(expandedKeys);
461 }
462
463 let state = useTreeState({
464 ...props,

Callers

nothing calls this directly

Calls 15

useLocaleFunction · 0.90
useCollatorFunction · 0.90
useControlledStateFunction · 0.90
useTreeStateFunction · 0.90
useTreeFunction · 0.90
useFocusRingFunction · 0.90
useRenderPropsFunction · 0.90
filterDOMPropsFunction · 0.90
mergePropsFunction · 0.90
useDndPersistedKeysFunction · 0.90
useRenderDropIndicatorFunction · 0.90
areSetsEqualFunction · 0.85

Tested by

no test coverage detected