GlassAccordion
Disclosure sections with controlled expansion and Reduce Motion support.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-accordion
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-accordionCopies 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-accordion |
|---|---|
| Module | SPGlassComponents |
| Kind | native-wrapper — system DisclosureGroup sections; no surface is drawn |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Containers/GlassAccordionExample.swift |
Minimal usage
@State private var expanded: Set<Question.ID> = []
GlassAccordion(questions, expanded: $expanded) { question in
Text(question.title)
} content: { question in
Text(question.answer)
}Variants
| Mode | Behaviour |
|---|---|
.multiple (default) | Any number of sections can be open. |
.single | Opening a section closes the others. If the bound set already holds several identifiers, only the first in display order is shown open. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
data | RandomAccessCollection of Identifiable | — | Sections, with stable identifiers. |
expanded | Binding<Set<ID>> | — | Identifiers of the open sections. |
mode | GlassAccordionMode | .multiple | See Variants. |
label | @ViewBuilder (Element) -> View | — | Header of a section. |
content | @ViewBuilder (Element) -> View | — | Body of a section, built only while it is open. |
The transition rules are in GlassAccordionReducer (setting, toggling, displayed), pure functions the host can reuse to open a section from code.
Style
| Parameter | Type | Default | Meaning |
|---|---|---|---|
style | GlassAccordionStyle | .plain | .plain: rows separated by hairlines, for an accordion inside a card or a form. .grouped: the rows sit on one opaque themed surface, for an accordion that stands alone. |
States
Expanded and collapsed, per section, controlled by the host through expanded. Identifiers that are not in data are ignored.
Advanced example
GlassCard {
GlassAccordion(sections, expanded: $expanded, mode: .single) { section in
Label(section.title, systemImage: section.symbol)
} content: { section in
ForEach(section.rows) { row in LabeledContent(row.name, value: row.value) }
}
}
.onOpenURL { url in
if let id = Section.id(from: url) {
expanded = GlassAccordionReducer.setting(id, expanded: true, in: expanded, mode: .single)
}
}Accessibility
DisclosureGroupexposes each header as a control with its expanded or collapsed state, and handles Space, Return and the arrow keys on macOS.- With Reduce Motion (real or simulated) sections open and close at once, without the sliding reveal; otherwise the theme's standard animation is used.
- Dividers are hidden from accessibility.
Limits
- The disclosure chevron and its position are the system's.
- The accordion draws no background; place it in a
GlassCardor aForm/Listfor a surface. - All section headers are built eagerly (a
VStack); for hundreds of sections use aListofDisclosureGroups instead.
Example
import SwiftUI
import SPGlassKit
public struct GlassAccordionExample: GlassExample {
public static let componentID = "glass-accordion"
private struct Question: Identifiable {
let id: String
let title: String
let answer: String
}
private let questions = [
Question(id: "delivery", title: "How long does delivery take?", answer: "Two to four working days for this sample shop."),
Question(id: "returns", title: "Can I return an item?", answer: "Yes, within 30 days, in its original packaging."),
Question(id: "unicode", title: "Les accents et les émojis passent-ils ? 🎉", answer: "Oui : « é », « ñ », « 日本語 » et le texte de droite à gauche (مرحبا) s'affichent sans casser la mise en page."),
]
@State private var expanded: Set<String> = ["delivery"]
@State private var singleMode = true
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
Toggle("One section at a time", isOn: $singleMode)
GlassAccordion(questions, expanded: $expanded, mode: singleMode ? .single : .multiple, style: .grouped) { question in
Text(question.title)
} content: { question in
Text(question.answer)
}
Text("\(expanded.count) open").font(.caption).foregroundStyle(.secondary)
}
.padding()
}
}
}
#Preview("GlassAccordion") { GlassAccordionExample() }
Registry entry
| Identifier | glass-accordion |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassAccordionMode, GlassAccordionStyle, GlassAccordionReducer, GlassAccordion |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Containers/GlassAccordion.swift7728 bytes · sha256 3993181b2daa…