Class Sidebar
A labelled, sectioned vertical navigation surface — the left nav of an app shell.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Sidebar : SidebarSlot, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
Sidebar is a compound component. It is a bordered column on its own and gets its structure from the sub-elements you compose into it: SidebarHeader, SidebarContent (holding SidebarSections of SidebarItems) and SidebarFooter. Every part is optional.
It is wider and text-first, unlike the icon-only BottomNavBar, and it owns a single-selection group: any SidebarItem carrying a value participates, and activating one sets selectedId and raises selectionChanged. Items with no value are plain action buttons and never change the selection.
Width is not a design token. The registry's sidebar is w-60 (240px) and the App UI sizing
ramp tops out well below that, so width is a plain pixel property with the
registry's default rather than a fabricated token. Everything else — padding, gaps, colours,
radii — comes from --appui-* tokens and rescales with Panel.density.
UI Toolkit has no gap, so the vertical rhythm is a leading margin on every child with the
first one tagged firstChildUssClassName; SidebarSlot keeps
those markers fresh on every layout pass.
Examples
An app shell nav composed in UXML.
<appui:Sidebar selected-id="assets">
<appui:SidebarHeader>
<appui:Text text="My Project" />
</appui:SidebarHeader>
<appui:SidebarContent>
<appui:SidebarSection heading="Workspace">
<appui:SidebarItem value="assets" label="Assets" icon="folder" />
<appui:SidebarItem value="scenes" label="Scenes" icon="stack" shortcut="Ctrl+2" />
</appui:SidebarSection>
</appui:SidebarContent>
<appui:SidebarFooter>
<appui:SidebarItem label="Settings" icon="gear" />
</appui:SidebarFooter>
</appui:Sidebar>
Reacting to the selection in C#.
var sidebar = new Sidebar { selectedId = "assets" };
sidebar.selectionChanged += id => Debug.Log($"navigate to {id}");
var content = new SidebarContent();
var section = new SidebarSection ;
section.Add(new SidebarItem { value = "assets", label = "Assets", icon = "folder" });
section.Add(new SidebarItem { value = "scenes", label = "Scenes", icon = "stack" });
content.Add(section);
sidebar.Add(content);
Constructors
Sidebar()
Default constructor.
Declaration
public Sidebar()
Fields
defaultWidth
The default width of a Sidebar, in pixels.
Declaration
public const float defaultWidth = 240
Field Value
| Type | Description |
|---|---|
| float |
Remarks
This mirrors the registry's w-60. It is deliberately a literal and not a token: the App UI
sizing ramp has no step this wide.
ussClassName
The Sidebar main styling class.
Declaration
public const string ussClassName = "appui-sidebar"
Field Value
| Type | Description |
|---|---|
| string |
Properties
selectedId
The value of the currently selected item, or null when nothing
is selected.
Declaration
[Tooltip("The value of the currently selected SidebarItem.")]
[CreateProperty]
[UxmlAttribute]
public string selectedId { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Setting this re-tags every descendant item, so it is safe to set before or after the items have been added.
width
The width of the Sidebar, in pixels. Defaults to defaultWidth.
Declaration
[Tooltip("The width of the Sidebar, in pixels.")]
[CreateProperty]
[UxmlAttribute]
public float width { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
OnSlotLayout()
Called after the child markers have been refreshed, on attach and on every layout change.
Declaration
protected override void OnSlotLayout()
Overrides
RefreshSelection()
Re-applies the active state to every SidebarItem in this Sidebar.
Declaration
public void RefreshSelection()
Remarks
This runs automatically when selectedId changes and on every layout pass. Call it directly only if you mutate the item tree and need the state before the next layout.
Events
selectionChanged
Raised with the value of an item the user has just activated.
Declaration
public event Action<string> selectionChanged
Event Type
| Type | Description |
|---|---|
| Action<string> |
Remarks
Only items carrying a value raise this. It fires on user activation, not when selectedId is set programmatically.