[GH-ISSUE #792] Input Autocomplete list still visible after losing focus #580

Closed
opened 2026-03-04 01:06:13 +03:00 by kerem · 1 comment
Owner

Originally created by @carpii on GitHub (Jan 2, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/792

Lets say an Input has an autocomplete list open.
Now move the focus to a different Form item (using either SHIFT+TAB or simply clicking with mouse)
The list does not close, and then the Form output starts overlapping the autocomplete list

I've tested this using the previous tview release too, but it doesn't seem to be a regression related to the recent key handling changes


package ui

import (
	"os"
	"sort"
	"strings"

	"github.com/rivo/tview"
)

var testlist = []string{
	"Taxes: Import Tax",
	"Taxes: Income Tax",
	"Taxes: National Insurance",
	"Taxes: Road Tax",
	"Taxes: VAT Bill",
	"TaxDummy: foobar",
	"TaxDummy: lorem ipsum",
	"TaxFoo: foo",
	"Random: TaxFoobar",
}

func uitest_category_search_autocomplete(currentText string) (entries []string) {
	for i := range testlist {
		if strings.Contains(strings.ToUpper(testlist[i]), strings.ToUpper(currentText)) {
			entries = append(entries, testlist[i])
		}
	}
	if len(entries) < 1 {
		entries = nil
	}
	return entries
}

func UI_test() {
	app := tview.NewApplication().EnableMouse(true)

	category_search_input := tview.NewInputField().
		SetLabel("Dummy Dropdown: ").
		SetFieldWidth(30)

	category_search_input.SetAutocompleteFunc(func(currentText string) (entries []string) {
		if currentText == "" {
			return nil
		}
		return uitest_category_search_autocomplete(currentText)
	})

	form := tview.NewForm().
		AddInputField("Dummy Input", "", 0, nil, nil).
		AddFormItem(category_search_input).
		AddInputField("Dummy Input", "", 0, nil, nil).
		AddButton("Save", nil).
		AddButton("Cancel", func() { os.Exit(0) })

	if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil {
		panic(err)
	}
}

Originally created by @carpii on GitHub (Jan 2, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/792 Lets say an Input has an autocomplete list open. Now move the focus to a different Form item (using either SHIFT+TAB or simply clicking with mouse) The list does not close, and then the Form output starts overlapping the autocomplete list I've tested this using the previous tview release too, but it doesn't seem to be a regression related to the recent key handling changes ![](https://i.imgur.com/3EH71v3.png) ---- ```` package ui import ( "os" "sort" "strings" "github.com/rivo/tview" ) var testlist = []string{ "Taxes: Import Tax", "Taxes: Income Tax", "Taxes: National Insurance", "Taxes: Road Tax", "Taxes: VAT Bill", "TaxDummy: foobar", "TaxDummy: lorem ipsum", "TaxFoo: foo", "Random: TaxFoobar", } func uitest_category_search_autocomplete(currentText string) (entries []string) { for i := range testlist { if strings.Contains(strings.ToUpper(testlist[i]), strings.ToUpper(currentText)) { entries = append(entries, testlist[i]) } } if len(entries) < 1 { entries = nil } return entries } func UI_test() { app := tview.NewApplication().EnableMouse(true) category_search_input := tview.NewInputField(). SetLabel("Dummy Dropdown: "). SetFieldWidth(30) category_search_input.SetAutocompleteFunc(func(currentText string) (entries []string) { if currentText == "" { return nil } return uitest_category_search_autocomplete(currentText) }) form := tview.NewForm(). AddInputField("Dummy Input", "", 0, nil, nil). AddFormItem(category_search_input). AddInputField("Dummy Input", "", 0, nil, nil). AddButton("Save", nil). AddButton("Cancel", func() { os.Exit(0) }) if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil { panic(err) } } ````
kerem closed this issue 2026-03-04 01:06:13 +03:00
Author
Owner

@rivo commented on GitHub (Jan 4, 2023):

Interesting that it wasn't noticed before. Should be fixed now.

<!-- gh-comment-id:1370896457 --> @rivo commented on GitHub (Jan 4, 2023): Interesting that it wasn't noticed before. Should be fixed now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#580
No description provided.