Skip to content

docs(tree): fix example that shows empty checklists as selected #20106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class TreeChecklistExample {
: new TodoItemFlatNode();
flatNode.item = node.item;
flatNode.level = level;
flatNode.expandable = !!node.children;
flatNode.expandable = !!node.children?.length;
this.flatNodeMap.set(flatNode, node);
this.nestedNodeMap.set(node, flatNode);
return flatNode;
Expand All @@ -171,9 +171,9 @@ export class TreeChecklistExample {
/** Whether all the descendants of the node are selected. */
descendantsAllSelected(node: TodoItemFlatNode): boolean {
const descendants = this.treeControl.getDescendants(node);
const descAllSelected = descendants.every(child =>
this.checklistSelection.isSelected(child)
);
const descAllSelected = descendants.length > 0 && descendants.every(child => {
return this.checklistSelection.isSelected(child);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why add the {} and return?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just find it more readable compared to the multi-line arrow function with an implicit return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the implicit return, but I don't think we have an official style on way or the other

});
return descAllSelected;
}

Expand All @@ -193,9 +193,7 @@ export class TreeChecklistExample {
: this.checklistSelection.deselect(...descendants);

// Force update for the parent
descendants.every(child =>
this.checklistSelection.isSelected(child)
);
descendants.forEach(child => this.checklistSelection.isSelected(child));
this.checkAllParentsSelection(node);
}

Expand All @@ -218,9 +216,9 @@ export class TreeChecklistExample {
checkRootNodeSelection(node: TodoItemFlatNode): void {
const nodeSelected = this.checklistSelection.isSelected(node);
const descendants = this.treeControl.getDescendants(node);
const descAllSelected = descendants.every(child =>
this.checklistSelection.isSelected(child)
);
const descAllSelected = descendants.length > 0 && descendants.every(child => {
return this.checklistSelection.isSelected(child);
});
if (nodeSelected && !descAllSelected) {
this.checklistSelection.deselect(node);
} else if (!nodeSelected && descAllSelected) {
Expand Down