GlassToolbar
Groups of toolbar actions with system placements, overflow and keyboard shortcuts.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-toolbar
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-toolbarCopies 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-toolbar |
|---|---|
| Module | SPGlassNavigation |
| Kind | native-wrapper — ToolbarContent made of ToolbarItemGroups with system placements |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Navigation/GlassToolbarExample.swift |
Minimal usage
content.glassToolbar([
GlassToolbarGroup(id: "main", placement: .trailing, actions: [
GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up") { share() },
]),
])GlassToolbar(groups) is the same thing as ToolbarContent, to combine with other items inside .toolbar { }.
Variants
| Placement | System placement |
|---|---|
.automatic | .automatic |
.leading | .topBarLeading (iOS), .navigation (macOS) |
.trailing | .topBarTrailing (iOS), .primaryAction (macOS) |
.primary | .primaryAction |
.secondary | .secondaryAction — the system collects these in its own overflow menu |
.bottom | .bottomBar (iOS), .automatic (macOS) |
.cancellation / .confirmation | .cancellationAction / .confirmationAction |
Parameters
GlassToolbarAction
| Parameter | Type | Default | Meaning |
|---|---|---|---|
id | String | — | Stable identifier. |
title / verbatim / text | LocalizedStringKey / StringProtocol / Text | — | Label, tooltip and menu title. |
systemImage | String | — | SF Symbol shown in the bar. |
role | ButtonRole? | nil | .destructive, .cancel. |
shortcut | KeyboardShortcut? | nil | Keyboard shortcut. |
isEnabled | Bool | true | Disabled state. |
priority | GlassToolbarActionPriority | .normal | .low overflows first, .high last. |
action | @MainActor () -> Void | — | Called on activation. |
GlassToolbarGroup
| Parameter | Type | Default | Meaning |
|---|---|---|---|
id | String | — | Stable identifier. |
placement | GlassToolbarPlacement | .automatic | Where the group goes. |
capacity | Int? | nil | Controls shown before overflow. nil: two on a compact width or at accessibility text sizes, five otherwise. |
actions | [GlassToolbarAction] | — | Actions in order. |
States
Enabled and disabled per action. Overflow is decided by the pure function GlassToolbarLayout.split(_:capacity:): when everything fits, everything is visible; otherwise the "More actions" menu takes one place and the rest goes to the actions of highest priority, the earliest first among equals. Order is kept on both sides.
Advanced example
.toolbar {
GlassToolbar([
GlassToolbarGroup(id: "edit", placement: .trailing, capacity: 3, actions: [
GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up",
shortcut: KeyboardShortcut("s", modifiers: [.command, .shift]), priority: .high) { share() },
GlassToolbarAction(id: "duplicate", title: "Duplicate", systemImage: "plus.square.on.square",
shortcut: KeyboardShortcut("d")) { duplicate() },
GlassToolbarAction(id: "archive", title: "Archive", systemImage: "archivebox", priority: .low) { archive() },
GlassToolbarAction(id: "delete", title: "Delete", systemImage: "trash", role: .destructive, priority: .low) { delete() },
]),
GlassToolbarGroup(id: "export", placement: .secondary, actions: [exportPDF, print]),
])
ToolbarItem(placement: .principal) { DocumentTitle() }
}With a capacity of three, Share and Duplicate stay in the bar; Archive and Delete are in the menu.
Accessibility
- Each button is a
Label: the bar shows the symbol, VoiceOver reads the title, macOS shows it as a tooltip. - The overflow menu is labelled "More actions" (localised) and lists titles with symbols; the destructive role is conveyed by the system.
- Shortcuts are attached to the buttons themselves, in the bar or in the menu.
- At accessibility text sizes fewer controls are kept in the bar.
Limits
- The system may still rearrange or collapse items of its own accord; the capacity is an upper bound, not a promise.
- Capacity is a count of controls, not a measured width.
.bottomhas no bottom bar on macOS and falls back to the automatic placement.- That shortcuts of actions inside the overflow menu fire on every platform was not verified on a running device.
Example
import SwiftUI
import SPGlassKit
public struct GlassToolbarExample: GlassExample {
public static let componentID = "glass-toolbar"
@State private var log = ["Nothing yet"]
@State private var isPinned = false
public init() {}
private func record(_ entry: String) {
log.insert(entry, at: 0)
}
private var groups: [GlassToolbarGroup] {
[
GlassToolbarGroup(id: "document", placement: .trailing, capacity: 3, actions: [
GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up", shortcut: KeyboardShortcut("s", modifiers: [.command, .shift]), priority: .high) { record("Shared") },
GlassToolbarAction(id: "pin", title: isPinned ? "Unpin" : "Pin", systemImage: isPinned ? "pin.fill" : "pin") {
isPinned.toggle()
record(isPinned ? "Pinned" : "Unpinned")
},
GlassToolbarAction(id: "duplicate", title: "Duplicate", systemImage: "plus.square.on.square", shortcut: KeyboardShortcut("d")) { record("Duplicated") },
GlassToolbarAction(id: "archive", title: "Archive", systemImage: "archivebox", isEnabled: log.count > 1, priority: .low) { record("Archived") },
GlassToolbarAction(id: "delete", title: "Delete", systemImage: "trash", role: .destructive, priority: .low) { log = ["Nothing yet"] },
]),
GlassToolbarGroup(id: "export", placement: .secondary, actions: [
GlassToolbarAction(id: "pdf", title: "Export as PDF", systemImage: "doc.richtext") { record("Exported as PDF") },
GlassToolbarAction(id: "print", title: "Print", systemImage: "printer", shortcut: KeyboardShortcut("p")) { record("Printed") },
]),
GlassToolbarGroup(id: "format", placement: .bottom, actions: [
GlassToolbarAction(id: "bold", title: "Bold", systemImage: "bold", shortcut: KeyboardShortcut("b")) { record("Bold") },
GlassToolbarAction(id: "italic", title: "Italic", systemImage: "italic", shortcut: KeyboardShortcut("i")) { record("Italic") },
]),
]
}
public var body: some View {
NavigationStack {
List(Array(log.enumerated()), id: \.offset) { _, entry in
Text(verbatim: entry)
}
.navigationTitle("Document")
.glassToolbar(groups)
}
}
}
#Preview("GlassToolbar") { GlassToolbarExample() }
Registry entry
| Identifier | glass-toolbar |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassToolbarPlacement, GlassToolbarGroup, GlassToolbar, GlassToolbarActionPriority, GlassToolbarAction, GlassToolbarLayout, Split |
| Licence | MIT |
| Manifest | manifest.json |
Files
Navigation/Navigation/GlassToolbar.swift6054 bytes · sha256 11bc027ca5e5…Navigation/Navigation/GlassToolbarAction.swift8101 bytes · sha256 ee1353ccb7b6…