Limit mat-tree-nodes items when selecting a parent

I am trying to limit the number of nodes to add on a list, when I check a parent node. For example:

  • Fruits:
    • Orange
    • Apple
    • Banana
    • Strawberry

I want to limit it to 3 elements, so if I check Fruits, I want to only get selected and added first 3 descendant nodes.

Here’s a code similar to mine on stackblitz. How do I have to do it in a code like this one?

Source: New feed