Skip to content

Commit

Permalink
Don't render suggestions when textinput is not focused.
Browse files Browse the repository at this point in the history
This can look confusing in forms otherwise.
  • Loading branch information
elProxy committed Jan 8, 2025
1 parent e5296a2 commit c137cc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions textinput/textinput_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package textinput

import (
"strings"
"testing"
)

Expand Down Expand Up @@ -29,4 +30,9 @@ 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())
}
}

0 comments on commit c137cc8

Please sign in to comment.