Skip to content

Commit

Permalink
Merge pull request #5438 from andydotxyz/fix/5418
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jan 20, 2025
2 parents 8be2895 + 3727c6b commit 2127941
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions widget/accordion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions widget/accordion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2127941

Please sign in to comment.