From 546df72bfbc32a303c0318f83a6903b17f54724b Mon Sep 17 00:00:00 2001 From: Marco Schumacher Date: Fri, 12 Aug 2022 14:47:27 +0200 Subject: [PATCH] fix: when collapsing an item, keep ancestors expanded --- src/components/expandControl.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/expandControl.tsx b/src/components/expandControl.tsx index 83aa8ff..6587b20 100644 --- a/src/components/expandControl.tsx +++ b/src/components/expandControl.tsx @@ -21,10 +21,9 @@ export function ExpandControl({ 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) : []) { @@ -32,6 +31,12 @@ export function ExpandControl({ itemId, hasDeferredChildren }: { itemId: Id; } } + if (isExpanded) { + newExpanded.delete(itemId); + } else { + newExpanded.add(itemId); + } + onExpandedChange?.(newExpanded); if (!controlledExpanded) {