Skip to content

Commit

Permalink
Merge pull request #4069 from andydotxyz/feature/setoptions
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jul 19, 2023
2 parents 940dcdc + cc04e5a commit 2641970
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions widget/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func (s *Select) SelectedIndex() int {
return -1 // not selected/found
}

// SetOptions updates the list of options available and refreshes the widget
//
// Since: 2.4
func (s *Select) SetOptions(options []string) {
s.Options = options
s.Refresh()
}

// SetSelected sets the current option of the select widget
func (s *Select) SetSelected(text string) {
for _, option := range s.Options {
Expand Down
8 changes: 8 additions & 0 deletions widget/select_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func TestSelect_SetOptions(t *testing.T) {
assert.Equal(t, 3, len(sel.popUp.Items))
assert.Equal(t, "10", sel.popUp.Items[0].(*menuItem).Item.Label)

sel.popUp.Hide()
sel.SetOptions([]string{"15", "16", "17"})

test.Tap(sel)
assert.NotNil(t, sel.popUp)
assert.Equal(t, 3, len(sel.popUp.Items))
assert.Equal(t, "16", sel.popUp.Items[1].(*menuItem).Item.Label)

sel.popUp.Hide()
sel.Options = []string{"20", "21"}
sel.Refresh()
Expand Down

0 comments on commit 2641970

Please sign in to comment.