enes

Tree View Experimental

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

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)

NameTypeDefaultDescription
ref bindableHTMLUListElementThe DOM reference of the tree element.
size'small' | 'medium' | 'large''medium'The size of every item in the tree.
navigationMode'tree' | 'treegrid''tree'Whether the tree takes a single tab stop, or every row is reachable on its own.
onOpenChange(e: Event, openItems: string[]) => voidCalled whenever a branch opens or closes.
selectionMode'single' | 'multiple''multiple'How many items can be checked at a time.
onCheckedChange(e: Event, checkedItems: string[]) => voidCalled whenever an item is checked or unchecked.
virtualizerTreeViewVirtualizerBridge to a windowing library. Only the rendered slice of items lives in the DOM.
openItems bindablestring[] | SvelteSet<string>The ids of the open branches. A `SvelteSet` is required when a `virtualizer` is set.
checkedItems bindablestring[] | SvelteSet<string>The ids of the checked items. A `SvelteSet` is required when a `virtualizer` is set.
childrenSnippetThe items of the tree.
TreeViewVirtualProps | TreeViewStaticProps
Element Attributes (ul)

Component Props (TreeViewItem)

NameTypeDefaultDescription
idstringThe id of the item, used by the tree to track its state. Falls back to a generated id.
type'item' | 'branch''item'Whether the item holds children, and can therefore be opened.
refHTMLLIElementThe DOM reference of the item element.
valuestring | numberidThe value reported by the tree events. Falls back to the id of the item.
textstringThe label of the item, used by the type-ahead navigation.
openbooleanWhether the branch is open.
checkedbooleanWhether the item is checked.
indeterminatebooleanRenders the checkbox in its mixed state, when only some children are checked.
disabledbooleanDisables the user interaction.
indexnumberThe real index of the item in the data set. Required when the tree is virtualized.
onOpenChange(e: Event, data: { id: string; open: boolean }) => voidCalled when this branch opens or closes.
onCheckedChange(e: Event, data: { id: string; checked: boolean }) => voidCalled when this item is checked or unchecked.
Element Attributes (li)

Component Props (TreeViewItemContent)

NameTypeDefaultDescription
refHTMLDivElementThe DOM reference of the layout element.
expandIconSnippet | ComponentCustom icon for the control that opens a branch.
iconBeforeSnippet | ComponentContent rendered before the label.
iconAfterSnippet | ComponentContent rendered after the label.
asideSnippet | ComponentContent pinned to the end of the row.
actionsSnippet | ComponentContent pinned to the end of the row, revealed on hover and on focus.
Element Attributes (div)