Tree select

Picks from nested options, like a team inside a department.

import { TreeSelect } from '@halo-ds/react';

When to use it

Use a Tree on its own for browsing, like a file list, or for picking several with checkboxes, like permissions for a role. Use Tree select to pick from nested options in a form, like a team inside a department.

Do

  • Open the branch that holds the current or chosen item.
  • Use icons to tell folders from files.
  • Use checkboxes when people pick several; let branches pick everything inside.
  • Turn on search in Tree select when the tree is long.

Don't

  • Nest deeper than four levels; split it into pages instead.
  • Use a Tree for a flat list.
  • Hide actions people need inside closed branches.
  • Mix checkboxes and single picking in one tree.

Props

TreeSelect props

PropTypeWhat it does
multiple`false \undefined`
value`string \null \undefined`
defaultValue`string \null \undefined`
onValueChange`((value: string) => void) \undefined`
nodes (required)TreeNode[]
placeholder`string \undefined`
search`boolean \undefined`Shows a search box above the tree. Figma: Search.
defaultExpanded`string[] \undefined`Branches open when the tree first shows.
iconReactNodeIcon at the start of the box. Figma: L icon.
size`"sm" \"md" \"lg" \undefined`32, 40 or 48px. Figma: Size.
invalid`boolean \undefined`
disabled`boolean \undefined`
name`string \undefined`Form field name. A hidden input carries the value; several values are joined with commas.
id`string \undefined`
aria-label`string \undefined`
aria-describedby`string \undefined`
aria-invalid`true \undefined`
required`boolean \undefined`
className`string \undefined`
classNames`Partial<Record<TreeSelectPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<TreeSelectPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

Examples

Overview

import { TreeSelect } from '@halo-ds/react';

const teams = [
  { id: 'product', label: 'Product', children: [{ id: 'design', label: 'Design' }, { id: 'research', label: 'Research' }] },
  { id: 'operations', label: 'Operations', children: [{ id: 'finance', label: 'Finance' }, { id: 'people', label: 'People' }] },
];

export default function Example() {
  return (
    <div style={{ display: 'grid', alignContent: 'start', gap: 20, width: 320, minHeight: 280 }}>
      <TreeSelect nodes={teams} placeholder="Choose a team" aria-label="Team" />
      <TreeSelect nodes={teams} multiple search placeholder="Choose teams" aria-label="Teams" />
    </div>
  );
}

Field

With a label and a hint, and the error state.

import { TreeSelectField } from '@halo-ds/react';

const teams = [
  { id: 'product', label: 'Product', children: [{ id: 'design', label: 'Design' }, { id: 'research', label: 'Research' }] },
  { id: 'operations', label: 'Operations', children: [{ id: 'finance', label: 'Finance' }, { id: 'people', label: 'People' }] },
];

export default function Demo() {
  return (
    <div className="demo-stack" style={{ width: 320 }}>
      <TreeSelectField label="Team" hint="Where this person works." nodes={teams} placeholder="Choose a team" search />
      <TreeSelectField label="Team" error="Choose a team." nodes={teams} placeholder="Choose a team" />
    </div>
  );
}

More: https://halodesignsystem.dev/components/tree-select