2024-01-03 20:52:56 +08:00
|
|
|
# Auto Complete
|
|
|
|
|
|
|
|
```rust demo
|
2024-06-14 17:23:02 +08:00
|
|
|
let value = RwSignal::new(String::new());
|
|
|
|
let options = Memo::<Vec<_>>::new(move |_| {
|
2024-01-03 20:52:56 +08:00
|
|
|
let prefix = value
|
|
|
|
.get()
|
|
|
|
.split_once('@')
|
|
|
|
.map_or(value.get(), |v| v.0.to_string());
|
|
|
|
vec!["@gmail.com", "@163.com"]
|
|
|
|
.into_iter()
|
2024-06-14 17:23:02 +08:00
|
|
|
.map(|suffix| (format!("{prefix}{suffix}"), format!("{prefix}{suffix}")))
|
2024-01-03 20:52:56 +08:00
|
|
|
.collect()
|
|
|
|
});
|
|
|
|
|
|
|
|
view! {
|
2024-06-14 17:23:02 +08:00
|
|
|
<AutoComplete value placeholder="Email">
|
|
|
|
<For
|
|
|
|
each=move || options.get()
|
|
|
|
key=|option| option.0.clone()
|
|
|
|
let:option
|
|
|
|
>
|
2024-07-22 16:28:38 +08:00
|
|
|
<AutoCompleteOption value=option.0>
|
2024-06-14 17:23:02 +08:00
|
|
|
{option.1}
|
2024-07-02 07:18:40 +00:00
|
|
|
</AutoCompleteOption>
|
2024-06-14 17:23:02 +08:00
|
|
|
</For>
|
|
|
|
</AutoComplete>
|
2024-01-03 20:52:56 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Disabled
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<AutoComplete placeholder="Email" disabled=true/>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Prefix & Suffix
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
view! {
|
|
|
|
<Space vertical=true>
|
|
|
|
<AutoComplete>
|
|
|
|
<AutoCompletePrefix slot>
|
2024-01-26 23:10:17 +09:00
|
|
|
<Icon icon=icondata::AiUserOutlined/>
|
2024-01-03 20:52:56 +08:00
|
|
|
</AutoCompletePrefix>
|
|
|
|
</AutoComplete>
|
|
|
|
<AutoComplete>
|
|
|
|
<AutoCompleteSuffix slot>
|
2024-01-26 23:10:17 +09:00
|
|
|
<Icon icon=icondata::AiGithubOutlined/>
|
2024-01-03 20:52:56 +08:00
|
|
|
</AutoCompleteSuffix>
|
|
|
|
</AutoComplete>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### AutoComplete Props
|
|
|
|
|
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
2024-02-09 22:44:22 +08:00
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Additional classes for the autocomplete element. |
|
|
|
|
| value | `Model<String>` | `Default::default()` | Input of autocomplete. |
|
|
|
|
| placeholder | `OptionalProp<RwSignal<String>>` | `Default::default()` | Autocomplete's placeholder. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| options | `MaybeSignal<Vec<AutoCompleteOption>>` | `Default::default()` | Options to autocomplete from. |
|
|
|
|
| disabled | `MaybeSignal<bool>` | `false` | Whether the input is disabled. |
|
2024-02-22 10:38:30 +03:00
|
|
|
| allow_free_input | `bool` | `false` | Whether free text input is allowed. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| invalid | `MaybeSignal<bool>` | `false` | Whether the input is invalid. |
|
|
|
|
| clear_after_select | `MaybeSignal<bool>` | `false` | Whether to clear after selection. |
|
2024-03-15 23:50:39 +08:00
|
|
|
| blur_after_select | `MaybeSignal<bool>` | `false` | Whether to blur after selection. |
|
2024-01-03 20:52:56 +08:00
|
|
|
| on_select | `Option<Callback<String>>` | `None` | On select callback function. |
|
|
|
|
| attr: | `Vec<(&'static str, Attribute)>` | `Default::default()` | The dom attrs of the input element inside the component. |
|
|
|
|
|
|
|
|
### AutoCompleteOption Properties
|
|
|
|
|
|
|
|
| Name | Type | Description |
|
|
|
|
| ----- | -------- | ------------------- |
|
|
|
|
| value | `String` | Option ID. |
|
|
|
|
| label | `String` | Option label value. |
|
|
|
|
|
|
|
|
### AutoCompleteOption Slots
|
|
|
|
|
|
|
|
| Name | Default | Description |
|
|
|
|
| ------------------ | ------- | --------------------------- |
|
|
|
|
| AutoCompletePrefix | `None` | AutoCompletePrefix content. |
|
|
|
|
| AutoCompleteSuffix | `None` | AutoCompleteSuffix content. |
|
|
|
|
|
|
|
|
### AutoComplete Ref
|
|
|
|
|
|
|
|
| Name | Type | Description |
|
|
|
|
| ----- | ----------- | ------------------------ |
|
|
|
|
| focus | `Fn(&self)` | Focus the input element. |
|
|
|
|
| blur | `Fn(&self)` | Blur the input element. |
|