diff --git a/examples/dynamic/dynamic-country/main.go b/examples/dynamic/dynamic-country/main.go index be5d7fc3..cad19cfd 100644 --- a/examples/dynamic/dynamic-country/main.go +++ b/examples/dynamic/dynamic-country/main.go @@ -44,6 +44,24 @@ func main() { time.Sleep(1000 * time.Millisecond) return huh.NewOptions(s...) }, &country /* only this function when `country` changes */), + huh.NewSelect[string](). + Height(8). + TitleFunc(func() string { + switch country { + case "United States": + return "State" + case "Canada": + return "Province" + default: + return "Territory" + } + }, &country). + OptionsFunc(func() []huh.Option[string] { + s := states[country] + // simulate API call + time.Sleep(1000 * time.Millisecond) + return huh.NewOptions(s...) + }, &country /* only this function when `country` changes */), huh.NewNote(). TitleFunc(func() string { return fmt.Sprintf("You selected: %s", country)