Skip to content

Commit

Permalink
fix: apply theme/keymap in form constructor for Bubble Tea
Browse files Browse the repository at this point in the history
Since Bubble Tea doesn't call Run() the theme would never be set.
  • Loading branch information
meowgorithm authored and maaslalani committed Oct 24, 2023
1 parent ac6df59 commit b8a2ba8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions form.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ func NewForm(groups ...*Group) *Form {
p := paginator.New()
p.SetTotalPages(len(groups))

return &Form{
f := Form{
groups: groups,
paginator: p,
theme: NewCharmTheme(),
keymap: NewDefaultKeyMap(),
}

// NB: If dynamic forms come into play this will need to be applied when
// groups and fields are added.
for _, group := range f.groups {
group.Theme(f.theme)
group.KeyMap(f.keymap)
for _, field := range group.fields {
field.Theme(f.theme)
field.KeyMap(f.keymap)
}
}

return &f
}

// Field is a form field.
Expand Down Expand Up @@ -160,16 +173,6 @@ func (f *Form) Run() error {
return nil
}

// Make theme and keymap available to groups and fields
for _, group := range f.groups {
group.Theme(f.theme)
group.KeyMap(f.keymap)
for _, field := range group.fields {
field.Theme(f.theme)
field.KeyMap(f.keymap)
}
}

if f.accessible {
for _, group := range f.groups {
for _, field := range group.fields {
Expand Down

0 comments on commit b8a2ba8

Please sign in to comment.