Sidebar for Slint
KitSidebar · Slint Kit 0.9.0
Application sidebar with sections, nested items, a current item and a collapsed icon rail.
The still preview and demo follow the documentation theme. You can change it before or during the demo.

This preview runs the actual Slint components and their Rust code compiled to WebAssembly. Slint draws the interface in the browser; the downloadable project compiles the same example into a native application for your platform.
Try the component
Download the complete project, extract it and run cargo run --locked in its folder. To add this component to an application, follow Project setup, then copy the two files below.
The kit supplies the component's behavior and styles; Rust callbacks connect its typed values to your application.
Choose a navigation item, expand Projects, then collapse the sidebar to its icon rail. The status reports the chosen label.
ui/app.slint
import { KitThemeContext } from "@kit";
import { InterFont } from "@kit-fonts/inter.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { LucideIcons } from "@kit-icons/all.slint";
import { KitSidebar, KitButton, SidebarRow, SidebarRowKind, KitTheme, KitThemes } from "@kit";
export component App inherits Window {
default-font-family: InterFont.family;
title: "KitSidebar example";
preferred-width: 640px;
preferred-height: 380px;
max-width: 100000px;
max-height: 100000px;
background: root.theme.canvas;
in-out property <KitTheme> theme: KitThemeContext.current;
in-out property <string> status: "No page chosen yet";
in-out property <bool> collapsed;
in property <[SidebarRow]> rows: [
{ item: { token: 1, generation: 1, label: "Workspace", description: "", disabled: false }, kind: SidebarRowKind.section, parent: { present: false, token: 0 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 2, generation: 1, label: "Dashboard", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.layout-dashboard(), badge: "" },
{ item: { token: 3, generation: 1, label: "Projects", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.folder(), badge: "" },
{ item: { token: 4, generation: 1, label: "Active", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: true, token: 3 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 5, generation: 1, label: "Archived", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: true, token: 3 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 6, generation: 1, label: "Settings", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.settings(), badge: "3" }
];
HorizontalLayout {
KitSidebar {
theme: root.theme;
rows: root.rows;
collapsed: root.collapsed;
accessible-name: "Main navigation";
chosen(row) => { root.status = "Current page: " + row.label; }
rail-parent-activated(row) => { root.collapsed = false; }
}
VerticalLayout {
padding: 24px;
spacing: 12px;
alignment: start;
KitButton { theme: root.theme; text: root.collapsed ? "Expand the sidebar" : "Collapse to icons"; activated => { root.collapsed = !root.collapsed; } }
Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; }
}
}
}
src/main.rs
// SPDX-License-Identifier: GPL-3.0-or-later
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError> {
let app = App::new()?;
slint_kit::install(&app);
app.run()
}
Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs
Pass rows as a flat model of SidebarRow, one generation for all rows, and handle chosen(OptionRow) for a destination. Choices<K> does not model nesting: keep the token of each row in your own table and map it back in chosen. Call slint_kit::install once per window. Bind current and expanded with <=> to keep them in your state, or set ownership to controlled and drive them from the callbacks. Place the sidebar in a HorizontalLayout: its width comes from the theme and text scale (KitMetrics.sidebar-width), or KitMetrics.sidebar-rail-width when collapsed.
Activating an item makes it current and emits chosen(OptionRow). Activating a parent (an item that has nested items) opens or closes it and emits expansion-requested(OptionRow, bool); a parent is not a destination. Collapsed to the rail, a parent emits rail-parent-activated(OptionRow) instead and changes nothing, so the host can expand the sidebar. The sidebar is one tab stop. Up, Down, Home, End, PageUp, PageDown and typeahead move the active row, skipping section headings and disabled items; Enter or Space activates it; Right opens a parent and then moves into it; Left closes an open parent. No tooltip names the icons in the rail: give each icon item a label, which is its accessible name. Sections and nested items have no place in the rail, and there is no flyout for nested items.
Control accessibility
Rows use the list and list-item roles of KitMenu, because this SDK has no navigation or tree roles. The current item is reported as selected, a parent as expandable with its expanded state, and each row with its index among the rows shown. Section headings are plain text. Slint 1.18.1 cannot move assistive focus to the active row, and has no aria-current attribute: selection is the closest mark. Headless tests do not qualify VoiceOver, NVDA or physical IME.
Visual composition
The file below describes the captured scene. For controller-driven components, it shows the displayed state without supplying the Rust wiring. Create a project.
Show the screenshot source

import { InterFont } from "@kit-fonts/inter.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { LucideIcons } from "@kit-icons/all.slint";
import { KitSidebar, KitButton, SidebarRow, SidebarRowKind, KitTheme, KitThemes } from "@kit";
export component Example inherits Window {
default-font-family: InterFont.family;
title: "KitSidebar example";
preferred-width: 640px;
preferred-height: 380px;
max-width: 100000px;
max-height: 100000px;
background: root.theme.canvas;
in-out property <KitTheme> theme: KitThemes.light;
in-out property <string> status: "No page chosen yet";
in-out property <bool> collapsed;
in property <[SidebarRow]> rows: [
{ item: { token: 1, generation: 1, label: "Workspace", description: "", disabled: false }, kind: SidebarRowKind.section, parent: { present: false, token: 0 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 2, generation: 1, label: "Dashboard", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.layout-dashboard(), badge: "" },
{ item: { token: 3, generation: 1, label: "Projects", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.folder(), badge: "" },
{ item: { token: 4, generation: 1, label: "Active", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: true, token: 3 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 5, generation: 1, label: "Archived", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: true, token: 3 }, leading-icon: { stroke: "", fill: "", viewbox: 24 }, badge: "" },
{ item: { token: 6, generation: 1, label: "Settings", description: "", disabled: false }, kind: SidebarRowKind.item, parent: { present: false, token: 0 }, leading-icon: LucideIcons.settings(), badge: "3" }
];
HorizontalLayout {
KitSidebar {
theme: root.theme;
rows: root.rows;
collapsed: root.collapsed;
accessible-name: "Main navigation";
chosen(row) => { root.status = "Current page: " + row.label; }
rail-parent-activated(row) => { root.collapsed = false; }
}
VerticalLayout {
padding: 24px;
spacing: 12px;
alignment: start;
KitButton { theme: root.theme; text: root.collapsed ? "Expand the sidebar" : "Collapse to icons"; activated => { root.collapsed = !root.collapsed; } }
Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; }
}
}
}
Public API
Inherits Rectangle.
Properties
The "Default" column repeats the initializer declared in the source; "—" is the zero value of the type, and a composite expression points to the source.
| Name | Type | Direction | Default |
|---|---|---|---|
modal-layer |
int |
in |
— |
interactive |
bool |
in |
true |
theme |
KitTheme |
in |
KitThemeContext.current |
control-size |
ControlSize |
in |
ControlSize.medium |
rows |
[SidebarRow] |
in |
— |
collapsed |
bool |
in |
— |
accessible-name |
string |
in |
"Sidebar" |
row-height |
length |
in |
KitMetrics.row-height(root.theme, root.control-size) |
ownership |
Ownership |
in |
Ownership.local |
current |
SelectionRef |
in-out |
— |
expanded |
[SelectionRef] |
in-out |
— |
shown-rows |
[SidebarVisibleRow] |
out |
— |
state |
SelectState |
out |
— |
has-focus |
bool |
out |
— |
page-rows |
int |
out |
— |
Property details
Effect, default, states and constraints of the central properties, with a snippet that uses public mechanisms. Inherited properties carry the explanation of the component that declares them. The complete typed example and the Forms guide wire these properties end to end.
modal-layer
The modal layer this component belongs to; 0 is the window. While a KitDialogSurface or KitDrawer with a positive modal-layer is open and topmost, the sidebar is inert. Give a sidebar placed inside a modal that modal's layer number.
- Default
0(window).
KitSidebar {
modal-layer: 1;
}
interactive
When false the sidebar and its rows ignore pointer, keys and assistive actions.
- Default
true.
interactive: false;
control-size
Density of the rows, from the theme: compact, medium or comfortable.
control-size: ControlSize.compact;
rows
The flat model in reading order: SidebarRow with item (an OptionRow: stable token, one generation for the whole model, label, disabled), kind (SidebarRowKind.section for a heading, item for a destination), parent (a SelectionRef; set it to nest an item under another item by token), leading-icon and badge. A section ignores parent; an unknown parent, a section as parent or a cycle leaves the item at the top level.
rows: root.rows;
collapsed
Collapses the sidebar to its icon rail. Sections and nested items are hidden, each top-level item shows its icon only, and the open state of parents is kept for when the sidebar expands again. An item without an icon shows its label, elided, in the rail.
- Default
false.
collapsed: root.rail;
accessible-name
The accessible name of the list of rows.
accessible-name: "Main navigation";
row-height
Height of every row, section headings included.
row-height: 40px;
ownership
Who owns current and expanded: Ownership.local (the default) updates them itself, Ownership.controlled only reports chosen and expansion-requested and waits for the host.
- Default
Ownership.local.
ownership: Ownership.controlled;
current
The current page, as a SelectionRef. The current item is tinted and reported as selected to assistive technology. Under Ownership.local activating an item sets it; under Ownership.controlled set it from chosen.
current <=> root.page;
expanded
The tokens of the open parents. Under Ownership.local activating a parent updates it; under Ownership.controlled update it from expansion-requested.
expanded <=> root.open-parents;
shown-rows
The rows on screen, each a SidebarVisibleRow with its depth, expandable and expanded state. It follows collapsed and expanded.
out property <int> count: sidebar.shown-rows.length;
has-focus
True while the sidebar owns keyboard focus.
out property <bool> sidebar-focused: sidebar.has-focus;
Types and variants
| Type | Declaration |
|---|---|
enum ControlSize |
compact, medium, comfortable |
struct OptionRow |
token: int, generation: int, label: string, description: string, disabled: bool |
enum Ownership |
local, controlled |
enum SelectionAvailability |
absent, available, unavailable |
struct SelectionRef |
present: bool, token: int |
struct SelectState |
selection-availability: SelectionAvailability, selected: SelectionRef, active: SelectionRef, open: bool, active-index: int, generation: int |
struct SidebarRow |
item: OptionRow, kind: SidebarRowKind, parent: SelectionRef, leading-icon: IconGlyph, badge: string |
enum SidebarRowKind |
section, item |
struct SidebarVisibleRow |
row: SidebarRow, depth: int, expandable: bool, expanded: bool |
Callbacks
chosen(OptionRow)— A destination was activated. The argument is itsOptionRow; map itstokenback to your own key.expansion-requested(OptionRow, bool)— A parent was activated or opened with Right or closed with Left. The arguments are itsOptionRowand whether it should be open.rail-parent-activated(OptionRow)— A parent was activated while the sidebar is collapsed. Typically setcollapsedto false.focus-observed(bool)— Keyboard focus entered or left the sidebar.
Functions
take-focus()ensure-active-visible()