AutoComplete

AutoComplete is a searchable dropdown input that allows users to type and filter through options, with support for single or multiple selections. Unlike a basic Select, it provides type-ahead functionality and can allow users to create new options.

Key features:

  • Type-ahead filtering: Users can type to narrow down options in real-time
  • Multi-select support: Set multi="true" to allow selecting multiple items
  • Custom option creation: Enable creatable="true" to let users add new options
  • Rich customization: Use optionTemplate to create complex option layouts

Using AutoComplete

<App>
  <AutoComplete>
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" enabled="false" />
    <Option value="3" label="Diana Prince" />
  </AutoComplete>
</App>
Example: Using AutoComplete
<App>
  <AutoComplete>
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" enabled="false" />
    <Option value="3" label="Diana Prince" />
  </AutoComplete>
</App>

Context variables available during execution:

  • $item: This context value represents an item when you define an option item template. Use $item.value and $item.label to refer to the value and label of the particular option.

Behaviors

This component supports the following behaviors:

BehaviorProperties
Animationanimation, animationOptions
Bookmarkbookmark, bookmarkLevel, bookmarkTitle, bookmarkOmitFromToc
Form BindingbindTo, initialValue, noSubmit
Component Labellabel, labelPosition, labelWidth, labelBreak, required, enabled, shrinkToLabel, style, readOnly
Publish/SubscribesubscribeToTopic
Tooltiptooltip, tooltipMarkdown, tooltipOptions
ValidationbindTo, required, minLength, maxLength, lengthInvalidMessage, lengthInvalidSeverity, minValue, maxValue, rangeInvalidMessage, rangeInvalidSeverity, pattern, patternInvalidMessage, patternInvalidSeverity, regex, regexInvalidMessage, regexInvalidSeverity, validationMode, verboseValidationFeedback
Styling Variantvariant

Properties

autoFocus

default: false

If this property is set to true, the component gets the focus automatically when displayed.

creatable

default: false

This property allows the user to create new items that are not present in the list of options.

This property sets the height of the dropdown list.

emptyListTemplate

This property defines the template to display when the list of options is empty.

<App>
  <AutoComplete>
    <property name="emptyListTemplate">
      <Text>No options found</Text>
    </property>
  </AutoComplete>
</App>
Example: emptyListTemplate
<App>
  <AutoComplete>
    <property name="emptyListTemplate">
      <Text>No options found</Text>
    </property>
  </AutoComplete>
</App>

enabled

default: true

This boolean property value indicates whether the component responds to user events (true) or not (false).

initiallyOpen

default: false

This property determines whether the dropdown list is open when the component is first rendered.

initialValue

This property sets the component's initial value.

maxLength

This property sets the maximum length of the input it accepts.

multi

default: false

The true value of the property indicates if the user can select multiple items.

    <App>
      <AutoComplete multi="true">
        <Option value="1" label="Bruce Wayne" />
        <Option value="2" label="Clark Kent" />
        <Option value="3" label="Diana Prince" />
        <Option value="4" label="Barry Allen" />
        <Option value="5" label="Hal Jordan" />
      </AutoComplete>
    </App>
Example: multi
    <App>
      <AutoComplete multi="true">
        <Option value="1" label="Bruce Wayne" />
        <Option value="2" label="Clark Kent" />
        <Option value="3" label="Diana Prince" />
        <Option value="4" label="Barry Allen" />
        <Option value="5" label="Hal Jordan" />
      </AutoComplete>
    </App>

optionTemplate

This property enables the customization of list items. To access the attributes of a list item use the $item context variable.

<App>
  <AutoComplete multi="true">
    <property name="optionTemplate">
      <Text textAlign="center" color="red">{$item.label}</Text>
    </property>
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" />
    <Option value="3" label="Diana Prince" />
  </AutoComplete>
</App>
Example: optionTemplate
<App>
  <AutoComplete multi="true">
    <property name="optionTemplate">
      <Text textAlign="center" color="red">{$item.label}</Text>
    </property>
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" />
    <Option value="3" label="Diana Prince" />
  </AutoComplete>
</App>

placeholder

An optional placeholder text that is visible in the input field when its empty.

readOnly

default: false

Set this property to true to disallow changing the component value.

required

default: false

Set this property to true to indicate it must have a value before submitting the containing form.

validationStatus

default: "none"

This property allows you to set the validation status of the input component.

Available values:

ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error

Events

didChange

This event is triggered when value of AutoComplete has changed.

Signature: didChange(newValue: any): void

  • newValue: The new value of the component.

gotFocus

This event is triggered when the AutoComplete has received the focus.

Signature: gotFocus(): void

itemCreated

This event is triggered when a new item is created by the user (if creatable is enabled).

Signature: (item: string) => void

  • item: The newly created item value.

