Skip to content

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
  1. A city
  2. When to use it
  3. For everyone
  4. Props

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

AutocompleteTypeDefault
suggestionsrequired string[]
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
defaultValue string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks 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
  1. A city
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms