Skip to content

feat: set placeholder to text#112

Open
janTatesa wants to merge 2 commits into
rhysd:mainfrom
janTatesa:set_placeholder_to_text
Open

feat: set placeholder to text#112
janTatesa wants to merge 2 commits into
rhysd:mainfrom
janTatesa:set_placeholder_to_text

Conversation

@janTatesa
Copy link
Copy Markdown

Resolves #110

Copy link
Copy Markdown
Contributor

@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote some review comments on this a while back, but never hit submit. Apologies.
I think this is generally a good idea. Just some small things I'd suggest doing.

I'm in general approval of the idea. Needs some tests if that's possible.

Comment thread src/textarea.rs Outdated
Comment thread src/textarea.rs
Comment thread src/widget.rs Outdated
pm100 added a commit to pm100/ratatui-textarea that referenced this pull request Mar 24, 2026
The placeholder field changes from (String, Style) to ratatui_core::text::Text,
allowing rich styled content (multiple spans with different colours/styles)
to be set as a placeholder.

New API:
- set_placeholder(impl Into<Text>) - primary setter
- placeholder() -> &Text - getter

The old set_placeholder_text/set_placeholder_style/placeholder_text/
placeholder_style methods are kept but marked deprecated.

Ported from rhysd/tui-textarea#112 (original author @janTatesa),
adapted to use ratatui-core/ratatui-widgets instead of ratatui.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pm100 added a commit to pm100/ratatui-textarea that referenced this pull request Mar 24, 2026
The placeholder field changes from (String, Style) to ratatui_core::text::Text,
allowing rich styled content (multiple spans with different colours/styles)
to be set as a placeholder.

New API:
- set_placeholder(impl Into<Text>) - primary setter
- placeholder() -> &Text - getter

The old set_placeholder_text/set_placeholder_style/placeholder_text/
placeholder_style methods are kept but marked deprecated.

Ported from rhysd/tui-textarea#112 (original author @janTatesa),
adapted to use ratatui-core/ratatui-widgets instead of ratatui.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pm100 added a commit to ratatui/ratatui-textarea that referenced this pull request Mar 29, 2026
* feat: upgrade placeholder to accept styled Text

The placeholder field changes from (String, Style) to ratatui_core::text::Text,
allowing rich styled content (multiple spans with different colours/styles)
to be set as a placeholder.

New API:
- set_placeholder(impl Into<Text>) - primary setter
- placeholder() -> &Text - getter

The old set_placeholder_text/set_placeholder_style/placeholder_text/
placeholder_style methods are kept but marked deprecated.

Ported from rhysd/tui-textarea#112 (original author @janTatesa),
adapted to use ratatui-core/ratatui-widgets instead of ratatui.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: address PR review issues for styled placeholder

- Add set_styled_placeholder(impl Into<Text>) alongside the existing
  set_placeholder_text / set_placeholder_style / placeholder_text /
  placeholder_style methods (no deprecations — both APIs coexist)
- Fix set_placeholder_text('') to clear placeholder.lines, restoring
  the original disabled-placeholder semantics
- Fix rendering guard: placeholder is only rendered when
  placeholder.lines is non-empty, so an unset placeholder no longer
  produces a styled-but-invisible paragraph on empty textarea
- Restore cursor Span in placeholder rendering (was dropped when
  placeholder_widget() was removed by the PR)
- Add placeholder_demo example covering all API combinations

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* style: apply cargo fmt

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: use div_ceil in placeholder_demo (clippy)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Placeholder should be Span<'a>

2 participants