DisclosureGroup¶

A header with a disclosure chevron that shows or hides its child views when the user clicks it. Use it for short optional or advanced content. Content that needs its own page belongs behind a NavigationLink.
Constructor¶
nib.DisclosureGroup(
label,
controls=None,
is_expanded=False,
on_expand=None,
**modifiers,
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
label |
str |
required | Header text, visible in both states. |
controls |
list[View] |
None |
Child views, shown while the group is expanded. |
is_expanded |
bool |
False |
Whether the group is expanded. Reactive, see below. |
on_expand |
Callable[[bool], None] |
None |
Called when the user expands (True) or collapses (False) the group. |
**modifiers |
View modifiers. |
Expansion state¶
is_expanded is a two-way property:
- Reading it returns the current state, including the user's last expand or collapse.
- Setting it expands or collapses the group on screen. A change made from Python does not call
on_expand.
import nib
details = nib.DisclosureGroup(
"Details",
controls=[nib.Text("Hidden content")],
on_expand=lambda expanded: print("expanded" if expanded else "collapsed"),
)
def collapse():
details.is_expanded = False
Examples¶
Advanced options¶

import nib
def main(app: nib.App):
app.title = "Export"
app.icon = nib.SFSymbol("square.and.arrow.up.on.square")
app.height = 260
app.build(
nib.VStack(
controls=[
nib.Picker("Format", selection="PNG", options=["PNG", "JPEG", "PDF"]),
nib.Toggle("Open after export", is_on=True),
nib.DisclosureGroup(
"Advanced",
controls=[
nib.Toggle("Include metadata", is_on=False),
nib.Toggle("Embed colour profile", is_on=True),
nib.Slider(
label="Quality", value=80, min_value=0, max_value=100
),
],
),
nib.Button(
"Export",
on_click=lambda: None,
style=nib.ButtonStyle.BORDERED_PROMINENT,
),
],
spacing=12,
padding=16,
width=312,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Initially expanded group¶

import nib
def main(app: nib.App):
app.title = "Network"
app.icon = nib.SFSymbol("network")
app.height = 200
def row(label, value):
return nib.HStack(
controls=[
nib.Text(label, foreground_color=nib.Color.SECONDARY),
nib.Spacer(),
nib.Text(value, style=nib.TextStyle(monospaced=True)),
]
)
app.build(
nib.VStack(
controls=[
nib.DisclosureGroup(
"Wi-Fi",
controls=[
nib.Toggle("Wi-Fi", is_on=True),
nib.Toggle("Ask to join networks", is_on=False),
],
is_expanded=True,
),
nib.DisclosureGroup(
"Details",
controls=[
row("IP address", "192.168.1.24"),
row("Router", "192.168.1.1"),
row("DNS", "1.1.1.1"),
],
is_expanded=False,
),
],
spacing=12,
padding=16,
width=312,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Related¶
- NavigationStack & NavigationLink: drill-down pages
- Section: grouped content without collapsing
- Form: settings layouts