Skip to content

Commit 0062381

Browse files
committed
fix: total count on leaves only
1 parent beedfb8 commit 0062381

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/app/components/checkbox-tree/services/data-state.service.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,25 @@ export class DataStateService {
262262
totalCount: number;
263263
} {
264264
let selectedCount = 0;
265-
let totalCount = 1; // Count this node
265+
let totalCount = 0;
266266

267267
const isCheckedLeaf =
268268
node.isLeaf &&
269269
node.checkboxState.checked &&
270270
!node.checkboxState.indeterminate;
271-
if (isCheckedLeaf) {
272-
selectedCount += 1;
273-
}
274271

275-
// Count children
276-
if (node.children) {
277-
for (const child of node.children) {
278-
selectedCount += child.selectedCount ?? 0;
279-
totalCount += child.totalCount ?? 0;
272+
if (node.isLeaf) {
273+
totalCount = 1;
274+
if (isCheckedLeaf) {
275+
selectedCount += 1;
276+
}
277+
} else {
278+
// Count children
279+
if (node.children) {
280+
for (const child of node.children) {
281+
selectedCount += child.selectedCount ?? 0;
282+
totalCount += child.totalCount ?? 0;
283+
}
280284
}
281285
}
282286

0 commit comments

Comments
 (0)