SP GlassKit1.1.0

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.

GlassAccordion running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-accordion

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-accordion
ModuleSPGlassComponents
Kindnative-wrapper — system DisclosureGroup sections; no surface is drawn
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Containers/GlassAccordionExample.swift

Minimal usage

Swift
@State private var expanded: Set<Question.ID> = []

GlassAccordion(questions, expanded: $expanded) { question in
    Text(question.title)
} content: { question in
    Text(question.answer)
}

Variants

ModeBehaviour
.multiple (default)Any number of sections can be open.
.singleOpening a section closes the others. If the bound set already holds several identifiers, only the first in display order is shown open.

Parameters

ParameterTypeDefaultMeaning
dataRandomAccessCollection of Identifiable—Sections, with stable identifiers.
expandedBinding<Set<ID>>—Identifiers of the open sections.
modeGlassAccordionMode.multipleSee 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

ParameterTypeDefaultMeaning
styleGlassAccordionStyle.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

Swift
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

  • DisclosureGroup exposes 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 GlassCard or a Form/List for a surface.
  • All section headers are built eagerly (a VStack); for hundreds of sections use a List of DisclosureGroups instead.

Example

Complete example (compiled with the package)
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

Identifierglass-accordion
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassAccordionMode, GlassAccordionStyle, GlassAccordionReducer, GlassAccordion
LicenceMIT
Manifestmanifest.json

Files