When directed to a huh model from another bubbletea model, the initial input does not have focus. This is exacerbated by, but does not require, the use of a field validation. If a field validation is used it soft-locks the program. If a field validation is not used on the first field then one can simply tab and shift-tab back.
To Reproduce
Create some kind of navigation model that directs to a huh model. (Alternatively run the reproduction code below)
Put a validation on the first field of the huh model in order to soft lock it.
Run the code, proceeding through the navigation model to the huh model.
Try and type into the Input
Try and tab/shift-tab off the Input.
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
)
func main() {
tea.NewProgram(NavModel{}).Run()
}
type NavModel struct{}
func (n NavModel) Init() tea.Cmd {
return nil
}
func (n NavModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.KeyMsg); ok {
if msg.String() == "ctrl+c" {
return n, tea.Quit
}
if msg.String() == "enter" {
// Hardcoding 80,80 because I'm being lazy in this reproduction code and not saving them after we receive them.
// Sending this windowSizeMsg is necessary to get it to properly render the NewModel at all.
return NewModel(), func() tea.Msg { return tea.WindowSizeMsg{Height: 80, Width: 80} }
}
}
return n, nil
}
func (n NavModel) View() string {
return "Press enter to proceed."
}
type Model struct {
form *huh.Form // huh.Form is just a tea.Model
}
func NewModel() Model {
return Model{
form: huh.NewForm(
huh.NewGroup(
huh.NewInput().
Validate(func(in string) error {
if in == "" {
return fmt.Errorf("Class must be set.")
}
return nil
}).
Key("class").
Title("Choose your class"),
huh.NewSelect[int]().
Key("level").
Options(huh.NewOptions(1, 20, 9999)...).
Title("Choose your level"),
),
),
}
}
func (m Model) Init() tea.Cmd {
return m.form.Init()
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.KeyMsg); ok {
if msg.String() == "ctrl+c" {
return m, tea.Quit
}
}
form, cmd := m.form.Update(msg)
if f, ok := form.(*huh.Form); ok {
m.form = f
}
return m, cmd
}
func (m Model) View() string {
if m.form.State == huh.StateCompleted {
class := m.form.GetString("class")
level := m.form.GetString("level")
return fmt.Sprintf("You selected: %s, Lvl. %d", class, level)
}
return m.form.View()
}
Expected behavior
When the huh model is rendered the initial input field should have focus and you should be able to type into it.
Screenshots
What isn't visible is I'm trying to type into the Input field.
Describe the bug
When directed to a
huh
model from another bubbletea model, the initial input does not have focus. This is exacerbated by, but does not require, the use of a field validation. If a field validation is used it soft-locks the program. If a field validation is not used on the first field then one can simplytab
andshift-tab
back.To Reproduce
huh
model. (Alternatively run the reproduction code below)Input
tab
/shift-tab
off theInput
.Expected behavior
When the
huh
model is rendered the initial input field should have focus and you should be able to type into it.Screenshots
What isn't visible is I'm trying to type into the
Input
field.Desktop:
go.mod