Add a few new items not in the options list. The following markup will display them:

<App var.newItems="{[]}">
  <AutoComplete
    id="autoComplete"
    creatable="true"
    onItemCreated="item => newItems.push(item)">
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" />
  </AutoComplete>
  <Text testId="text">
    New items: {newItems.join(", ")}
  </Text>
</App>
Example: itemCreated
<App var.newItems="{[]}">
  <AutoComplete
    id="autoComplete"
    creatable="true"
    onItemCreated="item => newItems.push(item)">
    <Option value="1" label="Bruce Wayne" />
    <Option value="2" label="Clark Kent" />
  </AutoComplete>
  <Text testId="text">
    New items: {newItems.join(", ")}
  </Text>
</App>

lostFocus

This event is triggered when the AutoComplete has lost the focus.

Signature: lostFocus(): void

validationIconError

Icon to display for error state when concise validation summary is enabled.

validationIconSuccess

Icon to display for valid state when concise validation summary is enabled.

verboseValidationFeedback

Enables a concise validation summary (icon) in input components.

Exposed Methods

focus

This method focuses the AutoComplete component.

Signature: focus()

setValue

This API allows you to set the value of the component. If the value is not valid, the component will not update its internal state.

Signature: setValue(value: any)

  • value: The value to set.

value

This API allows you to get or set the value of the component. If no value is set, it will retrieve undefined.

Signature: get value(): any

