Components Forms

Combobox and MultiSelect

One choice from a long list, searched as the person types or on the server with onSearch, and several choices toggled in a list.

import { Combobox, MultiSelect } from '@kition/tessera-ui'

When to use

  • Picking a user, a record, a country: more choices than a Select shows well.

When not to

  • A handful of fixed choices: use Select.

Examples

Search and pick
combobox.tsx
import { useState } from 'react'
import { Combobox } from '@kition/tessera-ui'

const PEOPLE = ['Ada Lovelace', 'Grace Hopper', 'Alan Turing', 'Katherine Johnson', 'Margaret Hamilton', 'Edsger Dijkstra', 'Barbara Liskov', 'Donald Knuth']

export default function Demo() {
  const [person, setPerson] = useState<number | undefined>(2)
  return (
    <div style={{ maxWidth: 320 }}>
      <Combobox
        label="Person"
        size="md"
        placeholder="Search people"
        value={person}
        onChange={setPerson}
        options={PEOPLE.map((name, index) => ({ value: index + 1, label: index === 5 ? `${name} (no GitHub)` : name, disabled: index === 5 }))}
      />
    </div>
  )
}
Several choices
multi-select.tsx
import { useState } from 'react'
import { MultiSelect } from '@kition/tessera-ui'

const MODES = ['free', 'reward', 'paid', 'hosted'].map((value) => ({ value, label: value }))

export default function Demo() {
  const [modes, setModes] = useState(['paid', 'hosted'])
  return (
    <div style={{ maxWidth: 280 }}>
      <MultiSelect label="Mode" placeholder="Any mode" size="md" values={modes} onChange={setModes} options={MODES} />
    </div>
  )
}

Props

Combobox

One choice from a long list, searched as the person types; the choice can be cleared.

PropTypeDefaultDescription
valuerequiredV | undefined—
onChangerequired(value: V | undefined) => void—
optionsrequiredreadonly ComboboxOption<V>[]—
onSearch(query: string) => void—Search on the server: called with each query, and the options shown are the caller's. Without it, the options are filtered here.
loadingboolean—
placeholderstring—
emptyTextReactNode—Shown when nothing matches.
labelrequiredstring—The control's accessible name.
sizeControlSize'sm'
disabledboolean—
classNamestring—
testIdstring—

MultiSelect

Several choices from a list: the chosen ones in the field, toggled in a list (searchable once it is long).

PropTypeDefaultDescription
valuesrequiredreadonly V[]—
onChangerequired(values: V[]) => void—
optionsrequiredreadonly ComboboxOption<V>[]—
placeholderstring—Shown when nothing is chosen.
labelrequiredstring—The control's accessible name.
sizeControlSize'sm'
disabledboolean—
classNamestring—
testIdstring—