Open
Description
Describe the bug
The default value isn't selected, instead the 1st available option is selected. Seems this is only happening when using the OptionsFunc
instead of Options
.
To Reproduce
The following code example works:
package main
import "github.com/charmbracelet/huh"
func main() {
foo := "two"
form := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Title("foo").
Options(huh.NewOptions("one", "two", "three")...).
Value(&foo),
),
)
form.Run()
}
The following example uses OptionsFunc
and the default value is not working:
package main
import "github.com/charmbracelet/huh"
func main() {
foo := "two"
form := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Title("foo").
OptionsFunc(func() []huh.Option[string] {
return getOptions()
}, nil).
Value(&foo),
),
)
form.Run()
}
func getOptions() []huh.Option[string] {
var options []huh.Option[string]
options = append(options, huh.NewOption("one", "one"))
options = append(options, huh.NewOption("two", "two"))
options = append(options, huh.NewOption("three", "three"))
return options
}
Expected behavior
Expect two
to be selected by default in both cases.
Related issue: #70
Activity