enes

Tree View

The Tree View displays hierarchical data in a nested list where each item can be expanded, checked or selected. Items are composed with the TreeViewItem and TreeViewItemContent components — the tree does not accept a data prop.

  • Fruits
    • Apple
    • Banana
  • Vegetables

This component is available in early access.

The API, features, and behavior of the component are subject to significant changes. We strongly advise against using this component in production environments at this time.

Usage

<script>
	import { TreeView, TreeViewItem, TreeViewItemContent } from 'fluentui-svelte';
</script>

<TreeView selectionMode="multiple">
	<TreeViewItem id="fruits" type="branch">
		<TreeViewItemContent>Fruits</TreeViewItemContent>
		<TreeView>
			<TreeViewItem id="apple">
				<TreeViewItemContent>Apple</TreeViewItemContent>
			</TreeViewItem>
			<TreeViewItem id="banana" disabled>
				<TreeViewItemContent>Banana</TreeViewItemContent>
			</TreeViewItem>
		</TreeView>
	</TreeViewItem>
	<TreeViewItem id="vegetables">
		<TreeViewItemContent>Vegetables</TreeViewItemContent>
	</TreeViewItem>
</TreeView>

Nesting a TreeView inside a TreeViewItem of type='branch' creates a subtree. Use openItems / checkedItems on the root TreeView (bindable) to control open and checked state programmatically.

Checkable Items

Set selectionMode="multiple" to render checkboxes on selectable items.

  • Fruits
    • Apple
    • Banana

Controlling Open and Checked State

Use the bindable openItems and checkedItems props on the root TreeView to control state programmatically.

  • Fruits
    • Apple
    • Banana

Component Props (TreeView)

NameTypeDescription
refHTMLUListElementBindable DOM reference of the root ul element.
size'small' | 'medium' | 'large'Visual size of the tree. Default is 'medium'.
navigationMode'tree' | 'treegrid'Keyboard navigation mode. Default is 'tree'.
selectionMode'single' | 'multiple'Selection mode for checkable items. Default is 'multiple'.
openItemsstring[] | SvelteSet<string>Bindable list or set of open item ids. Uses SvelteSet when a virtualizer is provided.
checkedItemsstring[] | SvelteSet<string>Bindable list or set of checked item ids. Uses SvelteSet when a virtualizer is provided.
onOpenChange(e: Event, openItems: string[]) => voidCallback fired when an item is expanded or collapsed.
onCheckedChange(e: Event, checkedItems: string[]) => voidCallback fired when an item is checked or unchecked.
virtualizerTreeViewVirtualizerOptional adapter for windowing or virtual list libraries. When provided, only the rendered slice is in the DOM.
childrenSnippetThe TreeViewItem children of the tree.

Component Props (TreeViewItem)

NameTypeDescription
idstringUnique identifier of the item. Required for open and checked state tracking.
type'item' | 'branch'Whether the item is a leaf ('item') or a branch that can contain a nested TreeView.
refHTMLLIElementBindable DOM reference of the li element.
valuestring | numberOptional value associated with the item.
textstringOptional accessible text label used by the tree.
openbooleanBindable open state for type='branch' items.
checkedbooleanBindable checked state for selectable items.
indeterminatebooleanWhether the item is in an indeterminate check state.
disabledbooleanDisables the item.
indexnumberExplicit index — used with a virtualizer to keep keyboard navigation in sync.
onOpenChange(e: Event, data: { id: string; open: boolean }) => voidCallback fired when this item is expanded or collapsed.
onCheckedChange(e: Event, data: { id: string; checked: boolean }) => voidCallback fired when this item is checked or unchecked.

Component Props (TreeViewItemContent)

NameTypeDescription
refHTMLDivElementBindable DOM reference of the layout element.
expandIconSnippet | ComponentCustom icon rendered for the expand or collapse affordance.
iconBeforeSnippet | ComponentIcon rendered before the item text.
iconAfterSnippet | ComponentIcon rendered after the item text.
asideSnippet | ComponentContent rendered on the trailing side of the row.
actionsSnippet | ComponentInteractive actions rendered on hover or focus.
childrenSnippetThe item label content.