Skip to the content
human-kit design
29 — Pickers

Transfer List

Two lists side by side, with buttons that move rows from one to the other.

Available 4
Date of birth
Doctor
Clinic
Insurer
Selected 2
Patient name
Cycle day

Installation

pnpm dlx @human-kit/design add transfer-list
npx @human-kit/design add transfer-list
yarn dlx @human-kit/design add transfer-list
bunx @human-kit/design add transfer-list

The command copies the files to src/lib/components/ui/transfer-list. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as TransferList from '$lib/components/ui/transfer-list';

	const columns = [
		{ id: 'name', label: 'Patient name' },
		{ id: 'doctor', label: 'Doctor' },
		{ id: 'clinic', label: 'Clinic' }
	];

	let shown = $state(['name']);
</script>

<TransferList.Root aria-label="Table columns" items={columns} bind:value={shown} />

Examples

A long list

With thousands of rows, set virtualizer={{ rowHeight: 24 }}: both lists draw only the rows near their viewport. The search, Shift ranges and "move all" still reach the rows that are not drawn, since they work on the array.

Samples 4997
LS-00001 · Embryo biopsy
LS-00002 · Blood
LS-00003 · Follicular fluid
LS-00005 · Semen
LS-00006 · Embryo biopsy
LS-00007 · Blood
LS-00008 · Follicular fluid
LS-00010 · Semen
LS-00011 · Embryo biopsy
In batch 3
LS-00004 · Endometrium
LS-00009 · Endometrium
LS-02500 · Semen

Guidelines

  • Use a transfer list to choose several items out of a long list and see both sides at once: the columns of a table, the members of a team.
  • For a few options, checkboxes are faster. For a choice the reader makes by typing, a multiple Combobox.Root takes less room.
  • Name both lists for what they mean, "Hidden" and "Shown", not "Left" and "Right".
  • Turn on reorder when the order of the right list is part of the answer, such as the order of columns.
  • Keep searchable on for lists longer than a screen. With a search on, the "move all" buttons move only the rows found.
  • The value is the keys of the right list, in order. Give getKey when the items have no id, and getLabel when their text is not in label or name.

Accessibility

  • Each list is a role="listbox" with several choices, named by its label. With an aria-label on the root, the whole is a role="group".
  • Each list is one tab stop. The arrow keys move through the rows, Space or Enter chooses one or lets it go, Shift with an arrow chooses a range.
  • Ctrl or Cmd with Enter sends the chosen rows to the other list; a double click sends one row.
  • The move buttons stay in the tab order when they have nothing to do, with aria-disabled, so the keyboard always finds them. Each is named by where the rows go: "Move selected to Shown".
  • Each move is announced in a polite live region.

API reference

PropTypeDefault
itemsT[]

Every item, in the order of the left list. Required.

—
value(string | number)[]

The keys of the items in the right list, in their order. Bindable.

—
defaultValue(string | number)[]

The keys in the right list at the start, when you give no value.

—
onChange(value, details) => void

Called after a move, with the new value and the items that moved.

—
getKey(item: T) => string | number

The identity of an item.

item.id
getLabel(item: T) => string

The text of a row, also what the search reads.

item.label ?? item.name
rowSnippet<[T]>

Draws a row yourself, in place of its text.

—
sourceLabelstring

The name over the left list.

'Available'
targetLabelstring

The name over the right list.

'Selected'
searchableboolean

A search field at the head of each list. Case and accents are ignored.

true
reorderboolean

Buttons to move the chosen rows of the right list up and down.

false
emptyTextstring

What an empty list says.

'Nothing here'
noMatchTextstring

What a search that finds nothing says.

'No matches'
virtualizer{ rowHeight?: number; overscan?: number }

Draws only the rows near the viewport, in both lists. rowHeight is 24; without it the first row is measured.

—
disabledKeysIterable<string | number>

The keys of the items that stay where they are.

—
namestring

The name of the hidden inputs that carry the value, so a form submits it.

—
moveShortcutboolean

Lets Ctrl or Cmd with Enter move the chosen rows across.

true

Plus every attribute of a <div>.