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.jsonGuidelines
- Static lists: pass
options. Remote data: setfilter={false}, fetch inonSearch, showloading. onSelect(option)fires on pick;onSubmit(text)on Enter with free text.- Also exported as
Combobox.
Props
| Prop | Type | Required |
|---|---|---|
options | Array<string | SelectOption> | No |
value | string | No |
defaultValue | string | No |
onChange | (text: string) => void | No |
onSelect | (option: SelectOption) => void | No |
onSearch | (q: string) => void | No |
onSubmit | (text: string) => void | No |
loading | boolean | No |
filter | boolean | No |
limit | number | No |
allowFreeText | boolean | No |
openOnFocus | boolean | No |
clearable | boolean | No |
label | string | No |
hint | React.ReactNode | No |
error | React.ReactNode | No |
required | boolean | No |
placeholder | string | No |
icon | string | null | No |
prefix | string | React.ReactNodeinline text/icon name/node before the value, e.g. '$' or 'https://' | No |
suffix | string | React.ReactNodeinline after the value, e.g. 'kg' or '.com' | No |
size | 'sm' | 'md' | 'lg' | No |
pill | boolean | No |
emptyText | string | No |
footer | React.ReactNode | No |
defaultOpen | boolean | No |
disabled | boolean | No |
className | string | No |
style | React.CSSProperties | No |