Skip to content

Commit

Permalink
fix: when collapsing an item, keep ancestors expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Aug 12, 2022
1 parent 8ae5af1 commit 546df72
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/expandControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ export function ExpandControl<T>({ itemId, hasDeferredChildren }: { itemId: Id;
} = table.getState();

const newExpanded = new Set(expanded);
if (expandOnlyOne) newExpanded.clear();
if (isExpanded) newExpanded.delete(itemId);
else {
newExpanded.add(itemId);

if (expandOnlyOne) {
newExpanded.clear();

const item = activeItemsById.get(itemId);
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
newExpanded.add(ancestor);
}
}

if (isExpanded) {
newExpanded.delete(itemId);
} else {
newExpanded.add(itemId);
}

onExpandedChange?.(newExpanded);

if (!controlledExpanded) {
Expand Down

0 comments on commit 546df72

Please sign in to comment.