Material tree parent node not working as expected

I have done a material tree selectable, with a limit of 42 elements selectable. When I reach the limit (42), the nodes become disabled. The problem is that when I reach the limit and I have from a family some childs selected and some disabled, the parent node is partially selected, so it works weird when I manually deselect a child, and select the parent node again.

enter image description here

Image above is not correct. Parent node should be marked as “All selected”

enter image description here

Image above is correct

enter image description here

This is what happens when I deselect a child, select parent and deselect parent.
And here’s the code.

  descendantsAllSelected(productNodeFlat: ProductNodeFlat): boolean {
    if (this.treeControl.dataNodes) {
      const descendants = this.treeControl.getDescendants(productNodeFlat);
      return descendants.every(child => this.productNodeFlatSelection.isSelected(child));
    }
    return false;
  }

  descendantsPartiallySelected(productNodeFlat: ProductNodeFlat): boolean {
    if (this.treeControl.dataNodes) {
      const descendants = this.treeControl.getDescendants(productNodeFlat);
      const result = descendants.some(child => this.productNodeFlatSelection.isSelected(child));
      return result && !this.descendantsAllSelected(productNodeFlat);
    }
    return false;
  }

Source: New feed