GlassSidebar
| 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
swift
@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
swift
@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:
swift
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.