Autocomplete
A text input that filters a list of suggestions as you type.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase autocomplete
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase autocomplete
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::autocomplete::{
AutocompleteRoot,
AutocompleteValue,
};
AutocompleteRoot::new()
.child(
AutocompleteValue::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#AutocompleteRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::autocomplete::AutocompleteRoot;
AutocompleteRoot::new()
.id("example-id")
.name("name")
.mode(/* mode: AutocompleteMode */)
.default_value(/* default_value: impl Into<SharedString> */)
.value(/* value: impl Into<SharedString> */)
.on_value_change(|/* callback arguments */| { /* handle change */ })
.default_open(true)
.open(true)
.on_open_change(|/* callback arguments */| { /* handle change */ })
.on_item_highlighted(|/* callback arguments */| { /* handle change */ })
.disabled(true)
.read_only(true)
.required(true)
.open_on_input_click(true)
.auto_highlight(/* auto_highlight: ComboboxAutoHighlight */)
.keep_highlight(true)
.highlight_item_on_hover(true)
.submit_on_item_click(true)
.loop_focus(true)
.limit(0)
.filter(|/* callback arguments */| { /* handle change */ })
.item_to_string_value(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AutocompleteRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<AutocompleteChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<AutocompleteChild<T>>>,) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.name | pub fn name(mut self, name: impl Into<SharedString>) -> Self
Sets the form field name used when serializing or submitting the value. |
.mode | pub fn mode(mut self, mode: AutocompleteMode) -> Self
Sets the mode configuration for this part. |
.default_value | pub fn default_value(mut self, default_value: impl Into<SharedString>) -> Self
The Autocomplete value axis is the input text (Base UI maps |
.value | pub fn value(mut self, value: impl Into<SharedString>) -> Self
Controlled input text (Base UI |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(&SharedString, &mut ComboboxChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value change occurs. |
.default_open | pub fn default_open(mut self, default_open: bool) -> Self
Sets the initial open state for an uncontrolled component. |
.open | pub fn open(mut self, open: bool) -> Self
Controls whether the component is open. |
.on_open_change | pub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut ComboboxChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change occurs. |
.on_item_highlighted | pub fn on_item_highlighted(mut self, on_item_highlighted: impl Fn(Option<&T>, &ComboboxItemHighlightDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when item highlighted occurs. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.read_only | pub fn read_only(mut self, read_only: bool) -> Self
When true, allows presentation and focus behavior without permitting value changes. |
.required | pub fn required(mut self, required: bool) -> Self
Marks the control as required for validation and accessibility state. |
.open_on_input_click | pub fn open_on_input_click(mut self, open_on_input_click: bool) -> Self
Controls whether open on input click behavior is enabled. |
.auto_highlight | pub fn auto_highlight(mut self, auto_highlight: ComboboxAutoHighlight) -> Self
Controls whether auto highlight behavior is enabled. |
.keep_highlight | pub fn keep_highlight(mut self, keep_highlight: bool) -> Self
Sets the keep highlight configuration for this part. |
.highlight_item_on_hover | pub fn highlight_item_on_hover(mut self, highlight_item_on_hover: bool) -> Self
Controls whether highlight item on hover behavior is enabled. |
.submit_on_item_click | pub fn submit_on_item_click(mut self, submit_on_item_click: bool) -> Self
Documented no-op hook until Form exposes programmatic submit. |
.loop_focus | pub fn loop_focus(mut self, loop_focus: bool) -> Self
Controls whether keyboard focus wraps from the last enabled item to the first and vice versa. |
.limit | pub fn limit(mut self, limit: usize) -> Self
Sets the limit configuration for this part. |
.filter | pub fn filter(mut self, filter: impl Fn(&T, Option<&SharedString>, &str) -> bool + 'static,) -> Self
Custom filter replacing the default case-insensitive contains match (only applies in |
.item_to_string_value | pub fn item_to_string_value(mut self, resolver: impl Fn(&T) -> SharedString + 'static) -> Self
Feeds display, filtering, fill-on-press, and Field serialization (Base UI |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ComboboxRootStyleState<T>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. AutocompleteRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#AutocompleteValue
Displays or edits the component's current value.
use base_gpui::autocomplete::AutocompleteValue;
AutocompleteValue::new()
.with_context(/* context: ComboboxContext<T> */)
.formatter(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AutocompleteValue with its default configuration. |
.with_context | pub fn with_context(mut self, context: ComboboxContext<T>) -> Self
Attaches the root context; called by |
.formatter | pub fn formatter(mut self, formatter: impl Fn(&str) -> SharedString + 'static) -> Self
Formatter closure over the current value; ignored when static children are present. |
.child | pub fn child(mut self, child: impl IntoElement) -> Self
Static children take precedence over the raw value (Base UI children fallback order). AutocompleteValue also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.