API reference: @salmonui/navigation/tree-view
TreeViewcomponent
import { TreeView } from '@salmonui/navigation/tree-view';function TreeView<T>(props: TreeViewProps<T>): ReactNode;
A hierarchical list (WAI-ARIA APG Tree View) over data, virtualized by
default. ref receives the TreeViewApi.
Props: TreeViewProps
| Name | Signature | Description |
|---|---|---|
data | readonly data: readonly T[]; | Root items. Nested with |
getItemId | readonly getItemId: (item: T) => TreeViewKey; | Stable, unique id of an item (duplicates log a development warning). |
getItemLabeloptional | readonly getItemLabel?: ((item: T) => string) | undefined; | Accessible name, typeahead and sort text. Default: |
getChildrenoptional | readonly getChildren?: ((item: T) => readonly T[] | null | undefined) | undefined; | |
getParentIdoptional | readonly getParentId?: ((item: T) => TreeViewKey | null | undefined) | undefined; | Flat data: the parent id (null or an unknown id makes a root). |
hasChildrenoptional | readonly hasChildren?: ((item: T) => boolean) | undefined; | Shows the expand twisty before children are known; expanding then calls |
loadChildrenoptional | readonly loadChildren?: ((item: T, options: {
readonly signal: AbortSignal;
}) => Promise<readonly T[]>) | undefined; | Loads the children of an item on its first expand. Reject to show the error state. |
onLoadErroroptional | readonly onLoadError?: ((error: unknown, item: T, id: TreeViewKey) => void) | undefined; | |
isItemDisabledoptional | readonly isItemDisabled?: ((item: T) => boolean) | undefined; | |
getItemIconoptional | readonly getItemIcon?: ((item: T) => ReactNode) | undefined; | |
getItemHrefoptional | readonly getItemHref?: ((item: T) => string | undefined) | undefined; | The label renders as a link; a click anywhere on the row follows it. |
renderLinkoptional | readonly renderLink?: ((props: TreeViewLinkProps, item: T) => ReactNode) | undefined; | Renders link items with another element (a router link); spread the props. |
getItemPropsoptional | readonly getItemProps?: ((item: T, context: TreeViewItemContext<T>) => (HTMLAttributes<HTMLElement> & Record<`data-${string}`, string | undefined>) | undefined) | undefined; | Extra props for a rendered row ( |
renderItemoptional | readonly renderItem?: ((context: TreeViewItemContext<T>) => ReactNode) | undefined; | Replaces the label content of a rendered row (inside the link with |
selectionoptional | readonly selection?: 'none' | 'single' | 'multiple' | undefined; | Default |
selectedoptional | readonly selected?: readonly TreeViewKey[] | undefined; | Selected ids (reactive: applied when the array identity changes). |
onBeforeSelectedChangeoptional | readonly onBeforeSelectedChange?: ((event: TreeViewBeforeSelectedChangeEvent<T>) => void) | undefined; | |
onSelectedChangeoptional | readonly onSelectedChange?: ((event: TreeViewSelectedChangeEvent<T>) => void) | undefined; | |
expandedoptional | readonly expanded?: readonly TreeViewKey[] | undefined; | Expanded ids (reactive). |
onBeforeExpandedChangeoptional | readonly onBeforeExpandedChange?: ((event: TreeViewBeforeExpandedChangeEvent<T>) => void) | undefined; | |
onExpandedChangeoptional | readonly onExpandedChange?: ((event: TreeViewExpandedChangeEvent<T>) => void) | undefined; | |
expandOnoptional | readonly expandOn?: 'auto' | 'click' | 'doubleClick' | 'none' | undefined; | What toggles a parent besides its twisty. |
checkableoptional | readonly checkable?: boolean | undefined; | Shows tri-state checkboxes ( |
checkedoptional | readonly checked?: readonly TreeViewKey[] | undefined; | Checked ids (reactive). |
defaultCheckedoptional | readonly defaultChecked?: readonly TreeViewKey[] | undefined; | Initial checked ids when |
onBeforeCheckedChangeoptional | readonly onBeforeCheckedChange?: ((event: TreeViewBeforeCheckedChangeEvent<T>) => void) | undefined; | |
onCheckedChangeoptional | readonly onCheckedChange?: ((event: TreeViewCheckedChangeEvent<T>) => void) | undefined; | |
checkPropagationoptional | readonly checkPropagation?: 'cascade' | 'none' | undefined; | Default |
cascadeToDisabledoptional | readonly cascadeToDisabled?: boolean | undefined; | Default true: a cascade also changes disabled descendants. |
checkOnClickoptional | readonly checkOnClick?: boolean | undefined; | A click on the row toggles its check. |
nameoptional | readonly name?: string | undefined; | Form field name: one hidden input per checked id. |
formoptional | readonly form?: string | undefined; | Associates the hidden inputs with a form by id. |
renamableoptional | readonly renamable?: boolean | undefined; | F2 or |
onBeforeRenameoptional | readonly onBeforeRename?: ((event: TreeViewBeforeRenameEvent<T>) => void) | undefined; | |
onRenameoptional | readonly onRename?: ((event: TreeViewRenameEvent<T>) => void) | undefined; | |
draggableoptional | readonly draggable?: boolean | undefined; | Pointer drag and drop (lazy chunk) and keyboard moves (Alt + arrows). |
dragGroupoptional | readonly dragGroup?: string | undefined; | Trees with the same group exchange items. |
onBeforeMoveoptional | readonly onBeforeMove?: ((event: TreeViewBeforeMoveEvent<T>) => void) | undefined; | |
onMoveoptional | readonly onMove?: ((event: TreeViewMoveEvent<T>) => void) | undefined; | |
onItemClickoptional | readonly onItemClick?: ((event: TreeViewItemClickEvent<T>) => void) | undefined; | |
onKeyDownoptional | readonly onKeyDown?: ((event: KeyboardEvent<HTMLDivElement>) => void) | undefined; | Runs before the built-in keys; |
sortoptional | readonly sort?: 'asc' | 'desc' | null | undefined; | Siblings sorted by |
localeoptional | readonly locale?: string | undefined; | Collator and plural locale. Default: the document language. |
heightoptional | readonly height?: number | string | undefined; | Height of the scroll box (px or CSS length). The server renders the rows that fit a number. |
virtualizeoptional | readonly virtualize?: boolean | undefined; | Default true: only the rows in view are rendered. |
textWrapoptional | readonly textWrap?: boolean | undefined; | Labels wrap; row heights are measured. |
rowHighlightoptional | readonly rowHighlight?: 'full' | 'label' | undefined; | Default |
disabledoptional | readonly disabled?: boolean | undefined; | |
localeTextoptional | readonly localeText?: Partial<TreeViewLocaleText> | undefined; | |
classNameoptional | readonly className?: string | undefined; | |
styleoptional | readonly style?: CSSProperties | undefined; | |
refoptional | readonly ref?: Ref<TreeViewApi<T>> | undefined; |