Skip to main content

Examples

Every example is live and its source is shown below it. The same examples are available as interactive stories with editable props in the Storybook playground.

Basic props​

This example combines a few behavior props on a tree where Child 1 is disabled:

  • defaultExpanded: every node starts expanded
  • chainedSelect={false}: each node is selected individually
  • expandDisabledNodes={false}: disabled nodes can't be expanded or collapsed
Root 1
Child 1
Grandchild 1
Grandchild 2
Child 2
Root 2
Child 3
Child 4
Show code
BasicPropsExample.tsx
import TreeSelect from '@attebyte/react-tree-select';
import { exampleDataWithDisabled, ExampleNode } from './data';

// defaultExpanded: all nodes start expanded
// chainedSelect={false}: each node is selected individually
// expandDisabledNodes={false}: disabled nodes can't be expanded or collapsed
export default function BasicPropsExample() {
return (
<TreeSelect<ExampleNode>
defaultData={exampleDataWithDisabled}
uniqueIDProperty='value'
labelProperty='label'
childrenProperty='children'
valueProperty='included'
disabledProperty='disabled'

defaultExpanded
chainedSelect={false}
expandDisabledNodes={false}

className='bg-neutral-800 text-white p-6 rounded font-sans'
aria-label='Basic props example'
/>
);
}

Because the nodes start expanded, the disabled Child 1 stays expanded. With chainedSelect turned off, the children of a disabled node can still be selected, which is useful when selecting a parent isn't meaningful.