--- productId: material-ui title: Transfer list React component components: List, ListItem, Checkbox, Switch githubLabel: 'scope: transfer list' --- # Transfer List A Transfer List (or "shuttle") enables the user to move one or more list items between lists. ## Basic transfer list For completeness, this example includes buttons for "move all", but not every transfer list needs these. ```tsx import * as React from 'react'; import Grid from '@mui/material/Grid'; import List from '@mui/material/List'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import Checkbox from '@mui/material/Checkbox'; import Button from '@mui/material/Button'; import Paper from '@mui/material/Paper'; import Stack from '@mui/material/Stack'; function not(a: readonly number[], b: readonly number[]) { return a.filter((value) => !b.includes(value)); } function intersection(a: readonly number[], b: readonly number[]) { return a.filter((value) => b.includes(value)); } export default function TransferList() { const [checked, setChecked] = React.useState([]); const [left, setLeft] = React.useState([0, 1, 2, 3]); const [right, setRight] = React.useState([4, 5, 6, 7]); const leftChecked = intersection(checked, left); const rightChecked = intersection(checked, right); const handleToggle = (value: number) => () => { const currentIndex = checked.indexOf(value); const newChecked = [...checked]; if (currentIndex === -1) { newChecked.push(value); } else { newChecked.splice(currentIndex, 1); } setChecked(newChecked); }; const handleAllRight = () => { setRight(right.concat(left)); setLeft([]); }; const handleCheckedRight = () => { setRight(right.concat(leftChecked)); setLeft(not(left, leftChecked)); setChecked(not(checked, leftChecked)); }; const handleCheckedLeft = () => { setLeft(left.concat(rightChecked)); setRight(not(right, rightChecked)); setChecked(not(checked, rightChecked)); }; const handleAllLeft = () => { setLeft(left.concat(right)); setRight([]); }; const customList = (items: readonly number[]) => ( {items.map((value: number) => { const labelId = `transfer-list-item-${value}-label`; return ( ); })} ); return ( {customList(left)} {customList(right)} ); } ``` ## Enhanced transfer list This example exchanges the "move all" buttons for a "select all / select none" checkbox and adds a counter. ```tsx import * as React from 'react'; import Grid from '@mui/material/Grid'; import List from '@mui/material/List'; import Card from '@mui/material/Card'; import CardHeader from '@mui/material/CardHeader'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemText from '@mui/material/ListItemText'; import ListItemIcon from '@mui/material/ListItemIcon'; import Checkbox from '@mui/material/Checkbox'; import Button from '@mui/material/Button'; import Divider from '@mui/material/Divider'; import Stack from '@mui/material/Stack'; function not(a: readonly number[], b: readonly number[]) { return a.filter((value) => !b.includes(value)); } function intersection(a: readonly number[], b: readonly number[]) { return a.filter((value) => b.includes(value)); } function union(a: readonly number[], b: readonly number[]) { return [...a, ...not(b, a)]; } export default function SelectAllTransferList() { const [checked, setChecked] = React.useState([]); const [left, setLeft] = React.useState([0, 1, 2, 3]); const [right, setRight] = React.useState([4, 5, 6, 7]); const leftChecked = intersection(checked, left); const rightChecked = intersection(checked, right); const handleToggle = (value: number) => () => { const currentIndex = checked.indexOf(value); const newChecked = [...checked]; if (currentIndex === -1) { newChecked.push(value); } else { newChecked.splice(currentIndex, 1); } setChecked(newChecked); }; const numberOfChecked = (items: readonly number[]) => intersection(checked, items).length; const handleToggleAll = (items: readonly number[]) => () => { if (numberOfChecked(items) === items.length) { setChecked(not(checked, items)); } else { setChecked(union(checked, items)); } }; const handleCheckedRight = () => { setRight(right.concat(leftChecked)); setLeft(not(left, leftChecked)); setChecked(not(checked, leftChecked)); }; const handleCheckedLeft = () => { setLeft(left.concat(rightChecked)); setRight(not(right, rightChecked)); setChecked(not(checked, rightChecked)); }; const customList = (title: React.ReactNode, items: readonly number[]) => ( } title={title} subheader={`${numberOfChecked(items)}/${items.length} selected`} /> {items.map((value: number) => { const labelId = `transfer-list-all-item-${value}-label`; return ( ); })} ); return ( {customList('Choices', left)} {customList('Chosen', right)} ); } ``` ## Limitations The component comes with a couple of limitations: - It only works on desktop. If you have a limited amount of options to select, prefer the [Autocomplete](/material-ui/react-autocomplete/#multiple-values) component. If mobile support is important for you, have a look at [#27579](https://github.com/mui/material-ui/issues/27579). - There are no high-level components exported from npm. The demos are based on composition. If this is important for you, have a look at [#27579](https://github.com/mui/material-ui/issues/27579).