List

Lists are continuous, vertical indexes of text or images.

<List>
<ListItem>Item 1</ListItem>
<ListItem>Item 2</ListItem>
</List>

Props

PropTypeDefaultDescription
childrennodeThe content of the component.
classesobjectOverride or extend the styles applied to the component. See CSS API below for more details.
componentelementType'ul'The component used for the root node. Either a string to use a HTML element or a component.
denseboolfalseIf true, compact vertical padding designed for keyboard and mouse input will be used for the list and list items. The prop is available to descendant components as the dense context.
disablePaddingboolfalseIf true, vertical padding will be removed from the list.
subheadernodeThe content of the subheader, normally ListSubheader.

The ref is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

Examples

Basic

<>
<List component="nav" aria-label="main mailbox folders">
<ListItem button>
<ListItemIcon>
<Add />
</ListItemIcon>
<ListItemText primary="Inbox" />
</ListItem>
<ListItem button>
<ListItemIcon>
<Mail />
</ListItemIcon>
<ListItemText primary="Drafts" />
</ListItem>
</List>
<Divider />
<List component="nav" aria-label="secondary mailbox folders">
<ListItem button>
<ListItemText primary="Trash" />
</ListItem>
<ListItem button component="a" href="#simple-list">
<ListItemText primary="Spam" />
</ListItem>
</List>
</>

Nested List

() => {
const [open, setOpen] = React.useState(false);
function handleClick() {
setOpen((open) => !open);
}
return (
<List
component="nav"
aria-labelledby="nested-list-subheader"
subheader={
<ListSubheader component="div" id="nested-list-subheader">
Nested List Items
</ListSubheader>
}
>
<ListItem button>
<ListItemIcon>
<Send />
</ListItemIcon>
<ListItemText primary="Sent mail" />
</ListItem>
<ListItem button>
<ListItemIcon>
<Goal />
</ListItemIcon>
<ListItemText primary="Drafts" />
</ListItem>
<ListItem button onClick={handleClick}>
<ListItemIcon>
<Mail />
</ListItemIcon>
<ListItemText primary="Inbox" />
{open ? <ArrowDown /> : <ArrowRight />}
</ListItem>
<Collapse in={open} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
<ListItem style={{ paddingLeft: '2rem' }} button>
<ListItemIcon>
<Notification />
</ListItemIcon>
<ListItemText primary="Starred" />
</ListItem>
</List>
</Collapse>
</List>
);
};

Using Secondary Action

() => {
const [checked, setChecked] = React.useState([1]);
const handleToggle = (value) => () => {
const currentIndex = checked.indexOf(value);
const newChecked = [...checked];
if (currentIndex === -1) {
newChecked.push(value);
} else {
newChecked.splice(currentIndex, 1);
}
setChecked(newChecked);
};
return (
<List dense>
{[0, 1, 2, 3].map((value) => {
const labelId = `checkbox-list-secondary-label-${value}`;
return (
<ListItem key={value} button>
<ListItemAvatar>
<Avatar
alt={`Avatar n°${value + 1}`}
src={`/static/images/avatar/${value + 1}.jpg`}
/>
</ListItemAvatar>
<ListItemText id={labelId} primary={`Line item ${value + 1}`} />
<ListItemSecondaryAction>
<Checkbox
edge="end"
onChange={handleToggle(value)}
checked={checked.indexOf(value) !== -1}
inputProps={{ 'aria-labelledby': labelId }}
/>
</ListItemSecondaryAction>
</ListItem>
);
})}
</List>
);
};