本文へ移動
日本語
「トランスファー」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

Two panels with the same structure, each a soft --ds-surface-2 surface with 16px corners and no lines: a header with the title, a count pill (the total, or “checked / total” in accent) and the select-all box, an optional white search field, and a self-scrolling list of rounded 40px rows with an optional avatar on the left and an 18px check box on the right. Checked rows take a faint accent tint. The round buttons between the panels turn accent when there is something to move. Moved items slide in from the side they came from and flash briefly. Both panels follow the order of items, so a moved item returns to its original relative position. The layout depends on the component's own width (not the viewport): two compact panels fit side by side down to 320px. The outer height never changes while moving, checking or searching.

向いている場面

  • Picking a subset where people need to see what is already chosen: project members, coupon products, role assignments.
  • Dozens to hundreds of candidates that need search, select all and several rounds of picking.
  • Reviewing and undoing a selection: the right panel is the result list, and moving an item back removes it.

向かない場面

  • Fewer than 8 candidates: a checkbox group shows everything at once.
  • Space for just one input: use a multi-select dropdown.
  • Hierarchical candidates: use a tree with check boxes.
  • The chosen items need manual ordering: the right panel follows the order of items.
  • Thousands of items: every item is rendered in the DOM, so add paging or virtual scrolling.

使い方

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

// avatar is optional: initials or an <img>, shown in a 28px circle
const people = [
  { key: 'maya', label: 'Maya Chen', description: 'Design', avatar: 'M' },
  { key: 'emma', label: 'Emma Davis', description: 'Engineering', avatar: 'E' },
  { key: 'ava', label: 'Ava Taylor', description: 'Marketing', avatar: 'A' },
  { key: 'jack', label: 'Jack Wilson (on leave)', description: 'Marketing', avatar: 'J', disabled: true },
]

// value holds the keys in the right-hand panel
export function ProjectMembers() {
  const [members, setMembers] = useState(['maya'])
  return (
    <Transfer
      aria-label="Choose project members"
      items={people}
      value={members}
      onChange={(keys, { direction, movedKeys }) => {
        setMembers(keys)
        console.log(direction === 'right' ? 'added' : 'removed', movedKeys)
      }}
      titles={['Available', 'Members']}
      searchable
      height={360}
    />
  )
}

プロパティ

プロパティ型既定値説明
items{ key: string, label: string, description?: string, avatar?: ReactNode, disabled?: boolean }[]—All options, both panels together. Keys are unique strings; disabled items are greyed out and cannot be checked. avatar is an optional 28px circle on the left of the row (initials or an <img>); it is decorative, the label carries the name.
valuestring[]—Controlled: keys of the items in the right-hand panel. Omit to let the component keep it.
defaultValuestring[][]Uncontrolled: items that start in the right-hand panel.
onChange(targetKeys, { direction, movedKeys }) => void—Called after a move with all right-hand keys, in items order. direction is 'right' or 'left'; movedKeys are the items moved.
titles[string, string]['Available', 'Selected']Panel titles; they also appear in the screen reader announcement after a move.
searchablebooleanfalseShows a search field under each panel header; each panel searches on its own.
searchPlaceholderstring'Search'Placeholder of the search fields.
filterOption(keyword, item) => boolean—Custom match rule. By default label and description are searched, ignoring case.
render(item) => ReactNode—Custom content between the avatar and the check box. Search highlighting is then up to you.
showSelectAllbooleantrueShows the select-all box at the right of each header, in line with the row check boxes; it covers visible, enabled items and can be indeterminate.
heightnumber | string280Height of the whole component. Stacked panels (below 320px of its own width) share what remains after the button row.
disabledbooleanfalseDisables checking, searching and moving.
emptyTextReactNode—Text for an empty panel. Defaults to the labels noMatch (while searching) or noData.
labelsobject—Replaces built-in text (selectAll, checkedCount, searchIn, clearSearch, noMatch, noData, moveRight, moveLeft, moveDown, moveUp, movedRight, movedLeft). Shallow-merged over the English defaults.
...restHTMLAttributes<HTMLDivElement>—className, style, aria-label and others go to the root <div role="group">. Use aria-label to say what is being chosen.

アクセシビリティ

  • The root is a labelled group; each panel is a group named by its title, each list a multi-selectable listbox with options carrying aria-selected.
  • Each list is one Tab stop using aria-activedescendant: Up and Down move, Home and End jump, Space toggles, Shift+Space or Shift+click checks a range, Ctrl/Cmd+A selects all.
  • The arrow buttons have names that change with the layout and use aria-disabled when nothing can move, so focus is never lost.
  • A polite live region announces each move, such as “Moved 2 items to Selected”.
  • Checked is a tick and indeterminate a dash, not only colour; avatars are hidden from screen readers; high-contrast mode outlines the panels and uses the system highlight colour.

モーション

Checking squeezes the box to 0.88 while pressed and springs it back (320ms), then draws the tick in 240ms. Moved items slide 8px in from the side they came from (320ms ease-out) while a light accent layer fades from 1 to 0 over about 1.1s. The move buttons fill with the accent in 200ms when something becomes movable and press down to 0.9 with a spring. The search field's halo grows in 220ms. With reduced motion nothing slides, scales or flashes; states switch at once.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

Transfer.jsxtransfer.csstokens.cssREADME.md

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

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