Styling

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-AutoCompletetransparenttransparent
backgroundColor-AutoComplete--defaultnonenone
backgroundColor-AutoComplete--default--hovernonenone
backgroundColor-AutoComplete--disablednonenone
backgroundColor-AutoComplete--errornonenone
backgroundColor-AutoComplete--error--hovernonenone
backgroundColor-AutoComplete--successnonenone
backgroundColor-AutoComplete--success--hovernonenone
backgroundColor-AutoComplete--warningnonenone
backgroundColor-AutoComplete--warning--hovernonenone
backgroundColor-AutoComplete-badge$color-primary-500$color-primary-500
backgroundColor-AutoComplete-badge$color-primary-500$color-primary-500
backgroundColor-AutoComplete-badge--active$color-primary-500$color-primary-500
backgroundColor-AutoComplete-badge--active$color-primary-500$color-primary-500
backgroundColor-AutoComplete-badge--hover$color-primary-400$color-primary-400
backgroundColor-AutoComplete-badge--hover$color-primary-400$color-primary-400
backgroundColor-item-AutoComplete$backgroundColor-dropdown-item$backgroundColor-dropdown-item
backgroundColor-item-AutoComplete--active$backgroundColor-dropdown-item--active$backgroundColor-dropdown-item--active
backgroundColor-item-AutoComplete--hover$backgroundColor-dropdown-item--hover$backgroundColor-dropdown-item--hover
backgroundColor-menu-AutoComplete$color-surface-raised$color-surface-raised
backgroundColor-menu-AutoComplete$color-surface-raised$color-surface-raised
border-AutoCompletenonenone
borderBottom-AutoCompletenonenone
borderBottomColor-AutoCompletenonenone
borderBottomStyle-AutoCompletenonenone
borderBottomWidth-AutoCompletenonenone
borderColor-AutoCompletenonenone
borderColor-AutoComplete--defaultnonenone
borderColor-AutoComplete--default--hovernonenone
borderColor-AutoComplete--disabled$borderColor--disabled$borderColor--disabled
borderColor-AutoComplete--disabled$borderColor--disabled$borderColor--disabled
borderColor-AutoComplete--errornonenone
borderColor-AutoComplete--error--hovernonenone
borderColor-AutoComplete--successnonenone
borderColor-AutoComplete--success--hovernonenone
borderColor-AutoComplete--warningnonenone
borderColor-AutoComplete--warning--hovernonenone
borderColor-menu-AutoComplete$borderColor$borderColor
borderColor-menu-AutoComplete$borderColor$borderColor
borderEndEndRadius-AutoCompletenonenone
borderEndStartRadius-AutoCompletenonenone
borderHorizontal-AutoCompletenonenone
borderHorizontalColor-AutoCompletenonenone
borderHorizontalStyle-AutoCompletenonenone
borderHorizontalWidth-AutoCompletenonenone
borderLeft-AutoCompletenonenone
borderLeftColor-AutoCompletenonenone
borderLeftStyle-AutoCompletenonenone
borderLeftWidth-AutoCompletenonenone
borderRadius-AutoComplete--defaultnonenone
borderRadius-AutoComplete--errornonenone
borderRadius-AutoComplete--successnonenone
borderRadius-AutoComplete--warningnonenone
borderRadius-AutoComplete-badge$borderRadius$borderRadius
borderRadius-menu-AutoComplete$borderRadius$borderRadius
borderRadius-menu-AutoComplete$borderRadius$borderRadius
borderRight-AutoCompletenonenone
borderRightColor-AutoCompletenonenone
borderRightStyle-AutoCompletenonenone
borderRightWidth-AutoCompletenonenone
borderStartEndRadius-AutoCompletenonenone
borderStartStartRadius-AutoCompletenonenone
borderStyle-AutoCompletenonenone
borderStyle-AutoComplete--defaultnonenone
borderStyle-AutoComplete--errornonenone
borderStyle-AutoComplete--successnonenone
borderStyle-AutoComplete--warningnonenone
borderTop-AutoCompletenonenone
borderTopColor-AutoCompletenonenone
borderTopStyle-AutoCompletenonenone
borderTopWidth-AutoCompletenonenone
borderVertical-AutoCompletenonenone
borderVerticalColor-AutoCompletenonenone
borderVerticalStyle-AutoCompletenonenone
borderVerticalWidth-AutoCompletenonenone
borderWidth-AutoCompletenonenone
borderWidth-AutoComplete--defaultnonenone
borderWidth-AutoComplete--errornonenone
borderWidth-AutoComplete--successnonenone
borderWidth-AutoComplete--warningnonenone
borderWidth-menu-AutoComplete1px1px
borderWidth-menu-AutoComplete1px1px
boxShadow-AutoComplete--defaultnonenone
boxShadow-AutoComplete--default--hovernonenone
boxShadow-AutoComplete--errornonenone
boxShadow-AutoComplete--error--hovernonenone
boxShadow-AutoComplete--successnonenone
boxShadow-AutoComplete--success--hovernonenone
boxShadow-AutoComplete--warningnonenone
boxShadow-AutoComplete--warning--hovernonenone
boxShadow-menu-AutoComplete$boxShadow-md$boxShadow-md
boxShadow-menu-AutoComplete$boxShadow-md$boxShadow-md
fontSize-AutoComplete--defaultnonenone
fontSize-AutoComplete--errornonenone
fontSize-AutoComplete--successnonenone
fontSize-AutoComplete--warningnonenone
fontSize-AutoComplete-badge$fontSize-sm$fontSize-sm
fontSize-AutoComplete-badge$fontSize-sm$fontSize-sm
fontSize-placeholder-AutoComplete--defaultnonenone
fontSize-placeholder-AutoComplete--errornonenone
fontSize-placeholder-AutoComplete--successnonenone
fontSize-placeholder-AutoComplete--warningnonenone
gap-adornment-AutoCompletenonenone
outlineColor-AutoComplete--focusnonenone
outlineOffset-AutoComplete--focusnonenone
outlineStyle-AutoComplete--focusnonenone
outlineWidth-AutoComplete--focusnonenone
padding-AutoCompletenonenone
padding-item-AutoCompletenonenone
paddingBottom-AutoCompletenonenone
paddingBottom-item-AutoCompletenonenone
paddingHorizontal-AutoComplete$space-2$space-2
paddingHorizontal-AutoComplete-badge$space-2_5$space-2_5
paddingHorizontal-item-AutoComplete$space-2$space-2
paddingLeft-AutoCompletenonenone
paddingLeft-item-AutoCompletenonenone
paddingRight-AutoCompletenonenone
paddingRight-item-AutoCompletenonenone
paddingTop-AutoCompletenonenone
paddingTop-item-AutoCompletenonenone
paddingVertical-AutoComplete$space-2$space-2
paddingVertical-AutoComplete-badge$space-0_5$space-0_5
paddingVertical-item-AutoComplete$space-2$space-2
textColor-AutoComplete--defaultnonenone
textColor-AutoComplete--default--hovernonenone
textColor-AutoComplete--disabled$textColor--disabled$textColor--disabled
textColor-AutoComplete--disabled$textColor--disabled$textColor--disabled
textColor-AutoComplete--errornonenone
textColor-AutoComplete--error--hovernonenone
textColor-AutoComplete--successnonenone
textColor-AutoComplete--success--hovernonenone
textColor-AutoComplete--warningnonenone
textColor-AutoComplete--warning--hovernonenone
textColor-AutoComplete-badge$const-color-surface-50$const-color-surface-50
textColor-AutoComplete-badge$const-color-surface-50$const-color-surface-50
textColor-AutoComplete-badge--activenonenone
textColor-AutoComplete-badge--hovernonenone
textColor-item-AutoComplete--disabled$color-surface-300$color-surface-300
textColor-placeholder-AutoCompletenonenone
textColor-placeholder-AutoComplete--defaultnonenone
textColor-placeholder-AutoComplete--errornonenone
textColor-placeholder-AutoComplete--successnonenone
textColor-placeholder-AutoComplete--warningnonenone