本文へ移動
日本語

仕組み

The field is filled like the text input and select, in three heights, and turns white with an accent halo while open. Selected values are round pills: white on the grey fill, grey once the field turns white. By default it is one row: hidden copies of the pills are measured to see how many fit, and the rest collapse into “+N”, so the height never changes. The panel has no portal: it hangs under the relative root at the field's width and flips above when there is not enough room below. Checking keeps it open. With a limit, unchecked options are dimmed once it is reached. A hidden input per value supports native form submission.

向いている場面

  • Choosing several from a fixed list in a form: assignees on a task, tags on a file, regions for a deployment.
  • Multi-value filters on a list page, such as several statuses at once.
  • Long or remote option lists: turn on searchable with onSearch and loading.
  • Choices with a cap (at most 3 people): use maxCount so the field explains why nothing more can be picked.

向かない場面

  • Only one value: use a single select.
  • Actions that run when picked: use a dropdown menu, which has menu semantics rather than a form value.
  • Only 3-5 options: show a row of checkboxes so everything is visible.
  • Free-form values that are not in the list: this component only picks from options.
  • An ancestor with overflow: hidden and no room above or below: the panel has no portal and would be clipped.

使い方

import { useState } from 'react'
import { MultiSelect } from './MultiSelect.jsx'

const people = [
  { value: 'emma', label: 'Emma Clark', group: 'Design' },
  { value: 'liam', label: 'Liam Chen', group: 'Design' },
  { value: 'noah', label: 'Noah Evans (on leave)', group: 'Design', disabled: true },
  { value: 'mia', label: 'Mia Torres', group: 'Engineering' },
  { value: 'ethan', label: 'Ethan Brooks', group: 'Engineering' },
]

export function AssigneeField() {
  const [value, setValue] = useState(['emma'])
  return (
    <div>
      <label htmlFor="assignees">Assignees</label>
      <MultiSelect
        id="assignees"
        options={people}
        value={value}
        onChange={setValue}
        searchable
        clearable
        showSelectAll
        maxCount={3}
        placeholder="Type a name to search"
      />
    </div>
  )
}

プロパティ

プロパティ型既定値説明
options{ value, label, description?, disabled?, group? }[]—Options. value is a string or number and must be unique; neighboring options with the same group form a group.
value(string | number)[]—Controlled selected values; their order is the tag order.
defaultValue(string | number)[][]Initial selected values when uncontrolled.
onChange(value, options) => void—Called on any change: checking, unchecking, removing a tag, Backspace, select all, clear.
openboolean—Controlled panel state; use with onOpenChange.
defaultOpenbooleanfalseInitial panel state when uncontrolled; does not steal focus.
onOpenChange(open) => void—Called when the panel opens or closes.
size'sm' | 'md' | 'lg''md'Single-row height 36 / 44 / 52px with 10 / 12 / 14px corners, pill height 24 / 28 / 36px, option rows 36 / 40 / 44px. Use lg on mobile.
placeholderstring'Select'Hint shown when nothing is selected.
disabledbooleanfalseDisables the control: pills lose their remove buttons and an open panel closes.
invalidbooleanfalseDanger hairline and tint, plus aria-invalid. Write the error text yourself and link it with aria-describedby.
requiredbooleanfalseSets aria-required; the asterisk is drawn by your form field.
searchablebooleanfalsePuts an input after the tags to filter by typing. The query clears after a keyboard pick and stays after a mouse pick.
onSearch(query) => void—Called when the query changes (after IME composition ends, and once with an empty string on close). Fetch remote results here.
filterOptionfalse | ((query, option) => boolean)—How to filter. Default: label contains the query, case-insensitive. Pass false for remote search.
clearablebooleanfalseShows a clear button when something can be removed. Its space is always reserved, so the field never resizes.
loadingbooleanfalseShows only “Loading…” in the panel while options load.
maxTagCountnumber | 'auto''auto'Maximum tags shown, the rest collapse into “+N”. 'auto' measures the width in one-row mode and shows all when wrapping.
wrapbooleanfalseWraps tags onto more rows and grows the field; by default it keeps a single row.
showSelectAllbooleanfalseShows “Select all / Clear” and the selected count above the list. With maxCount only Clear is shown.
maxCountnumber—Maximum number of selections. Once reached, unchecked options are dimmed and a hint explains why.
renderOption(option, { selected, active, query }) => ReactNode—Custom content to the right of each checkbox, such as an avatar. Search highlighting is then up to you (the demo wraps the match in <mark className="ds-multiselect__match">).
listHeightnumber240Maximum height of the option list in px; it scrolls beyond that.
emptyTextstring—Text when there are no options. Defaults to the noMatch or empty label.
labelsobject—Replaces built-in text (remove, clear, selectAll, selectedCount, summary, options, loading, noMatch, empty, limit, limitReached). Shallow-merged over the English defaults.
namestring—Renders a hidden <input name> per selected value, so native form submission includes them.
refRef<HTMLButtonElement | HTMLInputElement>—Forwarded to the focusable element: a <button>, or an <input> when searchable.
...restHTMLAttributes<HTMLDivElement>—className, style and similar go to the root. id, autoFocus and aria-label / labelledby / describedby go to the focusable element, so <label htmlFor> works. Set --ds-multiselect-z for the panel layer.

アクセシビリティ

  • Follows the WAI-ARIA combobox and listbox pattern: the focused element is a combobox with aria-expanded and aria-controls; the panel is a multiselectable listbox of options with aria-selected.
  • Focus stays on the field and the highlighted option is exposed with aria-activedescendant; a hidden summary (“3 selected: …”) is linked with aria-describedby.
  • Keys: Down / Up open and move (skipping disabled options), Home / End jump, PageUp / PageDown move 10, Enter toggles, Escape closes only the panel, Tab closes and moves on.
  • Backspace on an empty input removes the last tag; Ctrl / ⌘ + A selects all when select all is on.
  • On touch screens each option is at least 44px tall; with reduced motion the panel only fades and tags appear without scaling.

モーション

The panel enters in 220ms ease-out (from 6px toward the field and scale 0.96, with a fade, growing from the edge that touches the field) and leaves in 140ms ease-in. The field turns white and its accent halo grows in over 220ms. A newly checked pill pops in from scale 0.6 with a 320ms spring; the checkbox fills, springs back from a 0.88 press and its checkmark draws in 240ms; the limit hint turns warning-tinted and shakes for 240ms.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

MultiSelect.jsxmulti-select.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フォーム入力
「空き時間グリッド」は Pro に含まれます。解除するとプレビューが表示されます。
「図形のブール演算」は Pro に含まれます。解除するとプレビューが表示されます。
「カスケード選択」は Pro に含まれます。解除するとプレビューが表示されます。