enes

SideNav

Collapsible app navigation with a docked icon rail, a floating panel, nested links, custom content and a pinned footer.

Usage

Place SideNav and AppSurface directly inside AppWindow, after an optional TitleBar. Items are links by default; use as="button" for actions and set active from your router. SideNav also works on its own, in any container with a height.

<script>
	import { AppWindow, AppSurface, SideNav, SideNavItem } from 'fluentui-svelte';
	import { HomeRegular, FolderRegular, SettingsRegular } from 'fluentui-icons-svelte';
</script>

<AppWindow width={480} height={240}>
	<SideNav header="Workspace">
		<SideNavItem href="#home" label="Home" icon={HomeRegular} active />
		<SideNavItem href="#documents" label="Documents" icon={FolderRegular} />
		<SideNavItem href="#settings" label="Settings" icon={SettingsRegular} />
	</SideNav>
	<AppSurface style="padding: 1rem">Page content</AppSurface>
</AppWindow>

Collapsed rail

Bind collapsed to expand and collapse the navigation. Docked, a collapsed SideNav keeps a rail with the icon of every item; an item without an icon shows its initial.

Floating navigation

With floating, the navigation overlays its positioned parent instead of taking up space, and only the hamburger remains while it is closed. Escape, a click outside, moving the focus away or activating an item closes it; set closeOnSelect to false to keep it open after activating an item.

Page content

Position

position places the navigation on the left, the default, or on the right of the window. AppSurface follows it: it rounds the corners that face the navigation. It also applies to a floating navigation, which opens from that edge, and it mirrors in right-to-left layouts.

With a title bar

The global navigation button of TitleBarLeftControls controls the SideNav of the same AppWindow, and takes the place of its hamburger. Set showToggle on the SideNav to show both.

Workspace

Nested navigation and footer

SideNavBranch nests items under a disclosure, and the footer snippet pins items to the bottom. Opening a branch from the rail expands the navigation first. listViewProps customizes every list of the navigation, and selectedItems can be bound when selection is enabled.

Custom content and menus

topContent goes between the hamburger and the list, and footerContent after it. Each takes text, a snippet or a component; renderers receive collapsed and floating, and plain text is hidden in the rail.

Component Props (SideNav)

NameTypeDefaultDescription
ref bindableHTMLElement | nullThe DOM reference of the navigation landmark.
labelstring'Main navigation'The accessible name of the navigation landmark.
collapsed bindablebooleanfalseShows an icon rail when docked, or only the toggle when floating.
position'left' | 'right''left'The side of the window the navigation is on. It mirrors in right-to-left layouts, and AppSurface rounds the corners that face it.
showTogglebooleanAutomaticWhether the navigation shows its own hamburger toggle. By default it hides it when the title bar of its window has a global navigation button, which then controls the navigation. Set it to true to keep both, or to false to control the navigation yourself.
floatingbooleanfalseOverlays the content of a positioned parent instead of taking layout space. The overlay is non-modal.
widthnumber | string200The expanded width. Numbers are pixels converted to rem; strings are CSS lengths.
expandLabelstring'Expand navigation'The accessible label of the toggle while collapsed.
collapseLabelstring'Collapse navigation'The accessible label of the toggle while expanded.
closeOnSelectbooleantrueCloses a floating panel after activating a SideNavItem.
onCollapsedChange(event: Event, collapsed: boolean) => voidCalled when the user expands or collapses the navigation.
selectedItems bindablestring[]The selection shared by every list in the navigation. Selection is off by default.
listViewPropsSideNavListViewPropsOverrides the defaults of every list in the navigation, the main one, the footer and the ones inside a SideNavBranch: native list semantics, no selection and one tab stop per item.
headerstringThe text heading beside the hamburger button. Hidden in the compact rail.
topContentstring | Snippet | ComponentCustom content between the hamburger section and the list. Text, snippets and components are supported. Renderers receive collapsed and floating; strings are hidden in the compact rail.
footerContentstring | Snippet | ComponentCustom content after the scrolling list and before the pinned footer. Text, snippets and components are supported. Renderers receive collapsed and floating; strings are hidden in the compact rail.
footerSnippetFooter list items pinned to the bottom, outside the main list's scroll area.
childrenSnippetMain navigation items. Use SideNavItem and SideNavBranch.
HTMLAttributes<HTMLElement> without children

Component Props (SideNavItem)

NameTypeDefaultDescription
as'li' | 'a' | 'button' | 'div''a'The HTML tag. Links are the default; use button for actions and li or div for custom controls.
ref bindableHTMLLIElement | HTMLAnchorElement | HTMLButtonElement | HTMLDivElementThe DOM reference of the item.
labelstringThe accessible label, also used as visible content when children are absent.
iconSnippet | ComponentThe decorative icon shown in both expanded and collapsed modes.
childrenSnippetOptional item markup, following ListViewItem. The label is rendered when children are absent.
shape, value, active, role, disabled, checkmark, onAction, onfocus from ListViewItemProps
HTML Attributes

Component Props (SideNavBranch)

NameTypeDefaultDescription
labelstringThe accessible label of the disclosure button. In the compact rail, its initial stands in when there is no icon.
iconSnippet | ComponentThe decorative icon before the label.
expanded bindablebooleanfalseWhether the nested items are visible. Branches only expand or collapse and are never selectable. The compact rail reports a branch as collapsed, and opens the navigation when one is pressed.
onExpandedChange(e: Event, expanded: boolean) => voidCalled when a user expands or collapses the branch.
disabledbooleanfalseDisables the disclosure button.
ref bindableHTMLButtonElementThe DOM reference of the native disclosure button. Additional HTML attributes, including class and id, also target this button.
wrapperRef bindableHTMLLIElement | HTMLDivElementThe DOM reference of the wrapper element, the list item that holds the button and the nested list.
wrapperAttributesHTMLAttributesThe attributes to spread on the wrapper element.
shapeListViewItemBranchProps['shape']The disclosure button shape. Inherited from the list by default.
childrenSnippetThe nested SideNavItem and SideNavBranch content.
HTMLButtonAttributes without children, role, type, value, aria-expanded, aria-controls
Edit this Doc View as Markdown