Skip to content

MultiSelect

Several choices from a list. Each chosen option becomes a chip inside the control, with a cross to take it out, and typing narrows the list.

import { MultiSelect } from '@sypnia/ui/react'

On this page
  1. Choose several
  2. States
  3. When to use it
  4. For everyone
  5. Props

Choose several

The columns that go into an export. Type to narrow the list; Backspace removes the last chip.

idemailcreated_at

3 of 7 columns go into the file, in this order.

Code
import { useState } from 'react';
import { Field, MultiSelect, type Option } from '@sypnia/ui/react';

const columns: Option[] = [
  { value: 'id', label: 'id', description: 'uuid' },
  { value: 'email', label: 'email', description: 'text' },
  { value: 'full_name', label: 'full_name', description: 'text' },
  { value: 'plan', label: 'plan', description: 'text' },
  { value: 'country', label: 'country', description: 'text' },
  { value: 'created_at', label: 'created_at', description: 'timestamp' },
  { value: 'last_seen_at', label: 'last_seen_at', description: 'timestamp' },
];

export default function Basic() {
  const [chosen, setChosen] = useState(['id', 'email', 'created_at']);
  return (
    <Field label="Columns to export" hint={`${chosen.length} of ${columns.length} columns go into the file, in this order.`}>
      <MultiSelect options={columns} value={chosen} onChange={setChosen} placeholder="Choose columns" />
    </Field>
  );
}

States

Empty with an error that says how to fix it, and disabled.

Choose at least one event, or the webhook will never fire.

row.createdrow.deleted

Only the owner can change a webhook.

Code
import { Field, FormGrid, MultiSelect, type Option } from '@sypnia/ui/react';

const events: Option[] = [
  { value: 'row.created', label: 'row.created' },
  { value: 'row.updated', label: 'row.updated' },
  { value: 'row.deleted', label: 'row.deleted' },
  { value: 'backup.finished', label: 'backup.finished' },
];

export default function States() {
  return (
    <FormGrid>
      <Field label="Events to send" error="Choose at least one event, or the webhook will never fire.">
        <MultiSelect options={events} placeholder="Choose events" />
      </Field>
      <Field label="Events to send" hint="Only the owner can change a webhook.">
        <MultiSelect disabled options={events} defaultValue={['row.created', 'row.deleted']} />
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • Several options out of many: the columns of an export, the members of a group, the events of a webhook.
  • What was chosen must stay in sight while the person keeps choosing.

Do not use it when

  • There are six options or fewer: a CheckboxGroup shows them all without opening anything.
  • The person writes their own words instead of choosing from a list: TagInput.
  • Only one can be chosen: Select or Combobox.

For everyone

  • Typing filters; arrows move through the list; Enter adds or takes out the focused option and the list stays open; Escape closes it.
  • Backspace in an empty box takes out the last chip. Each chip has its own button, named «Remove» plus the option.
  • Chosen options are marked as selected in the list, so the list alone tells the whole state.
  • Inside a Field it takes the label, the hint and the error by itself; alone, give it an aria-label.

Props

MultiSelectTypeDefault
optionsrequired Option[]
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
emptyText ReactNode
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 ((values: string[]) => void)
placeholder string
value string[]
  1. Choose several
  2. States
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms