diff --git a/textinput/textinput.go b/textinput/textinput.go index 66e45185..1b44ab26 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -665,7 +665,7 @@ func (m Model) View() string { v += styleText(m.echoTransform(string(value[pos+1:]))) // text after cursor v += m.completionView(0) // suggested completion } else { - if m.canAcceptSuggestion() { + if m.focus && m.canAcceptSuggestion() { suggestion := m.matchedSuggestions[m.currentSuggestionIndex] if len(value) < len(suggestion) { m.Cursor.TextStyle = m.CompletionStyle diff --git a/textinput/textinput_test.go b/textinput/textinput_test.go index 95ef0c61..6c288abb 100644 --- a/textinput/textinput_test.go +++ b/textinput/textinput_test.go @@ -1,6 +1,7 @@ package textinput import ( + "strings" "testing" ) @@ -29,6 +30,11 @@ func Test_CurrentSuggestion(t *testing.T) { if suggestion != expected { t.Fatalf("Error: expected first suggestion but was %s", suggestion) } + + textinput.Blur() + if strings.HasSuffix(textinput.View(), "test2") { + t.Fatalf("Error: suggestions should not be rendered when input isn't focused. expected \"> test\" but got \"%s\"", textinput.View()) + } } func Test_SlicingOutsideCap(t *testing.T) {