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:
Jason Lee 2025-04-15 20:36:04 +08:00 committed by GitHub
parent 0c4a0538e6
commit 8d37716b88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 10 deletions

View file

@ -257,6 +257,11 @@ impl ModalStory {
let list = cx.new(|cx| {
let mut list = List::new(delegate, 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
});

View file

@ -646,8 +646,14 @@ impl TextInput {
}
/// 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();
cx.notify();
}
/// 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.
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);
}

View file

@ -57,11 +57,12 @@ impl NumberInput {
pub fn placeholder(
self,
placeholder: impl Into<SharedString>,
_: &mut Window,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
self.input
.update(cx, |input, _| input.set_placeholder(placeholder));
self.input.update(cx, |input, cx| {
input.set_placeholder(placeholder, window, cx)
});
self
}
@ -73,16 +74,22 @@ impl NumberInput {
pub fn set_placeholder(
&self,
text: impl Into<SharedString>,
_window: &mut Window,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.input.update(cx, |input, _| {
input.set_placeholder(text);
self.input.update(cx, |input, cx| {
input.set_placeholder(text, window, cx);
});
}
pub fn pattern(self, pattern: regex::Regex, _: &mut Window, cx: &mut Context<Self>) -> Self {
self.input.update(cx, |input, _| input.set_pattern(pattern));
pub fn 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
}

View file

@ -245,6 +245,11 @@ where
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 {
&self.delegate
}