Select doesn't render the elements before the selected elements if Value of it is set
Describe the bug
- Setting
Value()of the select doesn't render the elements which are present before the selected element - Though it does show them once we reach the end of it
Setup
Please complete the following information along with version numbers, if applicable.
- OS: macOS sonoma Version 14.3.1
- Shell: bash
- Terminal Emulator: Warp
To Reproduce
Steps to reproduce the behavior:
- Create a select
- Set value of it using
Value()function - If the selected element is not the first on the list, it doesn't render it's previous elements
Source Code
networkStruct.form = huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Key("IP METHOD").
Title("IPv4 Method").
DescriptionFunc(func() string {
if networkStruct.networkInterfaceDetails.IPv4Method != "Manual" {
return "Press 'tab' to Change Method\nNote: Switch to Manual Method In Order To Configure The Fields Below"
}
return "Press 'tab' to Change Method\n"
}, &networkStruct.networkInterfaceDetails.IPv4Method).
Value(&networkStruct.networkInterfaceDetails.IPv4Method).
Options(
huh.Option[string]{
Key: "Automatic",
Value: "Automatic",
},
huh.Option[string]{
Key: "Manual",
Value: "Manual",
},
huh.Option[string]{
Key: "Disabled",
Value: "Disabled",
},
),
),
).WithKeyMap(&huh.KeyMap{
Select: huh.SelectKeyMap{
Down: key.NewBinding(key.WithKeys("tab")),
Prev: key.NewBinding(key.WithKeys("up")),
Next: key.NewBinding(key.WithKeys("down")),
},
})
}
Expected behavior
It should render all the values instead of just rendering from the selected one
Screenshots
The value is set to Manual in the example below
https://github.com/user-attachments/assets/9acb2130-5d6e-42eb-8bd7-cb7ba583a8b0
I'm facing the same issue with MultiSelect too. It "hides" all the options before the first default selected option, until I press the up arrow key. Setting the height or limit doesn't help at all
I've got a fix for this mentioned in this discussion feel free to take a look and let me know
I've got a fix for this mentioned in this discussion feel free to take a look and let me know
Yes, this works like a charm! Thanks a lot!
I find that quite confusing as well, as there is no visual indication that there is more options if you scroll up. Even as I was writing my own app, it took me some time to figure it out.
Imho, auto-scrolling to the first selected value can make sense from a UX perspective, but it should be paired with either (ideally both):
- having a way to force the scrolling position
- having a visual clue about the scrolling (for example a gutter with
↑and↓)
any plan on opening a pr and merging to main branch?