fix(textinput): improve placeholder (#768)

similar to #767 but for textinputs
This commit is contained in:
Carlos Alexandro Becker
2025-10-01 10:22:53 -03:00
committed by GitHub
parent d6934a175b
commit 49ff5c03b7
2 changed files with 49 additions and 19 deletions
+38
View File
@@ -5,6 +5,8 @@ import (
"strconv"
"strings"
"testing"
tea "github.com/charmbracelet/bubbletea"
)
func Test_CurrentSuggestion(t *testing.T) {
@@ -46,6 +48,30 @@ func Test_SlicingOutsideCap(t *testing.T) {
textinput.View()
}
func TestChinesePlaceholder(t *testing.T) {
textinput := New()
textinput.Placeholder = "输入消息..."
textinput.Width = 20
got := textinput.View()
expected := "> 输入消息... "
if got != expected {
t.Fatalf("expected %q but got %q", expected, got)
}
}
func TestPlaceholderTruncate(t *testing.T) {
textinput := New()
textinput.Placeholder = "A very long placeholder, or maybe not so much"
textinput.Width = 10
got := textinput.View()
expected := "> A very …"
if got != expected {
t.Fatalf("expected %q but got %q", expected, got)
}
}
func ExampleValidateFunc() {
creditCardNumber := New()
creditCardNumber.Placeholder = "4505 **** **** 1234"
@@ -78,3 +104,15 @@ func ExampleValidateFunc() {
return err
}
}
func keyPress(key rune) tea.Msg {
return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{key}, Alt: false}
}
func sendString(m Model, str string) Model {
for _, k := range str {
m, _ = m.Update(keyPress(k))
}
return m
}