| 1 |
--- |
| 2 |
id: Tree view |
| 3 |
section: components |
| 4 |
cssPrefix: pf-v6-c-tree-view |
| 5 |
propComponents: ['TreeView', 'TreeViewDataItem', 'TreeViewSearch'] |
| 6 |
--- |
| 7 |
|
| 8 |
import { Fragment, useEffect, useState } from 'react'; |
| 9 |
import { FolderIcon, FolderOpenIcon, RhUiEllipsisVerticalFillIcon, HamburgerIcon, GitlabIcon, GithubIcon, GoogleIcon, RhUiClipboardFillIcon, RhUiStorageFillIcon } from '@patternfly/react-icons'; |
| 10 |
|
| 11 |
## Examples |
| 12 |
|
| 13 |
### Single selectable |
| 14 |
|
| 15 |
```ts file='./TreeViewSingleSelectable.tsx' |
| 16 |
|
| 17 |
``` |
| 18 |
|
| 19 |
### Multiselectable |
| 20 |
|
| 21 |
A tree view can be setup to allow multiple nodes to be selected. When a tree view is intended to allow multiple selection, the `isMultiSelectable` property must be passed. |
| 22 |
|
| 23 |
```ts file='./TreeViewMultiselectable.tsx' |
| 24 |
|
| 25 |
``` |
| 26 |
|
| 27 |
### With separate selection and expansion |
| 28 |
|
| 29 |
The `hasSelectableNodes` modifier will separate the expansion and selection behaviors, allowing a parent node to be selected or deselected without toggling its expansion. |
| 30 |
|
| 31 |
```ts file='./TreeViewSelectionExpansion.tsx' |
| 32 |
|
| 33 |
``` |
| 34 |
|
| 35 |
### With search |
| 36 |
|
| 37 |
A search input can be used to filter tree view items. It is recommended that a tree view with more than 7 nodes includes a search input. |
| 38 |
|
| 39 |
```ts file='./TreeViewWithSearch.tsx' |
| 40 |
|
| 41 |
``` |
| 42 |
|
| 43 |
### With checkboxes |
| 44 |
|
| 45 |
```ts file='./TreeViewWithCheckboxes.tsx' |
| 46 |
|
| 47 |
``` |
| 48 |
|
| 49 |
### With icons |
| 50 |
|
| 51 |
```ts file='./TreeViewWithIcons.tsx' |
| 52 |
|
| 53 |
``` |
| 54 |
|
| 55 |
### With unique icon per item |
| 56 |
|
| 57 |
```ts file='./TreeViewWithIconPerItem.tsx' |
| 58 |
|
| 59 |
``` |
| 60 |
|
| 61 |
### With badges |
| 62 |
|
| 63 |
```ts file='./TreeViewWithBadges.tsx' |
| 64 |
|
| 65 |
``` |
| 66 |
|
| 67 |
### With custom badges |
| 68 |
|
| 69 |
```ts file='./TreeViewWithCustomBadges.tsx' |
| 70 |
|
| 71 |
``` |
| 72 |
|
| 73 |
### With action items |
| 74 |
|
| 75 |
```ts file='./TreeViewWithActionItems.tsx' |
| 76 |
|
| 77 |
``` |
| 78 |
|
| 79 |
### Guides |
| 80 |
|
| 81 |
```ts file='./TreeViewGuides.tsx' |
| 82 |
|
| 83 |
``` |
| 84 |
|
| 85 |
### Compact |
| 86 |
|
| 87 |
```ts file='./TreeViewCompact.tsx' |
| 88 |
|
| 89 |
``` |
| 90 |
|
| 91 |
### Compact, no background |
| 92 |
|
| 93 |
```ts file='./TreeViewCompactNoBackground.tsx' |
| 94 |
|
| 95 |
``` |
| 96 |
|
| 97 |
### With memoization |
| 98 |
|
| 99 |
Turning on memoization with the `useMemo` property helps prevent unnecessary re-renders for large data sets. With this flag active, `activeItems` must pass in an array of nodes along the selected item's path to update properly. |
| 100 |
|
| 101 |
```ts file='./TreeViewWithMemoization.tsx' |
| 102 |
|
| 103 |
``` |