Currently, I am working on implementing the PrimeNG Tree component in Angular with selectionMode set to "checkbox". My goal is to achieve a programmatic single selection where selecting a child node automatically unselects all other child and parent nodes except for the one directly associated with the selected child node.
Despite my efforts to deselect all nodes before selecting a new one in my Angular component code, it seems that previously selected parent nodes remain selected. I have included the snippet of my code below:
export class TreeCheckboxDemo implements OnInit {
files!: TreeNode[];
selectedFiles!: TreeNode[];
constructor(private nodeService: NodeService) {}
ngOnInit() {
this.nodeService.getFiles().then((data) => (this.files = data));
}
public onNodeSelect(event: any) {
if (this.selectedFiles.length > 1) {
this.selectedFiles = null;
}
this.selectedFiles = [event.node];
}
}
To provide more context, I have created a StackBlitz example. Any assistance or additional code examples would be highly appreciated. Thank you!