TechnologiesSwiftUI

AutomaticDisclosureGroupStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A disclosure group style that resolves its appearance automatically

How it works

AutomaticDisclosureGroupStyle is the default DisclosureGroupStyle that SwiftUI applies to every disclosure group unless you specify otherwise. It renders the platform-standard appearance for collapsible content: a tappable label paired with a disclosure indicator that expands and collapses an attached region of subviews. Reach for it when you want a DisclosureGroup to look and behave exactly as the system intends for the current context, or when you need to explicitly reset to that default after experimenting with a custom style. Because it adapts to platform and environment conventions, it keeps your hierarchy consistent with the rest of the interface without any per-group configuration.

  1. Apply the style with disclosureGroupStyle(.automatic)

    DisclosureGroupStyle is set through the disclosureGroupStyle(_:) modifier, and .automatic is the shorthand for AutomaticDisclosureGroupStyle. Attaching .disclosureGroupStyle(.automatic) to the DisclosureGroup tells SwiftUI to render the system-standard disclosure chrome — the same result you get when no style modifier is present at all.

  2. Provide the label and the collapsible content

    The automatic style draws a header from the group's label and shows or hides the content closure beneath it. Here the label is the string "Account Settings", and the content — the three Text rows like Text("Email: jane@example.com") — is the region the style reveals when the group is open and tucks away when it is closed.

  3. Drive expansion state with the isExpanded binding

    AutomaticDisclosureGroupStyle reflects and toggles the group's expansion through an optional isExpanded binding. The $expanded binding, backed by the @State private var expanded = true property, both seeds the initial open state and updates as the user taps the disclosure indicator, so the style and your model stay in sync.

  4. Rely on the default conformance and presentation

    Conforming to DisclosureGroupStyle, AutomaticDisclosureGroupStyle supplies its own makeBody(configuration:) internally, so you never implement it yourself — you simply name .automatic. The surrounding .padding() only insets the styled group on screen; it does not alter how the style composes the indicator and content.

Try it — Change @State private var expanded = true to false to see AutomaticDisclosureGroupStyle render the group collapsed, showing only the "Account Settings" header until you tap it open.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

AutomaticDisclosureGroupStyle.swift
struct AutomaticDisclosureGroupStyleDemo: View {
    @State private var expanded = true

    var body: some View {
        DisclosureGroup("Account Settings", isExpanded: $expanded) {
            Text("Email: jane@example.com")
            Text("Plan: Pro")
            Text("Member since 2021")
        }
        .disclosureGroupStyle(.automatic)
        .padding()
    }
}
Live preview
Account Settings Email: jane@example.com Plan: Pro Member since 2021
Account Settings Email: jane@example.com Plan: Pro Member since 2021
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →