Skip to content
Nested Accordion preview
Rendered from the SwiftUI source on this page.

Nested Accordion

From syxUI — written for both platforms, not translated between them.

A parent row that expands into indented child rows.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccNested.swift
// Nested Accordion · syxUI · https://syxui.dev/components/acc-nested
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let accBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Nested accordion (parent → children)
struct AccNested: View {
    @State private var open = true
    let children = ["Personal details", "Password & security", "Linked accounts"]
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            HStack {
                Image(systemName: "person.crop.circle").font(.system(size: 16)).foregroundStyle(accBlue)
                Text("Account").font(.system(size: 15, weight: .semibold))
                Spacer()
                Image(systemName: "chevron.down").font(.system(size: 12, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open ? 180 : 0))
            }.padding(.vertical, 13)
            if open {
                ForEach(children, id: \.self) { c in
                    HStack {
                        Text(c).font(.system(size: 14)).foregroundStyle(.secondary)
                        Spacer()
                        Image(systemName: "chevron.right").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary.opacity(0.6))
                    }.padding(.vertical, 10).padding(.leading, 26)
                }
            }
        }.formaCard(16).frame(width: 340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17