-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default value doesn't work for NewSelect
#444
Comments
Just providing more context (if i understand it right) When the Lines 218 to 219 in 20a4d21
Which eventually is triggered here Lines 349 to 351 in 20a4d21
and when the Lines 371 to 380 in 20a4d21
Which ends up setting the "dynamic" options and based on the code it just shows that it just set's the options, and doesn't really take into consideration anything about selection of options, as seen in the Lines 172 to 187 in 20a4d21
So taking the same code over,( i.e. ensuring the option is selected) and putting it within diff --git a/field_select.go b/field_select.go
index 81e57d9..3d90d67 100644
--- a/field_select.go
+++ b/field_select.go
@@ -372,6 +372,15 @@ func (s *Select[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.id == s.id && msg.hash == s.options.bindingsHash {
s.options.update(msg.options)
+ // Set the cursor to the existing value or the last selected option.
+ for i, option := range msg.options {
+ if option.Value == s.accessor.Get() {
+ s.selected = i
+ break
+ } else if option.selected {
+ s.selected = i
+ }
+ }
// since we're updating the options, we need to update the selected cursor
// position and filteredOptions.
s.selected = clamp(s.selected, 0, len(msg.options)-1) Was able to get the "default" value set Can probably look at creating a PR for it, if that seems to make sense, or validates the thinking |
As #70 is closed, posting here - @maaslalani looks like the selection of default value for |
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 ofOptions
.To Reproduce
The following code example works:
The following example uses
OptionsFunc
and the default value is not working:Expected behavior
Expect
two
to be selected by default in both cases.Related issue: #70
The text was updated successfully, but these errors were encountered: