Drag and drop
TransferList
Assign permissions, reviewers, or other items by moving them between two named lists.
import '@reactloom/dnd/styles.css';
import { TransferList } from '@reactloom/dnd';Examples
Invoice permissions
- Draft invoices
- Issue invoices
- Read invoices
import { useState } from 'react';
import { TransferList } from '@reactloom/dnd';
const permissions = [
{ id: 'read', label: 'Read invoices' },
{ id: 'draft', label: 'Draft invoices' },
{ id: 'issue', label: 'Issue invoices' },
];
export default function Example() {
const [enabled, setEnabled] = useState(['read']);
return (
<TransferList items={permissions} value={enabled} onChange={setEnabled}
sourceLabel="Available permissions" destinationLabel="Enabled permissions" />
);
}Assign reviewers
- Priya Shah
- Ana Silva
No reviewers in this list
import { useState } from 'react';
import { TransferList } from '@reactloom/dnd';
const reviewers = [
{ id: 'priya', label: 'Priya Shah' },
{ id: 'ana', label: 'Ana Silva' },
];
export default function Example() {
const [assigned, setAssigned] = useState<string[]>([]);
return (
<TransferList items={reviewers} value={assigned} onChange={setAssigned}
sourceLabel="Available reviewers" destinationLabel="Assigned reviewers"
messages={{ empty: 'No reviewers in this list' }} />
);
}API reference
| Prop | Type | Default |
|---|---|---|
itemsrequiredAll items with a unique, stable string id and a label. | readonly T[] | — |
valuerequiredIDs in the destination list. The items prop determines display order on both sides. | readonly string[] | — |
onChangerequiredReceives the updated membership. Update value to commit the transfer. | (ids: string[]) => void | — |
sourceLabel · destinationLabelrequiredVisible and accessible names for the two sides. | string | — |
disabledDisable drag and move controls on both sides. | boolean | false |
messagesTranslate action labels, empty text, and announcements. | Partial<TransferMessages> | — |
classNameApply a class to the outer element. | string | — |
Customization
Set a root className to apply local theme overrides such as --pl-color-border-default or --pl-focus-ring-color. Style an active drop zone with [data-drop-target] and the active handle with [data-dragging].
Accessibility
Each item has a move button and a drag handle. Focus follows the moved item and the live region announces the destination. A list remains a valid drop target when it’s empty.
| Key | Action |
|---|---|
| Enter or Space on a move button | Move to the other list |
| Enter or Space on a drag handle | Enter drag mode and focus the other list |
| Enter or Escape in drag mode | Drop or cancel |
Usage guidelines
Do
- Use names that describe the state, such as Available permissions and Enabled permissions.
Don’t
- Avoid using the transfer list for reordering items within one collection. Use SortableList for that.