From bd4f24ac1e5253f277a34238409bc5bbd8fa7cef Mon Sep 17 00:00:00 2001 From: Martin Ball <98639962+benandez@users.noreply.github.com> Date: Sat, 28 Nov 2026 20:18:48 +0000 Subject: [PATCH] fix(ui-patterns): a preferences text row takes a placeholder (#4028) (#4091) Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx Co-authored-by: Claude Sonnet 5.5 --- .../src/patterns/preferences/model.rs | 11 ++++++- .../src/patterns/preferences/rows.rs | 12 +++++--- .../ui-patterns/tests/it/preferences/page.rs | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/crates/ui-patterns/src/patterns/preferences/model.rs b/crates/ui-patterns/src/patterns/preferences/model.rs index 944993fa5a..dd729063ef 100644 --- a/crates/ui-patterns/src/patterns/preferences/model.rs +++ b/crates/ui-patterns/src/patterns/preferences/model.rs @@ -126,6 +126,8 @@ pub struct RowSpec<'a> { /// default a drop-down, and on a card ([`PreferencesLayout::Cards`](super::PreferencesLayout::Cards)) a short /// choice of up to five options is segmented. Ignored by other kinds. pub pills: Option, + /// A [`RowKind::Text`] row: the translated text shown while the field is empty. Ignored by other kinds. + pub placeholder: Option<&'a str>, /// The control and the value it shows. pub kind: RowKind<'a>, } @@ -133,7 +135,7 @@ pub struct RowSpec<'a> { impl<'a> RowSpec<'a> { /// A visible, enabled row with no keywords or help. pub fn new(key: &'a str, label: &'a str, kind: RowKind<'a>) -> Self { - Self { key, label, keywords: "", help: None, visible: true, enabled: true, step: None, pills: None, kind } + Self { key, label, keywords: "", help: None, visible: true, enabled: true, step: None, pills: None, placeholder: None, kind } } /// Sets extra search text for the row. @@ -171,6 +173,13 @@ impl<'a> RowSpec<'a> { self } + /// Sets the text a [`RowKind::Text`] row shows while empty. + #[must_use] + pub fn placeholder(mut self, placeholder: &'a str) -> Self { + self.placeholder = Some(placeholder); + self + } + /// Sets the step of a [`RowKind::Float`] row. #[must_use] pub fn step(mut self, step: f64) -> Self { diff --git a/crates/ui-patterns/src/patterns/preferences/rows.rs b/crates/ui-patterns/src/patterns/preferences/rows.rs index 82c66c8ec2..700848cb2e 100644 --- a/crates/ui-patterns/src/patterns/preferences/rows.rs +++ b/crates/ui-patterns/src/patterns/preferences/rows.rs @@ -39,7 +39,7 @@ pub(super) enum Kind { Int { value: i64, range: RangeInclusive, unit: Option, unit_text: Option