list: Export query_input for support update the default Query Input. (#794)
## Break Change
- Updated `set_placeholder` and `set_pattern` method to add `window` and
`cx` argument.
```diff
- fn set_placeholder(&mut self, placeholder: impl Into<SharedString>)
+ fn set_placeholder(&mut self, placeholder: impl Into<SharedString>, _:
&Window, cx: &mut Context<Self>)
- fn set_pattern(&mut self, pattern: regex::Regex)
+ fn set_pattern(&mut self, pattern: regex::Regex, window: &mut Window,
cx: &mut Context<Self>)
```
This commit is contained in:
parent
0c4a0538e6
commit
8d37716b88
4 changed files with 38 additions and 10 deletions
|
|
@ -257,6 +257,11 @@ impl ModalStory {
|
||||||
let list = cx.new(|cx| {
|
let list = cx.new(|cx| {
|
||||||
let mut list = List::new(delegate, window, cx);
|
let mut list = List::new(delegate, window, cx);
|
||||||
list.focus(window, cx);
|
list.focus(window, cx);
|
||||||
|
if let Some(query_input) = list.query_input() {
|
||||||
|
query_input.update(cx, |input, cx| {
|
||||||
|
input.set_placeholder("Pickup your country...", window, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
list
|
list
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -646,8 +646,14 @@ impl TextInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the placeholder text of the input field with reference.
|
/// Set the placeholder text of the input field with reference.
|
||||||
pub fn set_placeholder(&mut self, placeholder: impl Into<SharedString>) {
|
pub fn set_placeholder(
|
||||||
|
&mut self,
|
||||||
|
placeholder: impl Into<SharedString>,
|
||||||
|
_: &Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
self.placeholder = placeholder.into();
|
self.placeholder = placeholder.into();
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
|
@ -671,7 +677,12 @@ impl TextInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the regular expression pattern of the input field with reference.
|
/// Set the regular expression pattern of the input field with reference.
|
||||||
pub fn set_pattern(&mut self, pattern: regex::Regex) {
|
pub fn set_pattern(
|
||||||
|
&mut self,
|
||||||
|
pattern: regex::Regex,
|
||||||
|
_window: &mut Window,
|
||||||
|
_cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
self.pattern = Some(pattern);
|
self.pattern = Some(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,12 @@ impl NumberInput {
|
||||||
pub fn placeholder(
|
pub fn placeholder(
|
||||||
self,
|
self,
|
||||||
placeholder: impl Into<SharedString>,
|
placeholder: impl Into<SharedString>,
|
||||||
_: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.input
|
self.input.update(cx, |input, cx| {
|
||||||
.update(cx, |input, _| input.set_placeholder(placeholder));
|
input.set_placeholder(placeholder, window, cx)
|
||||||
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,16 +74,22 @@ impl NumberInput {
|
||||||
pub fn set_placeholder(
|
pub fn set_placeholder(
|
||||||
&self,
|
&self,
|
||||||
text: impl Into<SharedString>,
|
text: impl Into<SharedString>,
|
||||||
_window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
self.input.update(cx, |input, _| {
|
self.input.update(cx, |input, cx| {
|
||||||
input.set_placeholder(text);
|
input.set_placeholder(text, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pattern(self, pattern: regex::Regex, _: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn pattern(
|
||||||
self.input.update(cx, |input, _| input.set_pattern(pattern));
|
self,
|
||||||
|
pattern: regex::Regex,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> Self {
|
||||||
|
self.input
|
||||||
|
.update(cx, |input, cx| input.set_pattern(pattern, window, cx));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,11 @@ where
|
||||||
self.query_input = Some(query_input);
|
self.query_input = Some(query_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the query input entity.
|
||||||
|
pub fn query_input(&self) -> Option<&Entity<TextInput>> {
|
||||||
|
self.query_input.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delegate(&self) -> &D {
|
pub fn delegate(&self) -> &D {
|
||||||
&self.delegate
|
&self.delegate
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue