Autocomplete
Show suggestions as users type and let them quickly select a match.
Usage guide
#Use for search or input with many candidates when users know the name. Select is simpler for a small fixed set of values.
Write the error message in the error slot.
Inside the component, add <span slot="error">Error message</span>. You can include links and other guidance as well as text. For inputs supporting noNativeValidity, enable it to show this guidance instead of a browser popup. Switch always displays errors below the component.
Report business rule failures with setCustomError().
For example, if the server rejects a duplicate value, update the error slot and call setCustomError(). This method does not take a message argument. A custom error also blocks form submission.
Clear the error after resolving it and check whether submission is allowed.
Use clearCustomError() to clear a business rule error. Required-field and format validation remain active. await checkValidity() returns true or false; reportValidity() validates and displays errors. Read valid named values through FormData on submission.
Prepare suggestions
Pass a string array to
source.Control search timing
Set the minimum character count with
minand the delay after typing in milliseconds withdebounceTime.Distinguish input from selection
changedreports input changes;selectedreports candidate selection. Connect app logic to the appropriate event.
Examples
#Feature examples
#Choose a feature from 20 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.
No matching features.
API reference
#Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.
<sy-autocomplete>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
boolean | false | Match suggestions case-sensitively. | |
number | 0 | Input debounce delay in milliseconds. | |
boolean | false | Block user interaction and keyboard focus. | |
boolean | false | Highlight matching text in suggestions. | |
boolean | false | Indicate that processing is in progress. | |
number | 0 | Minimum character count before suggestions appear. | |
string | '' | Field name used in FormData. | |
string | '' | Placeholder shown when the value is empty. | |
boolean | false | Display the current value while preventing edits. | |
boolean | false | Fail form validation when no value is provided. | |
'small' | 'medium' | 'large' | 'medium' | Component size. | |
'default' | 'warning' | 'error' | 'success' | 'default' | Visually represent default, success, warning, or error states. | |
string | '' | Current value or item identifier. | |
string[] | [] | Array of suggestion strings, passed as a JavaScript property. Pass objects and arrays as JavaScript properties. | |
'focus' | 'input' | 'focus' | User action that opens the list or popup. | |
boolean | false | Use the app's error UI instead of the browser's built-in error display. checkValidity still performs validation. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ value: string; isValid: boolean; status: string }> | Emitted when the value or selection state changes. | |
CustomEvent<{ value: string; isValid: boolean; status: string }> | Emitted when the user selects an item. |
Methods
| Method | Returns | Description |
|---|---|---|
Promise<void> | Move keyboard focus to the input or action element. | |
Promise<void> | Remove focus from the input element. | |
Promise<boolean> | Return true if the current constraints are satisfied, otherwise false. | |
Promise<boolean> | Validate the current value and display errors to the user. | |
Promise<string> | Return the current validation state. | |
Promise<void> | Set a custom error state. | |
Promise<void> | Clear the custom error state. |
Slots
| Slot | Description |
|---|---|
| Validation error message. |
<sy-autocomplete-option>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
string[] | [] | Array of suggestion strings, passed as a JavaScript property. Pass objects and arrays as JavaScript properties. | |
boolean | false | Indicate that processing is in progress. | |
number | -1 | Index of the candidate being navigated with the keyboard, managed by Autocomplete. | |
string | '' | Search query used to filter and highlight candidates. | |
boolean | false | Match suggestions case-sensitively. | |
boolean | false | Highlight matching text in suggestions. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<number> | Read the result from the event's detail. | |
CustomEvent<string> | Emitted when the user selects an item. |
Methods
| Method | Returns | Description |
|---|---|---|
Promise<void> | Initialize event bindings for suggestion options. Normally managed by Autocomplete. | |
Promise<void> | Render the component again using its current properties. Normally, property changes or the parent component manage updates. |