Skip to content

Select field: Selected option not visible on big lists #628

@edsonmedina

Description

@edsonmedina

Describe the bug

If I create a select field with a long list of options (bigger than the viewport) it becomes scrollable.
But if I pre-select an option that is not in the first viewport page I can't see the cursor.

To Reproduce

Steps to reproduce the behavior:

  • create a select field with a long list (ie: 50 options)
  • pre-select an option down the list (ie: position 30)
  • run

Source Code

package main

import (
        "github.com/charmbracelet/huh"
)

func main() {

        country := "PT"

        x := huh.NewSelect[string]().
                Title("Pick a country.").
                Options(
                        huh.NewOption("United States", "US"),
                        huh.NewOption("Germany", "DE"),
                        huh.NewOption("Brazil", "BR"),
                        huh.NewOption("Canada", "CA"),
                        huh.NewOption("Spain", "ES"),
                        huh.NewOption("Portugal", "PT"), // outside of initial viewport
                        huh.NewOption("Italy", "IT"),
                        huh.NewOption("Germany", "DE"),
                ).
                Height(5). // small viewport
                Value(&country) // pre-select an option below the viewport bottom
        x.Run()
}
         

Expected behavior

I expect the viewport to show the cursor on the selected option

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions