DocsComponentsTemplatesThemesGitHub

Autocomplete

Combobox: type to filter suggestions (or fetch them with onSearch + loading), match highlighted, keyboard navigation, free text allowed.

Code

import * as React from 'react';
import { Autocomplete } from '@fruit-labs/design';

export default function Demo() {
  return (
    <div
      style={{
        maxWidth: 380,
        minHeight: 300,
      }}
    >
      <Autocomplete
        label="City"
        defaultValue="Ban"
        defaultOpen
        options={[
          {
            value: 'blr',
            label: 'Bangalore',
            description: 'Karnataka, India',
          },
          {
            value: 'bkk',
            label: 'Bangkok',
            description: 'Thailand',
          },
          {
            value: 'bcn',
            label: 'Barcelona',
            description: 'Spain',
          },
          {
            value: 'ban',
            label: 'Banff',
            description: 'Canada',
          },
        ]}
      />
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { Autocomplete } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/autocomplete.json

Guidelines

  • Static lists: pass options. Remote data: set filter={false}, fetch in onSearch, show loading.
  • onSelect(option) fires on pick; onSubmit(text) on Enter with free text.
  • Also exported as Combobox.

Props

PropTypeRequired
optionsArray<string | SelectOption>No
valuestringNo
defaultValuestringNo
onChange(text: string) => voidNo
onSelect(option: SelectOption) => voidNo
onSearch(q: string) => voidNo
onSubmit(text: string) => voidNo
loadingbooleanNo
filterbooleanNo
limitnumberNo
allowFreeTextbooleanNo
openOnFocusbooleanNo
clearablebooleanNo
labelstringNo
hintReact.ReactNodeNo
errorReact.ReactNodeNo
requiredbooleanNo
placeholderstringNo
iconstring | nullNo
prefixstring | React.ReactNode
inline text/icon name/node before the value, e.g. '$' or 'https://'
No
suffixstring | React.ReactNode
inline after the value, e.g. 'kg' or '.com'
No
size'sm' | 'md' | 'lg'No
pillbooleanNo
emptyTextstringNo
footerReact.ReactNodeNo
defaultOpenbooleanNo
disabledbooleanNo
classNamestringNo
styleReact.CSSPropertiesNo

Edit this example on GitHub