Skip to main content
Tw Twintrinsic
  • Getting Started
  • Components
  • Theming
  • Completion
Examples
Data Dashboard Game Map
Core
App
Layout
Accordion AccordionItem Card Container Panel Separator Sidebar Splitter
Navigation
AppHeader BottomBar Breadcrumb BreadcrumbItem Menu MenuItem Tabs Tab TabList TabPanel TreeMenu
Data Display
Avatar AvatarGroup Badge Carousel CarouselItem Chip ChipGroup CodeBlock CodeBlockSpeed CodeEditor DataTable Map Progress Skeleton Table TableBody TableCell TableHead TableHeader TableRow Tag TagGroup Timeline TimelineItem Tooltip Tree TreeNode
Metrics
DonutChart PieChart LineChart BarChart HorizontalBarChart AreaChart StatsCard MetricGrid KPICard GaugeChart ProgressMetric MetricTrend
Form
AutoComplete Button ButtonGroup Calendar Checkbox ColorPicker Combobox Dropdown FileUpload FloatLabel Form FormField Input InputSwitch InvalidState Knob ListInput Listbox NumberInput Radio RadioGroup Rating Select SelectGroup Slider Switch TextInput Textarea
Feedback
Modal Stepper StepperStep Toast
Utility
Icon Lazy LazyPanel Masonry ThemeToggle

AutoComplete

The AutoComplete component provides suggestions as you type, supporting both single and multiple selections. It's built on top of the base Input component and includes features like custom templates, keyboard navigation, and input masking.

Examples

Basic Usage

<AutoComplete
  label="Country"
  items={countries}
  placeholder="Select a country"
/>

Multiple Selection

<AutoComplete
  label="Countries"
  items={countries}
  multiple={true}
  placeholder="Select countries"
/>

Custom Template

<AutoComplete
  label="User"
  items={users}
  itemTemplate={{
    render: ({ item }) => `
      <div class="flex items-center gap-2">
        <img src="${item.avatar}" alt="" class="w-8 h-8 rounded-full" />
        <span>${item.label}</span>
      </div>
    `
  }}
  placeholder="Select a user"
/>

Props

PropTypeDefaultDescription
labelstringRequiredInput label
itemsArray<any>[]Array of items to search through
labelFieldstringlabelField to use for item labels
valueFieldstringvalueField to use for item values
valuestring | Array<string>RequiredSelected value(s)
minLengthnumber1Minimum characters before showing suggestions
delaynumber150Delay in ms before searching
multiplebooleanfalseWhether to allow multiple selections
highlightbooleantrueWhether to highlight matching text
forceSelectionbooleanfalseWhether to force selection from suggestions
maxItemsnumber10Maximum number of suggestions to show
filterfunctionRequiredCustom filter function (items, query) => filteredItems
itemTemplateComponentRequiredCustom item template component
emptyMessagestringNo results foundMessage to show when no results are found
loadingMessagestringLoading...Message to show when loading
loadingbooleanfalseWhether suggestions are loading
disabledbooleanfalseWhether the input is disabled

Events

EventDetail TypeDescription
onselect{ item: any } | { items: Array<any> }Fired when an item is selected
onremove{ item: any }Fired when an item is removed (multiple mode)
oninput{ value: string }Fired when input value changes
onfocusvoidFired when input gains focus
onblurvoidFired when input loses focus

Keyboard Navigation

The AutoComplete component supports keyboard navigation:

  • ArrowDown - Highlight next suggestion
  • ArrowUp - Highlight previous suggestion
  • Enter - Select highlighted suggestion
  • Escape - Close suggestions

Accessibility

The component follows WAI-ARIA guidelines for combobox and listbox patterns:

  • Proper ARIA roles and attributes for the input and suggestions list
  • Keyboard navigation support
  • Screen reader announcements for loading and empty states
  • Proper focus management