GlassSidebar
NavigationSplitView sidebar with sections, selection, search and adaptive collapse.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-sidebar
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-sidebarCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-sidebar |
|---|---|
| Module | SPGlassNavigation |
| Kind | native-wrapper — a NavigationSplitView whose sidebar is a system List with .searchable |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Navigation/GlassSidebarExample.swift |
Minimal usage
@State private var selection: String?
GlassSidebar("Mail", sections: [
GlassSidebarSection(id: "boxes", title: "Mailboxes", items: [
GlassSidebarItem(id: "inbox", title: "Inbox", systemImage: "tray", badge: 12),
GlassSidebarItem(id: "sent", title: "Sent", systemImage: "paperplane"),
]),
], selection: $selection) { id in
if let id { MailboxView(id: id) } else { Text("Select a mailbox") }
}Variants
| Variant | Use |
|---|---|
Section with title: nil | Rows without a header. |
badge: | Count at the trailing edge of a row; zero shows nothing. |
keywords: | Extra words the search matches (synonyms, translations). |
isSearchable: false | No search field. |
columnVisibility: | Collapse or show the sidebar from code. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title | LocalizedStringKey | — | Title of the sidebar column. |
sections | [GlassSidebarSection<ID>] | — | Rows, grouped. |
selection | Binding<ID?> | — | Selected row. |
searchText | Binding<String>? | nil | Search text when the host needs it; otherwise owned by the sidebar. |
columnVisibility | Binding<NavigationSplitViewVisibility>? | nil | Sidebar visibility when the host drives it. |
isSearchable | Bool | true | Adds the system search field (placement: .sidebar). |
searchPrompt | LocalizedStringKey? | "Search" | Placeholder of the search field. |
detail | (ID?) -> Detail | — | Detail column for the selection. |
States
Selected row: selection. Searching: rows are filtered by GlassSidebarFilter.filter(_:query:); a search without result shows the system's ContentUnavailableView.search. Collapsed: on a compact width the system turns the split view into a stack and pushes the detail when a row is selected.
Advanced example
@State private var selection: Folder.ID?
@State private var query = ""
@State private var visibility: NavigationSplitViewVisibility = .all
GlassSidebar("Files", sections: model.sections, selection: $selection,
searchText: $query, columnVisibility: $visibility, searchPrompt: "Search folders") { id in
FolderView(id: id)
.toolbar {
Button("Focus", systemImage: "rectangle.expand.vertical") { visibility = .detailOnly }
}
}
.onChange(of: query) { model.logRecentSearch($1) }The filter is public and pure, so the host can reuse it:
GlassSidebarFilter.filter(sections, query: "evenements") // matches "Événements"Accessibility
- Rows are system list rows: selection, headers and badges are announced by the system; the list is fully keyboard navigable.
- Symbols are decorative; the title is always present.
- Search ignores case, accents and character width, and matches every word of the query in any order.
- Row titles wrap at large text sizes.
Limits
- Row and section titles are
Strings supplied already localised, because the search needs their text. - One level of sections; no nested outline.
- A section whose title matches the query keeps all its rows.
- Collapse behaviour and the search field placement were compiled for both platforms but not exercised on a running device here.
Example
import SwiftUI
import SPGlassKit
public struct GlassSidebarExample: GlassExample {
public static let componentID = "glass-sidebar"
@State private var selection: String? = "inbox"
@State private var columnVisibility: NavigationSplitViewVisibility = .automatic
public init() {}
private let sections: [GlassSidebarSection<String>] = [
GlassSidebarSection(id: "mailboxes", title: "Mailboxes", items: [
GlassSidebarItem(id: "inbox", title: "Inbox", systemImage: "tray", badge: 12, keywords: ["unread"]),
GlassSidebarItem(id: "drafts", title: "Drafts", systemImage: "doc", badge: 2),
GlassSidebarItem(id: "sent", title: "Sent", systemImage: "paperplane"),
GlassSidebarItem(id: "archive", title: "Archive", systemImage: "archivebox"),
]),
GlassSidebarSection(id: "labels", title: "Labels", items: [
GlassSidebarItem(id: "travel", title: "Voyages et séjours", systemImage: "airplane", keywords: ["travel", "trips"]),
GlassSidebarItem(id: "receipts", title: "Reçus", systemImage: "receipt", keywords: ["receipts"]),
GlassSidebarItem(id: "long", title: "A label with a deliberately long name to check wrapping", systemImage: "tag"),
]),
]
public var body: some View {
GlassSidebar("Mail", sections: sections, selection: $selection, columnVisibility: $columnVisibility, searchPrompt: "Search mailboxes") { id in
if let id {
VStack(spacing: 12) {
Text(verbatim: title(of: id)).font(.title2)
Button(columnVisibility == .detailOnly ? "Show sidebar" : "Hide sidebar") {
columnVisibility = columnVisibility == .detailOnly ? .all : .detailOnly
}
}
.padding()
.navigationTitle(Text(verbatim: title(of: id)))
} else {
ContentUnavailableView("Select a mailbox", systemImage: "sidebar.left")
}
}
}
private func title(of id: String) -> String {
sections.flatMap(\.items).first { $0.id == id }?.title ?? id
}
}
#Preview("GlassSidebar") { GlassSidebarExample() }
Registry entry
| Identifier | glass-sidebar |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassSidebarItem, GlassSidebarSection, GlassSidebarFilter, GlassSidebar |
| Licence | MIT |
| Manifest | manifest.json |
Files
Navigation/Navigation/GlassSidebar.swift9115 bytes · sha256 292ee5b8ca38…