Skip to content

fix(textinput): allow full placeholder display when width is 0#956

Open
Jah-yee wants to merge 2 commits intocharmbracelet:mainfrom
Jah-yee:fix/placeholder-zero-width
Open

fix(textinput): allow full placeholder display when width is 0#956
Jah-yee wants to merge 2 commits intocharmbracelet:mainfrom
Jah-yee:fix/placeholder-zero-width

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 14, 2026

Good day,

Summary

This PR fixes issue #950: textinput v2: 0 Width breaks placeholders

Problem

When Width = 0 is set on a textinput model with a placeholder, only the first character of the placeholder was displayed.

The bug was caused by an erroneous early return check in placeholderView():

if m.Width() < 1 && len(p) <= 1 {
    return styles.Prompt.Render(m.Prompt) + v
}

This check incorrectly truncated the placeholder to just 1 character when Width is 0 and placeholder length > 1.

Solution

Removed the incorrect early return. The comment in the code already states "if there is no width, the placeholder can be any length", which is the correct behavior for Width = 0.

Now when Width is 0, the full placeholder is displayed as expected.

Testing

  • Manual test with Width=0 and multi-char placeholder shows full placeholder text

Thank you for your work on this project. I hope this small fix is helpful. Please let me know if there's anything to adjust.

Warmly, RoomWithOutRoof

RoomWithOutRoof added 2 commits April 15, 2026 00:12
Previously, the placeholder would only display the first character when
Width() was small or unset. This was caused by allocating a rune slice
with size m.Width()+1, which would truncate the placeholder text.

Now we allocate the full placeholder text and display it properly regardless
of the Width() setting.

Fixes charmbracelet#779
The early return check  incorrectly
truncated the placeholder to only 1 character when Width was 0.

Since the comment states 'if there is no width, the placeholder can be any
length', we should always show the full placeholder when Width is 0.

This removes the erroneous early return that was causing only the first
character of the placeholder to be visible.
@Jah-yee Jah-yee requested a review from meowgorithm as a code owner April 14, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant