Repository Public MIT
1# GlassAccordion23| | |4|---|---|5| Identifier | `glass-accordion` |6| Module | `SPGlassComponents` |7| Kind | `native-wrapper` — system `DisclosureGroup` sections; no surface is drawn |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Containers/GlassAccordionExample.swift` |1011## Minimal usage1213```swift14@State private var expanded: Set<Question.ID> = []1516GlassAccordion(questions, expanded: $expanded) { question in17 Text(question.title)18} content: { question in19 Text(question.answer)20}21```2223## Variants2425| Mode | Behaviour |26|---|---|27| `.multiple` (default) | Any number of sections can be open. |28| `.single` | Opening a section closes the others. If the bound set already holds several identifiers, only the first in display order is shown open. |2930## Parameters3132| Parameter | Type | Default | Meaning |33|---|---|---|---|34| `data` | `RandomAccessCollection` of `Identifiable` | — | Sections, with stable identifiers. |35| `expanded` | `Binding<Set<ID>>` | — | Identifiers of the open sections. |36| `mode` | `GlassAccordionMode` | `.multiple` | See Variants. |37| `label` | `@ViewBuilder (Element) -> View` | — | Header of a section. |38| `content` | `@ViewBuilder (Element) -> View` | — | Body of a section, built only while it is open. |3940The transition rules are in `GlassAccordionReducer` (`setting`, `toggling`, `displayed`), pure functions the host can reuse to open a section from code.4142### Style4344| Parameter | Type | Default | Meaning |45|---|---|---|---|46| `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. |4748## States4950Expanded and collapsed, per section, controlled by the host through `expanded`. Identifiers that are not in `data` are ignored.5152## Advanced example5354```swift55GlassCard {56 GlassAccordion(sections, expanded: $expanded, mode: .single) { section in57 Label(section.title, systemImage: section.symbol)58 } content: { section in59 ForEach(section.rows) { row in LabeledContent(row.name, value: row.value) }60 }61}62.onOpenURL { url in63 if let id = Section.id(from: url) {64 expanded = GlassAccordionReducer.setting(id, expanded: true, in: expanded, mode: .single)65 }66}67```6869## Accessibility7071- `DisclosureGroup` exposes each header as a control with its expanded or collapsed state, and handles Space, Return and the arrow keys on macOS.72- With Reduce Motion (real or simulated) sections open and close at once, without the sliding reveal; otherwise the theme's standard animation is used.73- Dividers are hidden from accessibility.7475## Limits7677- The disclosure chevron and its position are the system's.78- The accordion draws no background; place it in a `GlassCard` or a `Form`/`List` for a surface.79- All section headers are built eagerly (a `VStack`); for hundreds of sections use a `List` of `DisclosureGroup`s instead.80