<List data-test="list-item-selection">
<ListItem selected>
<ListItemText primary="First line of content" />
<ListItem>
<ListItemText primary="First line of content" />
</ListItem>
<ListItem selected>
<ListItemText primary="First line of content" />
</ListItem>
<ListItem>
<ListItemText primary="First line of content" />
</ListItem>
</List>
</Playground>
A list item may optionally contain a supporting visual. These are not limited to simply icons, but may also be interactive components. When using an interactive component as the supporting visual, the onClick event of the supporting visual will not trigger the ListItem
primary action (its onClick
event handler).
<List data-test="list-supporting-visual">
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText primary="First line of content" />
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
/>
</ListItem>
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="Third line of content"
/>
</ListItem>
<ListItem
supportingVisual={
<IconButton
icon={AssetIcon}
onClick={() => console.log('Supporting visual click')}
/>
}
onClick={() => console.log('ListItem click')}
>
<ListItemText primary="Action-able (onClick) supporting visual" />
</ListItem>
</List>
</Playground>
List items are clickable; which represents the primary action. Items may also contain a single, ancillary action; a secondary action.
Clicking a secondary action will not trigger the primary action (
onClick
event handler on theListItem
).
<List data-test="list-item-actions">
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
}
>
<ListItemText primary="First line of content" />
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
/>
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="Third line of content"
/>
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText primary="First line of content" />
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
/>
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="Third line of content"
/>
</ListItem>
</List>
</Playground>
List items with primary actions are focus-able. When a list item is focused, then tabbing will focus the list item's supporting visual and then secondary action. Pressing up/down arrow keys will move the focus to the next list item.
All list items are focus-able, even if they do not contain a primary action.
<List data-test="list-focusable">
<ListItem
onClick={() => console.log('ListItem 1 click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action 1 click')}>
Secondary Action 1
}
supportingVisual={
<IconButton
icon={AssetIcon}
onClick={() => console.log('Supporting visual 1 click')}
/>
}
>
<ListItemText primary="1" />
</ListItem>
<ListItem
onClick={() => console.log('ListItem 2 click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action 2 click')}>
Secondary Action 2
</Button>
}
supportingVisual={
<IconButton
icon={AssetIcon}
onClick={() => console.log('Supporting visual 2 click')}
/>
}
>
<ListItemText primary="2" />
</ListItem>
<ListItem
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText primary="3 (not focusable)" />
</ListItem>
<ListItem
onClick={() => console.log('ListItem 4 click')}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Action
</Button>
}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText primary="4" />
</ListItem>
</List>
</Playground>
A ListItem
may have up to 3 distinct content values; primary
, secondary
, tertiary
. Each value will render on its own line. Content that is too long will be clamped (to a single line only).
A list item text's values can contain click event handlers; triggering one will not trigger the click event handler on the
ListItem
.
<List data-test="list-content-too-long">
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Actions
}
>
<ListItemText
primary="Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text."
secondary="Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text."
tertiary="Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text."
/>
</ListItem>
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
secondaryAction={
<Button onClick={() => console.log('Secondary action click')}>
Secondary Actions
</Button>
}
>
<ListItemText
primary="Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext."
secondary="Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext.Longsecondlineoftext."
tertiary="Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext.Longthirdlineoftext."
/>
</ListItem>
</List>
</Playground>
A dense list is suited for Lists with items that contain only a primary action. Do not use a dense list if requiring a secondary action.
<List dense>
<ListItem onClick={() => console.log('ListItem click')}>
<ListItemText primary="First line of content" />
<ListItem onClick={() => console.log('ListItem click')}>
<ListItemText
primary="First line of content"
secondary="Second line of content"
/>
</ListItem>
<ListItem onClick={() => console.log('ListItem click')}>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="Third line of content"
/>
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText primary="First line of content" />
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
/>
</ListItem>
<ListItem
onClick={() => console.log('ListItem click')}
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="Third line of content"
/>
</ListItem>
</List>
</Playground>
<List noBorder>
<ListItem>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="third line of content"
/>
<ListItem>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="third line of content"
/>
</ListItem>
<ListItem>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="third line of content"
/>
</ListItem>
</List>
</Playground>
<div style={{ width: '300px' }}>
<SpacedGroup direction="vertical">
<List data-test="list-parent-width">
<ListItem
supportingVisual={
<Avatar
size={36}
src={
'https://i.pinimg.com/236x/c1/2e/ba/c12eba2c171e51501c00759b3363367c--dapper-suits-bloomberg-businessweek.jpg'
}
/>
}
secondaryAction={<AssetIcon />}
>
<ListItemText
primary="Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text."
secondary="Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text. Long second line of text."
tertiary="Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text. Long third line of text."
/>
<ListItem>
<ListItemText
primary="First line of content"
secondary="Second line of content"
tertiary="third line of content"
/>
</ListItem>
</List>
</SpacedGroup>
</div>
</Playground>
<List>
<ListItem data-trackingid="edit" onClick={() => {}}>
<ListItemText primary="title" />
</ListItem>
</List>
<List>
<ListItem data-trackingid="edit" onClick={() => {}}>
<ListItemText primary="title" />
</List>
</Playground>