diff --git a/widget/accordion.go b/widget/accordion.go index 4b362e0903..6e971b4487 100644 --- a/widget/accordion.go +++ b/widget/accordion.go @@ -98,6 +98,15 @@ func (a *Accordion) OpenAll() { a.Refresh() } +// Prepend adds the given item to the beginning of this Accordion. +// +// Since: 2.6 +func (a *Accordion) Prepend(item *AccordionItem) { + a.Items = append([]*AccordionItem{item}, a.Items...) + + a.Refresh() +} + // Remove deletes the given item from this Accordion. func (a *Accordion) Remove(item *AccordionItem) { for i, ai := range a.Items { diff --git a/widget/accordion_test.go b/widget/accordion_test.go index 0d118de26e..f3d37ad92b 100644 --- a/widget/accordion_test.go +++ b/widget/accordion_test.go @@ -533,6 +533,15 @@ func TestAccordion_OpenAll(t *testing.T) { assert.True(t, ac.Items[2].Open) } +func TestAccordion_Prepend(t *testing.T) { + ac := widget.NewAccordion(widget.NewAccordionItem("foo", widget.NewLabel("foobar"))) + assert.Len(t, ac.Items, 1) + + ac.Prepend(widget.NewAccordionItem("bar", widget.NewLabel("more bar"))) + assert.Len(t, ac.Items, 2) + assert.Equal(t, "bar", ac.Items[0].Title) +} + func TestAccordion_Remove(t *testing.T) { ai := widget.NewAccordionItem("foo", widget.NewLabel("foobar")) ac := widget.NewAccordion(ai)