Autocomplete
Free text with suggestions: the person can pick one or write their own. Unlike Combobox, the value does not have to be in the list.
import { Autocomplete } from '@sypnia/ui/react'
On this page
A city
Start writing: Bo…
Code
import { useState } from 'react';
import { Autocomplete, Field } from '@sypnia/ui/react';
// Pick a suggestion or write your own: the value does not have to be in the list.
export default function City() {
const [city, setCity] = useState('');
return <Field label="City" hint={city ? `Saved as «${city}»` : 'Start writing: Bo…'}><Autocomplete suggestions={['Bogotá', 'Medellín', 'Cali', 'Barranquilla', 'Bucaramanga', 'Cartagena']} value={city} onChange={setCity} /></Field>;
} When to use it
Use it when
- Cities, tags, names people tend to repeat.
Do not use it when
- A value that must be one of the options: use Combobox.
For everyone
- It is a combobox: the arrows move through suggestions, Escape closes the list.
Props
| Autocomplete | Type | Default |
|---|---|---|
suggestionsrequired | string[] | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | string | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
name | string | |
onChange | ((v: string) => void) | |
placeholder | string | |
size | "sm" | "md" | "lg" | |
value | string |