Accordion and Collapsible
Sections that expand and collapse, in a bordered group or on their own.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type faq struct {
open []bool
}
func (f *faq) View(c *ui.Context) {
questions := []struct{ q, a string }{
{"Does Onevra need a web view?", "No. MyGo draws every control itself, on the GPU."},
{"Which platforms does it run on?", "macOS, Windows and Linux, from the same Go code."},
{"Can I use MyGo widgets too?", "Yes. Onevra builds on MyGo and works beside it."},
}
ui.Column(c).Width(440).MaxWidthPercent(100).Children(func() {
components.Accordion(c, func(group *components.AccordionGroup) {
for i, item := range questions {
if group.Item(item.q, &f.open[i], func() {
components.Text(c, item.a).TextColor(c.Theme().TextMuted).FillWidth()
}).Changed() && f.open[i] {
// Keep one section open at a time.
for j := range f.open {
f.open[j] = j == i
}
}
}
})
})
}components.Accordion builds independently expandable sections in a bordered box. Each item binds its own *bool, so any number can be open; to keep one open at a time, close the others when an item reports Changed(). Up, Down, Home and End move between headers.
Collapsible
components.Collapsible is one animated disclosure without a box. ArrowPosition puts the arrow before or after the label, and Leading and Trailing add an icon or a count to the header.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
type advancedOptions struct {
open, verbose, telemetry bool
}
func (a *advancedOptions) View(c *ui.Context) {
ui.Column(c).Width(320).MaxWidthPercent(100).Children(func() {
components.Collapsible(c, "Advanced", &a.open, components.CollapsibleOptions{
ArrowPosition: components.ArrowLeft,
Leading: func() { components.Icon(c, lucide.SlidersHorizontal).Size(14, 14).Shrink(0) },
Trailing: func() { components.Badge(c, "2") },
}, func() {
ui.Column(c).Gap(10).Padding(8, 0, 0, 0).Children(func() {
components.Checkbox(c, &a.verbose, "Verbose logging")
components.Checkbox(c, &a.telemetry, "Share usage data")
})
}).Root.FillWidth()
})
}API
Accordion
func Accordion(c *ui.Context, fn func(group *AccordionGroup)) ui.ElementAccordion builds independently expandable sections in MyGo's bordered box, without hover styling. Use group.Item inside fn. Up, Down, Home and End move focus between headers; Tab still visits controls inside open panels.
pkg.go.devAccordionGroup
type AccordionGroup struct {
// contains filtered or unexported fields
}AccordionGroup builds the items of one Accordion. It is valid only inside the Accordion callback; nested accordions have independent groups.
Methods
func (group *AccordionGroup) Item(title string, open *bool, fn func()) DisclosurePartsItem builds a section, with application-owned expansion state and content. Its Changed method reports trigger activation. To allow just one open item, use that signal to close other application-owned expansion values.
Collapsible
func Collapsible(c *ui.Context, label string, open *bool, options CollapsibleOptions, fn func()) DisclosurePartsCollapsible shows an animated disclosure with MyGo's spacing and appearance, without hover styling. The caller owns open; Enter and Space toggle it.
pkg.go.devCollapsibleOptions
CollapsibleOptions configures the disclosure arrow, whose default is right, optional leading content, such as an icon, built inside the trigger before its label, and optional trailing content, such as a count, built at the header's end outside the trigger and vertically centered on it.
Prop
Type
DisclosureParts
DisclosureParts exposes the container and disclosure button for this frame. Changed reports activation of the trigger, not application-owned state edits.
Prop
Type
Methods
func (p DisclosureParts) Changed() bool