call(back)
FrontendmediumSign in to star problems

Nested Checkboxes

Build a tree of checkboxes from the nested data in the starter.

Requirements

  • Checking or unchecking a parent sets every checkbox beneath it the same way.
  • A parent shows as checked when all of its descendants are checked, unchecked when none are, and indeterminate (the dash state) when some are.
  • Changing a leaf updates every ancestor accordingly.
  • The tree renders recursively to any depth, with each level indented.

Hints

Hint 1

Keep a set of checked leaf ids only. A parent's state is then a count: all leaves checked, none, or some.

Hint 2

A helper that returns the leaf ids under a node drives both the derived state and the toggle.

Hint 3

indeterminate is not an HTML attribute; set it on the input element through a ref callback.

Asked at