From f611b599aafc49d69aeb9503f41c747ca200e5a5 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 2 Sep 2024 14:57:53 +0800 Subject: [PATCH] dropdown: Fix Dropdown placeholder to support change locale. (#203) --- crates/ui/src/dropdown.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 8c1160d4..edb4d89b 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -218,7 +218,7 @@ pub struct Dropdown { icon: Option, open: bool, cleanable: bool, - placeholder: SharedString, + placeholder: Option, title_prefix: Option, selected_value: Option<::Value>, empty: Option AnyElement + 'static>>, @@ -327,7 +327,7 @@ where let mut this = Self { id: id.into(), focus_handle, - placeholder: t!("Dropdown.placeholder").into(), + placeholder: None, list, size: Size::Medium, icon: None, @@ -359,7 +359,7 @@ where /// Set the placeholder for display when dropdown value is empty. pub fn placeholder(mut self, placeholder: impl Into) -> Self { - self.placeholder = placeholder.into(); + self.placeholder = Some(placeholder.into()); self } @@ -518,9 +518,11 @@ where })) .child(title.clone()) } else { - div() - .text_color(cx.theme().accent_foreground) - .child(self.placeholder.clone()) + div().text_color(cx.theme().accent_foreground).child( + self.placeholder + .clone() + .unwrap_or_else(|| t!("Dropdown.placeholder").into()), + ) }; title.when(self.disabled, |this| {