diff --git a/widget/select.go b/widget/select.go index 3d344e30a0..70245f3b43 100644 --- a/widget/select.go +++ b/widget/select.go @@ -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 { diff --git a/widget/select_internal_test.go b/widget/select_internal_test.go index c3689b5da1..a030e15035 100644 --- a/widget/select_internal_test.go +++ b/widget/select_internal_test.go @@ -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()