diff --git a/crates/story/src/calendar_story.rs b/crates/story/src/calendar_story.rs index 95aaf2a6..8499a18f 100644 --- a/crates/story/src/calendar_story.rs +++ b/crates/story/src/calendar_story.rs @@ -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 }); diff --git a/crates/story/src/dropdown_story.rs b/crates/story/src/dropdown_story.rs index e6074dab..b1d0d403 100644 --- a/crates/story/src/dropdown_story.rs +++ b/crates/story/src/dropdown_story.rs @@ -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(), diff --git a/crates/story/src/input_story.rs b/crates/story/src/input_story.rs index 66ff8a96..5698ea18 100644 --- a/crates/story/src/input_story.rs +++ b/crates/story/src/input_story.rs @@ -49,7 +49,7 @@ impl InputStory { fn new(cx: &mut ViewContext) -> 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.") }); diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 36f304c0..dbd716e6 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -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.set_selected_index(None, cx) + self.set_selected_index(None, cx); + cx.emit(DropdownEvent::Confirm(None)); } fn display_title(&self, cx: &WindowContext) -> impl IntoElement { diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index 763a493d..3485e1d9 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -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 } diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index bff5e605..da1764da 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -91,7 +91,7 @@ where .appearance(false) .prefix(|_| IconName::Search) .placeholder("Search...") - .cleanable(true) + .cleanable() }); cx.subscribe(&query_input, Self::on_query_input_event) diff --git a/crates/ui/src/time/date_picker.rs b/crates/ui/src/time/date_picker.rs index ed83de1d..1a256f7f 100644 --- a/crates/ui/src/time/date_picker.rs +++ b/crates/ui/src/time/date_picker.rs @@ -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 }