-
Notifications
You must be signed in to change notification settings - Fork 120
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
Dynamic Inputs #233
Dynamic Inputs #233
Conversation
go.mod
Outdated
@@ -1,21 +1,24 @@ | |||
module github.com/charmbracelet/huh | |||
|
|||
go 1.18 | |||
go 1.20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason to bump this up to Go 1.20?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, downgrading...
I first wanted to say, thank you for this work and this amazing library! I was trying this out with a Lines 247 to 257 in 133f205
It looks like the type switch only has Thanks again! |
@ChrisRx You're absolutely correct! This will definitely be fixed before merging / releasing. Thank you so much, really appreciate the review ❤️ |
Really excited to see this make it into huh! Do we know when this PR will be merged? |
I also want to know, I made the local clone and I'm going to test it on an internal CLI haha |
var ( | ||
styles = s.activeStyles() | ||
c = styles.SelectSelector.String() | ||
sb strings.Builder | ||
) | ||
|
||
if s.options.loading && time.Since(s.options.loadingStart) > spinnerShowThreshold { | ||
s.spinner.Style = s.activeStyles().MultiSelectSelector.UnsetString() | ||
sb.WriteString(s.spinner.View() + " Loading...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @maaslalani, I noticed that the ‘Loading’ message is currently hardcoded. It might be beneficial to allow this message to be defined dynamically, perhaps with a method like ‘LoadingMessage()’. While this isn’t critical for functionality, it could be quite useful for customization and internationalization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @OliveiraCleidson, thanks for pointing this out. We can fix this in a future release! Great call.
Adds `Func`-able properties to all fields to allow dynamic updates based on updates in other parts of the group. Note that bindings must be specified. Bindings allow the Function to know when it should update as the functoin re-evaluates only when the value of the binding changes.
Dynamic Forms
huh?
forms can now react to changes in other parts of the form. Replaceproperties such as
Options
,Title
,Description
with their dynamiccounterparts:
OptionsFunc
,TitleFunc
, andDescriptionFunc
to recomputeproperties values on changes when watched variables change.
Let’s build a simple state / province picker.
The
country
select will be static, we’ll use this value to recompute theoptions and title for the next input.
Define your
Select
withTitleFunc
andOptionsFunc
and bind them to the&country
value from the previous field. Whenever the user chooses a differentcountry, the
TitleFunc
andOptionsFunc
will be recomputed.Important
We have to pass
&country
as the binding to recompute the function only whencountry
changes, otherwise we will hit the API too often.Lastly, run the
form
with these inputs.