Hero Ui

HeroUI Autocomplete

Forms 8

About

HeroUI v3 Autocomplete is a searchable select that filters a ListBox of options as you type, supporting single and multiple selection with removable tags, grouped sections, disabled options, descriptions, form validation, controlled state, custom trigger values with avatars, and full-width layouts inside a Surface. Built on the real @heroui/react package with @heroui/styles, it composes with SearchField, ListBox, TagGroup, Label, Description, FieldError and useFilter. A thin re-export of the upstream component so consumers install and render the genuine HeroUI primitive.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds HeroUI Autocomplete to your project and fits it to your theme.

Code

How HeroUI Autocomplete is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client"

import type { Key } from "@heroui/react"

import {
  EmptyState,
  Label,
  ListBox,
  SearchField,
  Surface,
  useFilter,
} from "@heroui/react"
import { useState } from "react"
import { Autocomplete } from "@/components/ui/heroui-autocomplete"

export function FullWidth() {
  const [selectedKey, setSelectedKey] = useState<Key | null>(null)
  const { contains } = useFilter({ sensitivity: "base" })

  const items = [
    { id: "florida", name: "Florida" },
    { id: "delaware", name: "Delaware" },
    { id: "california", name: "California" },
    { id: "texas", name: "Texas" },
    { id: "new-york", name: "New York" },
    { id: "washington", name: "Washington" },
  ]

  return (
    <Surface className="w-[380px] space-y-4 rounded-3xl p-6">
      <Autocomplete
        fullWidth
        placeholder="Select one"
        selectionMode="single"
        value={selectedKey}
        variant="secondary"
        onChange={setSelectedKey}
      >
        <Label>State</Label>
        <Autocomplete.Trigger>
          <Autocomplete.Value />
          <Autocomplete.ClearButton />
          <Autocomplete.Indicator />
        </Autocomplete.Trigger>
        <Autocomplete.Popover>
          <Autocomplete.Filter filter={contains}>
            <SearchField autoFocus name="search" variant="secondary">
              <SearchField.Group>
                <SearchField.SearchIcon />
                <SearchField.Input placeholder="Search states..." />
                <SearchField.ClearButton />
              </SearchField.Group>
            </SearchField>
            <ListBox renderEmptyState={() => <EmptyState>No results found</EmptyState>}>
              {items.map((item) => (
                <ListBox.Item key={item.id} id={item.id} textValue={item.name}>
                  {item.name}
                  <ListBox.ItemIndicator />
                </ListBox.Item>
              ))}
            </ListBox>
          </Autocomplete.Filter>
        </Autocomplete.Popover>
      </Autocomplete>
    </Surface>
  )
}

export default FullWidth

Dependencies

More by Hero Ui

View all
  • DatePicker

    DatePicker

    473
  • Chip

    Chip

    449
  •  The Pagination

    The Pagination

    368
  • HeroUI Table

    HeroUI Table

    123
  • HeroUI Color Picker

    HeroUI Color Picker

    115
  • Skeleton

    Skeleton

    107
  • HeroUI Disclosure Group

    HeroUI Disclosure Group

    98
  • HeroUI AlertDialog

    HeroUI AlertDialog

    85

More in Forms

View all
  • Premium Auth

    Premium Auth

    577
  • Login 1

    Login 1

    68
  • Contact Card

    Contact Card

    1.1K
  • Form

    Form

    18
  • Login Card

    Login Card

    36
  • Login 2

    Login 2

    15
  • Change Password Form

    Change Password Form

    11
  • Form

    Form

    3