SPB Git

Repository Public MIT

glass-breadcrumb.md 3.1 KB

# GlassBreadcrumb

Identifier glass-breadcrumb
Module SPGlassNavigation
Kind custom-glass — a navigation bar drawn with glassSurface(_:in:), opaque with Reduce Transparency
Platforms iOS 26, iPadOS 26, macOS 26
Example Examples/Gallery/Navigation/GlassBreadcrumbExample.swift

# Minimal usage

swift
GlassBreadcrumb([
    GlassBreadcrumbItem(id: "root", title: "Home", systemImage: "house"),
    GlassBreadcrumbItem(id: "docs", title: "Documents"),
    GlassBreadcrumbItem(id: "2026", title: "2026"),
]) { id in
    navigate(to: id)
}

# Variants

Variant Use
maxVisibleItems: 4 (default) Root, overflow menu, then the three levels closest to the current location.
maxVisibleItems: 2 Root, overflow menu, current location.
maxVisibleItems: 1 Overflow menu and current location only.
systemImage: A symbol before the title of a level.

When the bar is narrower than its content, it shows fewer levels (down to one) before it truncates any title.

# Parameters

Parameter Type Default Meaning
items [GlassBreadcrumbItem<ID>] — Path from the root to the current location. An empty path draws nothing.
maxVisibleItems Int 4 Largest number of levels shown at once.
onSelect @MainActor (ID) -> Void — Called with the identifier of the activated level, visible or in the menu.

# States

The last item is the current location: stronger text, the selected trait and the accessibility value "Current location". The other levels are plain buttons. Hidden levels live in a menu labelled with their number ("3 hidden levels"). The layout is the pure type GlassBreadcrumbLayout(count:maxVisible:).

# Advanced example

swift
@State private var path: [Folder]

GlassBreadcrumb(path.map { GlassBreadcrumbItem(id: $0.id, title: $0.name) }, maxVisibleItems: 3) { id in
    if let index = path.firstIndex(where: { $0.id == id }) {
        path.removeSubrange((index + 1)...)
    }
}
.safeAreaPadding(.horizontal)

# Accessibility

  • The bar is a container labelled "Breadcrumb"; each level is a button whose label is its title.
  • The current location is exposed by a trait and a value, not only by its weight and colour.
  • Separators are hidden from assistive technologies.
  • Every level and the menu are reachable with the keyboard (Tab or Full Keyboard Access) and have the platform's minimum hit target.
  • Titles use theme fonts and follow Dynamic Type; a single remaining level truncates in the middle.

# Limits

  • One glass surface for the whole bar; levels are not individual glass surfaces.
  • The bar is never tinted, whatever the theme's glass tint: it carries text in the theme's text colours, which a tinted glass (Aurora, Neon) made illegible in 1.0.
  • Activating the current location also calls onSelect; ignore it if it means nothing in your application.
  • The path is always written from the root; in right-to-left languages the row is mirrored by the system.
  • Very long paths rely on the overflow menu; the bar does not scroll.
  • Visual result and keyboard traversal were not checked on a running device here.
Files main
Menu

Theme