Skip to main content
Section(children: Component): Component;
Section(children: Component[]): Component;
Section(props: { header?: Component; footer?: Component }, children: Component[]): Component;
children
Component | Component[]
required
The content of the section.
props
object
Configuration options for the section.

Support

Usage

Basic section

Section([
    Text("Item 1"),
    Text("Item 2"),
    Text("Item 3")
])

With header

Section({ header: Text("Settings") }, [
    Toggle({ label: "Dark Mode", isOn, setIsOn }),
    Toggle({ label: "Notifications", isOn: notifs, setIsOn: setNotifs })
])
Section(
    {
        header: Text("Account"),
        footer: Text("Your email is used for sign-in.")
    },
    [
        Text("user@example.com"),
        Text("Change password")
    ]
)

Inside a List

List([
    Section({ header: Text("Fruits") }, [
        ForEach(fruits, (fruit) => Text(fruit))
    ]),
    Section({ header: Text("Vegetables") }, [
        ForEach(veggies, (veg) => Text(veg))
    ])
])

Pinned headers in LazyVStack

Use with LazyVStack and pinnedViews to create sticky section headers:
ScrollView([
    LazyVStack({ pinnedViews: "sectionHeaders" }, [
        Section({ header: Text("Section A").font("headline") }, [
            ForEach(sectionAItems, (item) => Text(item.name))
        ])
    ])
])

See Also

  • List — scrollable list
  • LazyVStack — lazy vertical stack with pinned views