Skip to content

Option with \n in it breaks scrolling with NewSelect, probably others #184

Closed as duplicate of#429
@iloveicedgreentea

Description

@iloveicedgreentea

Describe the bug

var controlIDs []huh.Option[string]

for k, v := range m.appState.ControlIDs {
	x := huh.NewOption(fmt.Sprintf("%s \n %s", k, v), fmt.Sprintf("%s \n %s", k, v))
controlIDs = append(controlIDs, x)
}

huh.NewGroup(
	huh.NewSelect[string]().
		Key(keyControlIDs).
		// build control IDs based on type
		Options(controlIDs...).
		Title("Choose your control ID").
		Description("Placeholder").
		Value(&selectedControl),
),

The above code will generate an item that is formatted correctly however if the view height is < max items, scrolling will break. That means instead of the focused item being highlighted as you scroll, it will scroll past your view and scroll off screen. I suspect the View function responsible for calculating the height of all items does not account for \n in each item

Removing the \n immediately fixes the problem. However I don't think its \n per se, its really just any item that is two lines long as it happens for very long strings too (string > max width)

To Reproduce
Steps to reproduce the behavior:
Use the above code to create a form with new lines in it or ones that are really long

Expected behavior
I expect scrolling to not get cut off and work as expected, based on where the cursor is

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingselect

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions