Overview

Use Checkbox Tree to select items from a hierarchy whose levels open and close, such as subjects and their assessments when setting an assessment, or year groups, classes and pupils.

It combines a Tree with Checkbox Group: every row has a checkbox, and every parent row can select everything inside it.

Checkbox Tree anatomy

Anatomy

#PartDescription
1ChevronOpens and closes the group. Points right when closed, down when open. Its label is read by screen readers.
2Parent checkboxCheckboxTree.CollapsibleTrigger. Selects or clears everything in the group, shown or not. Indeterminate when some items are selected.
3ItemCheckboxTree.Item, with a value. Its text sits next to the checkbox.
4Count (add-on)A Badge you add to a collapsed parent, such as "2 of 3".
5Icon (add-on)An optional Icon before the text, for the type of item.

Use it when

  • Items sit in two or more levels that need to collapse, such as subjects and their assessments.
  • People filter by category and sub-category at once.

Don't use it when

  • The list is flat, such as five classes. Use Checkbox Group.
  • There's only one level with a select all. Use Checkbox Group with CheckboxGroup.AllItem.
  • People pick a single item. Use a tree without checkboxes, or Radio Button.

Behaviour

Clicking a parent's checkbox or its text selects it. Clicking the chevron opens or closes it.

A parent selects all its items even when it's closed and they're hidden. Pressing Escape inside an open group closes it and moves focus to its chevron.

Open or closed

Start with groups closed, so people can scan the top level. Open a group by default only when it's the only one, or when it already has selected items.

Hidden selections

When a closed group has selected items, show how many next to it, with a Badge such as "2 of 3". People can then see what's selected without opening every group.

Labels

Keep labels short enough to fit on one line, such as "Year 7 Maths · Autumn". Long labels are cut off with an ellipsis.

Add-ons

These aren't part of the component, but work well with it:

  • Search. A Search Input above the tree, for long lists.
  • Counts. A Badge on collapsed parents, showing how many items are selected.
  • Icons. An Icon before the text, for the type of node.

A tree with a search input, icons and a count badge

Keyboard

Tab moves through the chevrons and checkboxes in order. Enter or Space on a chevron opens or closes its group; Space on a checkbox ticks or unticks it. Escape closes the open group you're in.

Accessibility

  • Label every chevron. Give CollapsibleTrigger a label such as "Show Maths assessments", and a title for its checkbox, such as "All Maths assessments".
  • Name every item. Give each item a title with its text, or it's named by its value.
  • Show hidden selections in text. Use a count Badge on closed groups, not colour alone.

Do's and Don'ts

    Do

    Show how many items are selected in a closed group.

    Don't

    Leave a closed group with no hint of what’s selected inside it.

    Do

    Use a tree for real levels, such as subjects and their assessments.

    Don't

    Use a tree for a flat list, such as five classes. Use Checkbox Group.

    Do

    Start with groups closed, so people can scan the top level.

    Don't

    Open every level of a long tree by default.

    Do

    Keep labels short enough to fit on one line.

    Don't

    Use long labels that get cut off.

Structure and spacing

PropertyTokenpxrem
Row height (minimum)size-832px2
Indent per levelspace-416px1
Space for chevronspace-1040px2.5
Checkbox to textspace-28px0.5

Options

OptionIn codeValuesDefault
Selected itemschecked, defaultCheckedA list of item valuesNone
On changeonCheckedChangeCalled with the new list of valuesNone
GroupCheckboxTree.CollapsibledefaultOpen, open to set its stateClosed
Parent rowCheckboxTree.CollapsibleTriggerlabel (chevron), title (checkbox)-
Group contentCheckboxTree.CollapsibleContentThe group's items and sub-groups-
ItemCheckboxTree.Itemvalue, title, disabled-

Related