Skip to content

Commit

Permalink
fix(related-table): expanded toggling already expanded nodes (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertNader committed Nov 18, 2022
1 parent 890dc4d commit a6d29c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/related-table/src/Hooks/useTreeCollection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ describe('useTreeCollection', () => {
)
);

expect(result.current.items[0].isExpanded()).toEqual(true);
expect(result.current.items[1].isExpanded()).toEqual(true);
expect(result.current.items[2].isExpanded()).toEqual(true);
});
it('should not toggle expanded nodes when expanding all nodes', () => {
const { result, rerender } = renderHook((expanded: boolean) =>
useTreeCollection(
items,
{
columnDefinitions,
keyPropertyName: 'id',
parentKeyPropertyName: 'parentId',
sorting: {},
selection: {
trackBy: 'entityId',
},
},
expanded
)
);

act(() => {
result.current.expandNode(result.current.items[0]);
});

rerender(true);

expect(result.current.items[0].isExpanded()).toEqual(true);
expect(result.current.items[1].isExpanded()).toEqual(true);
expect(result.current.items[2].isExpanded()).toEqual(true);
Expand Down
4 changes: 3 additions & 1 deletion packages/related-table/src/Hooks/useTreeCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export const useTreeCollection = <T>(

nodes.forEach((node) => {
if (!nodesExpanded[node.id]) {
node.toggleExpandCollapse();
if (!node.isExpanded()) {
node.toggleExpandCollapse();
}
node.setVisible(true);
newNodesExpanded[node.id] = true;
}
Expand Down

0 comments on commit a6d29c8

Please sign in to comment.