dropdown: Fix Dropdown placeholder to support change locale. (#203)

This commit is contained in:
Jason Lee 2024-09-02 14:57:53 +08:00 committed by GitHub
parent af09525c1e
commit f611b599aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -218,7 +218,7 @@ pub struct Dropdown<D: DropdownDelegate + 'static> {
icon: Option<IconName>, icon: Option<IconName>,
open: bool, open: bool,
cleanable: bool, cleanable: bool,
placeholder: SharedString, placeholder: Option<SharedString>,
title_prefix: Option<SharedString>, title_prefix: Option<SharedString>,
selected_value: Option<<D::Item as DropdownItem>::Value>, selected_value: Option<<D::Item as DropdownItem>::Value>,
empty: Option<Box<dyn Fn(&WindowContext) -> AnyElement + 'static>>, empty: Option<Box<dyn Fn(&WindowContext) -> AnyElement + 'static>>,
@ -327,7 +327,7 @@ where
let mut this = Self { let mut this = Self {
id: id.into(), id: id.into(),
focus_handle, focus_handle,
placeholder: t!("Dropdown.placeholder").into(), placeholder: None,
list, list,
size: Size::Medium, size: Size::Medium,
icon: None, icon: None,
@ -359,7 +359,7 @@ where
/// Set the placeholder for display when dropdown value is empty. /// Set the placeholder for display when dropdown value is empty.
pub fn placeholder(mut self, placeholder: impl Into<SharedString>) -> Self { pub fn placeholder(mut self, placeholder: impl Into<SharedString>) -> Self {
self.placeholder = placeholder.into(); self.placeholder = Some(placeholder.into());
self self
} }
@ -518,9 +518,11 @@ where
})) }))
.child(title.clone()) .child(title.clone())
} else { } else {
div() div().text_color(cx.theme().accent_foreground).child(
.text_color(cx.theme().accent_foreground) self.placeholder
.child(self.placeholder.clone()) .clone()
.unwrap_or_else(|| t!("Dropdown.placeholder").into()),
)
}; };
title.when(self.disabled, |this| { title.when(self.disabled, |this| {