Autocomplete

Show suggestions as users type and let them quickly select a match.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-autocomplete
  placeholder="Enter a fruit name"
  size="medium"
  trigger="focus"
  min="0"
  highlight-matches
  id="sample"
  aria-label="Search fruit"
></sy-autocomplete>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "source": [
      "Apple",
      "Apricot",
      "Banana",
      "Cherry",
      "Grape",
      "Orange",
      "Peach"
    ]
  });
</script>

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.

  1. 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.

  2. 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.

  3. 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.

  1. Prepare suggestions

    Pass a string array to source.

  2. Control search timing

    Set the minimum character count with min and the delay after typing in milliseconds with debounceTime.

  3. Distinguish input from selection

    changed reports input changes; selected reports candidate selection. Connect app logic to the appropriate event.

Feature examples

#

Choose a feature from 20 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Case Sensitive

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Debounce Time

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Disabled

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Highlight Matches

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Loading

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Min

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Placeholder

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Readonly

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Required

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Size

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Source

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Status

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Trigger

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Value

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · checkValidity

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · setCustomError

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · Set Focus & Blur

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · Changed

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Selected

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

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 / PropertyTypeDefaultDescription
booleanfalseMatch suggestions case-sensitively.
number0Input debounce delay in milliseconds.
booleanfalseBlock user interaction and keyboard focus.
booleanfalseHighlight matching text in suggestions.
booleanfalseIndicate that processing is in progress.
number0Minimum character count before suggestions appear.
string''Field name used in FormData.
string''Placeholder shown when the value is empty.
booleanfalseDisplay the current value while preventing edits.
booleanfalseFail 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.
booleanfalseUse the app's error UI instead of the browser's built-in error display. checkValidity still performs validation.

Events

EventDetailDescription
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

MethodReturnsDescription
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

SlotDescription
Validation error message.

<sy-autocomplete-option>

Properties

Attribute / PropertyTypeDefaultDescription
string[][]Array of suggestion strings, passed as a JavaScript property.

Pass objects and arrays as JavaScript properties.

booleanfalseIndicate that processing is in progress.
number-1Index of the candidate being navigated with the keyboard, managed by Autocomplete.
string''Search query used to filter and highlight candidates.
booleanfalseMatch suggestions case-sensitively.
booleanfalseHighlight matching text in suggestions.

Events

EventDetailDescription
CustomEvent<number>Read the result from the event's detail.
CustomEvent<string>Emitted when the user selects an item.

Methods

MethodReturnsDescription
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.