@k8ordo/ui

Autocomplete

A field for picking several options from a fixed list. The choices show as tags that can be removed one by one.

Import

ts
import { Autocomplete } from '@k8ordo/ui';

Usage

tsx
const [value, setValue] = useState<string[]>([]);

const options = [
  { label: 'Apple', value: 'apple' },
  { label: 'Banana', value: 'banana' },
  { label: 'Cherry', value: 'cherry' },
  { label: 'Grape', value: 'grape' },
  { label: 'Orange', value: 'orange' },
];

<Autocomplete
  id="autocomplete-basic"
  aria-describedby={undefined}
  disabled={false}
  invalid={false}
  required={false}
  onChange={setValue}
  options={options}
  value={value}
/>

Required

tsx
<Autocomplete
  id="autocomplete-required"
  aria-describedby={undefined}
  disabled={false}
  invalid={false}
  required
  onChange={setValue}
  options={options}
  value={value}
/>

Multiple selection

Apple
Cherry
tsx
const [value, setValue] = useState<string[]>(['apple', 'cherry']);

<Autocomplete
  id="autocomplete-multiple"
  aria-describedby={undefined}
  disabled={false}
  invalid={false}
  required={false}
  onChange={setValue}
  options={options}
  value={value}
/>

Disabled

Apple
tsx
<Autocomplete
  id="autocomplete-disabled"
  aria-describedby={undefined}
  disabled
  invalid={false}
  required={false}
  onChange={setValue}
  options={options}
  value={['apple']}
/>

Invalid

tsx
<Autocomplete
  id="autocomplete-invalid"
  aria-describedby={undefined}
  disabled={false}
  invalid
  required={false}
  onChange={setValue}
  options={options}
  value={value}
/>

Props

id
Type: string
Default: -
options
Type: readonly Option[]
Default: -
defaultValue?
Type: string[]
Default: -
invalid?
Type: boolean
Default: false
onChange?
Type: (value: string[]) => void
Default: -
ref?
Type: Ref<HTMLInputElement>
Default: -
value?
Type: string[]
Default: -
PropTypeDefault
idstring-
optionsreadonly Option[]-
defaultValue?string[]-
invalid?booleanfalse
onChange?(value: string[]) => void-
ref?Ref<HTMLInputElement>-
value?string[]-

Inherited attributes (except the ones set internally): InputHTMLAttributes<HTMLInputElement>

The wording this component draws (labels, placeholders, and so on) comes from the message dictionary unless a prop sets it. To replace it, see: i18n

k8ordo

React libraries that use Baseline features without holding back.