Set default true for cleanable & trigger event when dropdown clean (#152)

This commit is contained in:
Floyd Wang 2024-08-15 18:01:43 +08:00 committed by GitHub
parent 36475bac76
commit a02a6ed6b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 18 deletions

View file

@ -25,7 +25,7 @@ impl CalendarStory {
let now = chrono::Local::now().naive_local().date();
let date_picker = cx.new_view(|cx| {
let mut picker = DatePicker::new("date_picker_medium", cx)
.cleanable(true)
.cleanable()
.width(px(220.));
picker.set_date(now, cx);
picker
@ -47,7 +47,7 @@ impl CalendarStory {
let mut picker = DatePicker::new("date_range_picker", cx)
.width(px(300.))
.number_of_months(2)
.cleanable(true);
.cleanable();
picker.set_date((now, now.checked_add_days(Days::new(4)).unwrap()), cx);
picker
});

View file

@ -60,9 +60,8 @@ impl DropdownStory {
Country::new("Ecuador", "EC"),
];
let country_dropdown = cx.new_view(|cx| {
Dropdown::new("dropdown-country", countries, Some(6), cx).cleanable(true)
});
let country_dropdown =
cx.new_view(|cx| Dropdown::new("dropdown-country", countries, Some(6), cx).cleanable());
let fruits = SearchableVec::new(vec![
"Apple".into(),

View file

@ -49,7 +49,7 @@ impl InputStory {
fn new(cx: &mut ViewContext<Self>) -> Self {
let input1 = cx.new_view(|cx| {
let mut input = TextInput::new(cx).cleanable(true);
let mut input = TextInput::new(cx).cleanable();
input.set_text(
"Hello 世界this is GPUI component, this is a long text.",
cx,
@ -64,7 +64,7 @@ impl InputStory {
cx.subscribe(&input2, Self::on_input_event).detach();
let mask_input = cx.new_view(|cx| {
let mut input = TextInput::new(cx).cleanable(true);
let mut input = TextInput::new(cx).cleanable();
input.set_masked(true, cx);
input.set_text("this-is-password", cx);
input
@ -74,20 +74,20 @@ impl InputStory {
TextInput::new(cx)
.prefix(|_| div().child(IconName::Search).ml_3())
.placeholder("Search some thing...")
.cleanable(true)
.cleanable()
});
let suffix_input1 = cx.new_view(|cx| {
TextInput::new(cx)
.suffix(|_| div().child(IconName::Info).mr_3())
.placeholder("This input only support [a-zA-Z0-9] characters.")
.pattern(regex::Regex::new(r"^[a-zA-Z0-9]*$").unwrap())
.cleanable(true)
.cleanable()
});
let both_input1 = cx.new_view(|cx| {
TextInput::new(cx)
.prefix(|_| div().child(IconName::Search).ml_3())
.suffix(|_| div().child(IconName::Info).mr_3())
.cleanable(true)
.cleanable()
.placeholder("This input have prefix and suffix.")
});

View file

@ -371,8 +371,8 @@ where
}
/// Set true to show the clear button when the input field is not empty.
pub fn cleanable(mut self, cleanable: bool) -> Self {
self.cleanable = cleanable;
pub fn cleanable(mut self) -> Self {
self.cleanable = true;
self
}
@ -468,7 +468,8 @@ where
}
fn clean(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
self.set_selected_index(None, cx)
self.set_selected_index(None, cx);
cx.emit(DropdownEvent::Confirm(None));
}
fn display_title(&self, cx: &WindowContext) -> impl IntoElement {

View file

@ -267,8 +267,8 @@ impl TextInput {
}
/// Set true to show the clear button when the input field is not empty.
pub fn cleanable(mut self, cleanable: bool) -> Self {
self.cleanable = cleanable;
pub fn cleanable(mut self) -> Self {
self.cleanable = true;
self
}

View file

@ -91,7 +91,7 @@ where
.appearance(false)
.prefix(|_| IconName::Search)
.placeholder("Search...")
.cleanable(true)
.cleanable()
});
cx.subscribe(&query_input, Self::on_query_input_event)

View file

@ -76,8 +76,8 @@ impl DatePicker {
}
/// Set true to show the clear button when the input field is not empty.
pub fn cleanable(mut self, cleanable: bool) -> Self {
self.cleanable = cleanable;
pub fn cleanable(mut self) -> Self {
self.cleanable = true;
self
}