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.
Apply the style with disclosureGroupStyle(.automatic)
DisclosureGroupStyle is set through the
disclosureGroupStyle(_:)modifier, and.automaticis the shorthand for AutomaticDisclosureGroupStyle. Attaching.disclosureGroupStyle(.automatic)to theDisclosureGrouptells SwiftUI to render the system-standard disclosure chrome — the same result you get when no style modifier is present at all.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 threeTextrows likeText("Email: jane@example.com")— is the region the style reveals when the group is open and tucks away when it is closed.Drive expansion state with the isExpanded binding
AutomaticDisclosureGroupStyle reflects and toggles the group's expansion through an optional
isExpandedbinding. The$expandedbinding, backed by the@State private var expanded = trueproperty, both seeds the initial open state and updates as the user taps the disclosure indicator, so the style and your model stay in sync.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.
@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.
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()
}
}