Skip to content

fix(textinput): stop applying Text/Placeholder style to padding#973

Open
c-tonneslan wants to merge 1 commit into
charmbracelet:masterfrom
c-tonneslan:fix/textinput-textstyle-consistency
Open

fix(textinput): stop applying Text/Placeholder style to padding#973
c-tonneslan wants to merge 1 commit into
charmbracelet:masterfrom
c-tonneslan:fix/textinput-textstyle-consistency

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #245.

When Width is set, View pads the input out to that width with spaces. Both the text path and the placeholder path were running those padding spaces through the active style, so setting a background color on Text or Placeholder ended up coloring well past the actual content. The original issue notes that PlaceholderStyle looked like it scoped to just the placeholder text and TextStyle didn't, but in current main it's actually both that extend past, just in slightly different shapes.

Easiest way to make them agree: drop the styling on the padding spaces in both paths. Style now covers the text, the rest is empty.

meowgorithm called this out as the preferred direction in the issue:

The way the placeholder is rendering is the correct one and we should normalize the other case accordingly.

Test plan

go test ./textinput/...

Added TestTextStyleAndPlaceholderStyleScopeMatch which sets a background style on both Focused.Text and Focused.Placeholder and checks that the padding suffix is unstyled spaces.

When Width is set, View pads the input out to that width with spaces.
Both the text path and the placeholder path were running those padding
spaces through the active style, so setting a background color on either
Text or Placeholder caused the bg to extend well past the actual content,
which doesn't match how a placeholder usually reads in CSS terms (you
expect the style to scope to the text itself).

Drop the styling on the padding in both code paths so the two views
behave the same way: style covers the text, the rest is empty space.
Closes charmbracelet#245.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@c-tonneslan c-tonneslan requested a review from meowgorithm as a code owner May 15, 2026 14:18
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