Set default true for cleanable & trigger event when dropdown clean (#152)
This commit is contained in:
parent
36475bac76
commit
a02a6ed6b8
7 changed files with 18 additions and 18 deletions
|
|
@ -25,7 +25,7 @@ impl CalendarStory {
|
||||||
let now = chrono::Local::now().naive_local().date();
|
let now = chrono::Local::now().naive_local().date();
|
||||||
let date_picker = cx.new_view(|cx| {
|
let date_picker = cx.new_view(|cx| {
|
||||||
let mut picker = DatePicker::new("date_picker_medium", cx)
|
let mut picker = DatePicker::new("date_picker_medium", cx)
|
||||||
.cleanable(true)
|
.cleanable()
|
||||||
.width(px(220.));
|
.width(px(220.));
|
||||||
picker.set_date(now, cx);
|
picker.set_date(now, cx);
|
||||||
picker
|
picker
|
||||||
|
|
@ -47,7 +47,7 @@ impl CalendarStory {
|
||||||
let mut picker = DatePicker::new("date_range_picker", cx)
|
let mut picker = DatePicker::new("date_range_picker", cx)
|
||||||
.width(px(300.))
|
.width(px(300.))
|
||||||
.number_of_months(2)
|
.number_of_months(2)
|
||||||
.cleanable(true);
|
.cleanable();
|
||||||
picker.set_date((now, now.checked_add_days(Days::new(4)).unwrap()), cx);
|
picker.set_date((now, now.checked_add_days(Days::new(4)).unwrap()), cx);
|
||||||
picker
|
picker
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,8 @@ impl DropdownStory {
|
||||||
Country::new("Ecuador", "EC"),
|
Country::new("Ecuador", "EC"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let country_dropdown = cx.new_view(|cx| {
|
let country_dropdown =
|
||||||
Dropdown::new("dropdown-country", countries, Some(6), cx).cleanable(true)
|
cx.new_view(|cx| Dropdown::new("dropdown-country", countries, Some(6), cx).cleanable());
|
||||||
});
|
|
||||||
|
|
||||||
let fruits = SearchableVec::new(vec![
|
let fruits = SearchableVec::new(vec![
|
||||||
"Apple".into(),
|
"Apple".into(),
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ impl InputStory {
|
||||||
|
|
||||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
let input1 = cx.new_view(|cx| {
|
let input1 = cx.new_view(|cx| {
|
||||||
let mut input = TextInput::new(cx).cleanable(true);
|
let mut input = TextInput::new(cx).cleanable();
|
||||||
input.set_text(
|
input.set_text(
|
||||||
"Hello 世界,this is GPUI component, this is a long text.",
|
"Hello 世界,this is GPUI component, this is a long text.",
|
||||||
cx,
|
cx,
|
||||||
|
|
@ -64,7 +64,7 @@ impl InputStory {
|
||||||
cx.subscribe(&input2, Self::on_input_event).detach();
|
cx.subscribe(&input2, Self::on_input_event).detach();
|
||||||
|
|
||||||
let mask_input = cx.new_view(|cx| {
|
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_masked(true, cx);
|
||||||
input.set_text("this-is-password", cx);
|
input.set_text("this-is-password", cx);
|
||||||
input
|
input
|
||||||
|
|
@ -74,20 +74,20 @@ impl InputStory {
|
||||||
TextInput::new(cx)
|
TextInput::new(cx)
|
||||||
.prefix(|_| div().child(IconName::Search).ml_3())
|
.prefix(|_| div().child(IconName::Search).ml_3())
|
||||||
.placeholder("Search some thing...")
|
.placeholder("Search some thing...")
|
||||||
.cleanable(true)
|
.cleanable()
|
||||||
});
|
});
|
||||||
let suffix_input1 = cx.new_view(|cx| {
|
let suffix_input1 = cx.new_view(|cx| {
|
||||||
TextInput::new(cx)
|
TextInput::new(cx)
|
||||||
.suffix(|_| div().child(IconName::Info).mr_3())
|
.suffix(|_| div().child(IconName::Info).mr_3())
|
||||||
.placeholder("This input only support [a-zA-Z0-9] characters.")
|
.placeholder("This input only support [a-zA-Z0-9] characters.")
|
||||||
.pattern(regex::Regex::new(r"^[a-zA-Z0-9]*$").unwrap())
|
.pattern(regex::Regex::new(r"^[a-zA-Z0-9]*$").unwrap())
|
||||||
.cleanable(true)
|
.cleanable()
|
||||||
});
|
});
|
||||||
let both_input1 = cx.new_view(|cx| {
|
let both_input1 = cx.new_view(|cx| {
|
||||||
TextInput::new(cx)
|
TextInput::new(cx)
|
||||||
.prefix(|_| div().child(IconName::Search).ml_3())
|
.prefix(|_| div().child(IconName::Search).ml_3())
|
||||||
.suffix(|_| div().child(IconName::Info).mr_3())
|
.suffix(|_| div().child(IconName::Info).mr_3())
|
||||||
.cleanable(true)
|
.cleanable()
|
||||||
.placeholder("This input have prefix and suffix.")
|
.placeholder("This input have prefix and suffix.")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -371,8 +371,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set true to show the clear button when the input field is not empty.
|
/// Set true to show the clear button when the input field is not empty.
|
||||||
pub fn cleanable(mut self, cleanable: bool) -> Self {
|
pub fn cleanable(mut self) -> Self {
|
||||||
self.cleanable = cleanable;
|
self.cleanable = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,7 +468,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
|
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 {
|
fn display_title(&self, cx: &WindowContext) -> impl IntoElement {
|
||||||
|
|
|
||||||
|
|
@ -267,8 +267,8 @@ impl TextInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set true to show the clear button when the input field is not empty.
|
/// Set true to show the clear button when the input field is not empty.
|
||||||
pub fn cleanable(mut self, cleanable: bool) -> Self {
|
pub fn cleanable(mut self) -> Self {
|
||||||
self.cleanable = cleanable;
|
self.cleanable = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ where
|
||||||
.appearance(false)
|
.appearance(false)
|
||||||
.prefix(|_| IconName::Search)
|
.prefix(|_| IconName::Search)
|
||||||
.placeholder("Search...")
|
.placeholder("Search...")
|
||||||
.cleanable(true)
|
.cleanable()
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.subscribe(&query_input, Self::on_query_input_event)
|
cx.subscribe(&query_input, Self::on_query_input_event)
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ impl DatePicker {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set true to show the clear button when the input field is not empty.
|
/// Set true to show the clear button when the input field is not empty.
|
||||||
pub fn cleanable(mut self, cleanable: bool) -> Self {
|
pub fn cleanable(mut self) -> Self {
|
||||||
self.cleanable = cleanable;
|
self.cleanable = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue