Problem
Render a tree of checkboxes with parent/child relationships.
Requirements
- Checking a parent checks all descendants; unchecking unchecks all descendants.
- When all children are checked, the parent becomes checked; if some (not all) are checked, the parent shows an indeterminate state.
- Works for arbitrary nesting depth.
Hints / Approach
- Model:
{ id, label, children: [] }. Keep acheckedmap keyed by id, or storecheckedon nodes immutably. - Downward propagation: on toggling a node, set the same value on the whole subtree (DFS).
- Upward propagation: after a change, recompute each ancestor —
allChecked → checked,someChecked → indeterminate,noneChecked → unchecked. SetinputEl.indeterminate = true(it's a DOM property, not an attribute/state).