Messages
Lists are continuous, vertical indexes of text and images. Use a list to help people find a specific item and act on it. To show content of several kinds about one subject, such as an image, text and actions, use a card instead.
A list is made of these parts:
| Part | Use |
|---|---|
List | The container of the items |
ListItem | One item, with its parts in slots |
Text | From react-aria-components: the label, the supporting text, the overline and the trailing text of an item |
useDragAndDrop | The hook that lets people drag the items |
import { List, ListItem, useDragAndDrop } from '@material-web/react'
import { Text } from 'react-aria-components'Basic list
Put one ListItem per item in a List, and write the parts of an item as its children, each with its slot. Import Text from react-aria-components.
import { Icon, IconButton, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Basic() {
return (
<List aria-label="Contacts" variant="segmented" className="w-90">
<ListItem id="ali" textValue="Ali Connors">
<Icon slot="leading" name="person" />
<Text slot="overline">Favorite</Text>
<Text slot="label">Ali Connors</Text>
<Text slot="description">Brunch this weekend?</Text>
<Text slot="trailing">100+</Text>
<IconButton slot="trailing" aria-label="More options for Ali Connors">
<Icon name="more_vert" />
</IconButton>
</ListItem>
<ListItem id="sandra" textValue="Sandra Adams">
<Icon slot="leading" name="person" />
<Text slot="label">Sandra Adams</Text>
<Text slot="description">Oui oui</Text>
<Text slot="trailing">12</Text>
<IconButton slot="trailing" aria-label="More options for Sandra Adams">
<Icon name="more_vert" />
</IconButton>
</ListItem>
<ListItem id="trevor" textValue="Trevor Hansen">
<Icon slot="leading" name="person" />
<Text slot="label">Trevor Hansen</Text>
<Text slot="description">Birthday gift</Text>
<Text slot="trailing">3</Text>
<IconButton slot="trailing" aria-label="More options for Trevor Hansen">
<Icon name="more_vert" />
</IconButton>
</ListItem>
</List>
)
}- Ids: Give each
ListItemanid, which identifies it in the list's selection and actions. - Text values: Give each
ListItematextValuewith the text of its label, which names the item. An item whose children are plain text uses them as itstextValue. For any other item,textValueis required. - Dynamic lists: Write the items as the
childrenof the list, or pass the list itsitemsand a function that returns theListItemof each one. Passdependenciesalong with them when that function depends on other values. See Collections and React Aria's collections guide. - Outside a list: A
ListItemoutside aListthrows an error.
A List takes the props of React Aria's GridList, and a ListItem those of its GridListItem. The Props tab lists them.
Note: GridListSection and GridListLoadMoreItem from react-aria-components are not styled.
A list comes in two variants. Set variant to standard (the default) or segmented. The variant is a visual choice and does not change how a list behaves.
import { List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
const contacts = [
{ id: 'ali', name: 'Ali Connors', message: 'Brunch this weekend?' },
{ id: 'sandra', name: 'Sandra Adams', message: 'Oui oui' },
{ id: 'trevor', name: 'Trevor Hansen', message: 'Birthday gift' },
]
export default function Variants() {
return (
<>
{(['standard', 'segmented'] as const).map((variant) => (
<List key={variant} aria-label={`Contacts, ${variant}`} variant={variant} className="w-72">
{contacts.map((contact) => (
<ListItem key={contact.id} id={contact.id} textValue={contact.name}>
<Text slot="label">{contact.name}</Text>
<Text slot="description">{contact.message}</Text>
</ListItem>
))}
</List>
))}
</>
)
}Standard list
A standard list shows its items one after another, with no gap between them.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Standard() {
return (
<List aria-label="Folders" variant="standard" className="w-90">
<ListItem id="inbox" textValue="Inbox">
<Icon slot="leading" name="inbox" />
<Text slot="label">Inbox</Text>
<Text slot="trailing">24</Text>
</ListItem>
<ListItem id="starred" textValue="Starred">
<Icon slot="leading" name="star" />
<Text slot="label">Starred</Text>
<Text slot="trailing">3</Text>
</ListItem>
<ListItem id="sent" textValue="Sent">
<Icon slot="leading" name="send" />
<Text slot="label">Sent</Text>
</ListItem>
</List>
)
}Segmented list
A segmented list separates the items with a gap and rounds the corners at the two ends of the list. Use it for a contained list, where the gaps set the items apart as a group.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Segmented() {
return (
<div className="rounded-shape-xl bg-surface-container p-space-200">
<List aria-label="Account" variant="segmented" className="w-80">
<ListItem id="profile" textValue="Profile">
<Icon slot="leading" name="person" />
<Text slot="label">Profile</Text>
<Text slot="description">Name, photo and bio</Text>
</ListItem>
<ListItem id="security" textValue="Security">
<Icon slot="leading" name="lock" />
<Text slot="label">Security</Text>
<Text slot="description">Password and sign-in</Text>
</ListItem>
<ListItem id="notifications" textValue="Notifications">
<Icon slot="leading" name="notifications" />
<Text slot="label">Notifications</Text>
<Text slot="description">Email and push</Text>
</ListItem>
</List>
</div>
)
}Slots
- leading
- overline
- label
- description
- trailing
- selection
| Slot | Child | Use |
|---|---|---|
leading | An Icon, a button, a Checkbox or an element of your own | Before the text. See Leading. |
overline | A Text | The overline, over the label |
label | A Text | The label text |
description | A Text | The supporting text, under the label |
trailing | A Text, an Icon, a button, a Checkbox or an element of your own | At the end of the item, in the order written. See Trailing. |
selection | A Checkbox | The item's selection checkbox |
Set slot on each part of an item to place it.
- A button, including a selectable one, is disabled with the item. A button also takes the
dragslot. - A
Checkboxin theleadingortrailingslot is the item's selection checkbox as well. - A part with a slot the item does not have throws an
Invalid sloterror. - An element of your own is placed by its
slotattribute, which is not checked. - Give every part a slot. A part without one is placed wherever the item has room.
See Slots.
Text
Write an item's text in a Text for each part, and set its slot:
labelis the label text.descriptionis the supporting text, under the label.overlineis the overline, over the label.trailingis the trailing text, such as a count.
For an item with a label alone, write plain text as its children: <ListItem>Label text</ListItem>.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function TextSlots() {
return (
<List aria-label="Inbox" variant="segmented" className="w-90">
<ListItem id="label">Label text alone</ListItem>
<ListItem id="one" textValue="One line">
<Icon slot="leading" name="mail" />
<Text slot="label">One line</Text>
<Text slot="trailing">100+</Text>
</ListItem>
<ListItem id="two" textValue="Two lines">
<Icon slot="leading" name="mail" />
<Text slot="label">Two lines</Text>
<Text slot="description">Supporting text under the label</Text>
<Text slot="trailing">100+</Text>
</ListItem>
<ListItem id="three" textValue="Three lines">
<Icon slot="leading" name="mail" />
<Text slot="overline">Overline</Text>
<Text slot="label">Three lines</Text>
<Text slot="description">Supporting text under the label</Text>
<Text slot="trailing">100+</Text>
</ListItem>
<ListItem id="wrapped" textValue="A wrapping line">
<Icon slot="leading" name="mail" />
<Text slot="label">A wrapping line</Text>
<Text slot="description">
Supporting text that is long enough to wrap adds its lines to the item
</Text>
</ListItem>
</List>
)
}Leading
Put a part in the leading slot to show it before the text: an Icon, or an avatar, an image or a video thumbnail of your own. An Icon is sized by the item. Size an element of your own with classes: size-10 rounded-full for a 40dp round avatar, size-14 rounded-shape-sm for a 56dp image, and h-14 w-25 rounded-shape-sm for a 100 by 56dp video thumbnail.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
const picture = `data:image/svg+xml,${encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 56"><rect width="100" height="56" fill="#6750A4"/><path d="M42 16 62 28 42 40Z" fill="#fff"/></svg>',
)}`
export default function Leading() {
return (
<List aria-label="Media" variant="segmented" className="w-90">
<ListItem id="icon" textValue="Leading icon">
<Icon slot="leading" name="star" />
<Text slot="label">Leading icon</Text>
<Text slot="description">20dp</Text>
</ListItem>
<ListItem id="avatar" textValue="Leading avatar">
<span
slot="leading"
aria-hidden
className="grid size-10 place-items-center rounded-full bg-primary-container text-title-md text-on-primary-container"
>
A
</span>
<Text slot="label">Leading avatar</Text>
<Text slot="description">40dp, round</Text>
</ListItem>
<ListItem id="image" textValue="Leading image">
<img
slot="leading"
src={picture}
alt=""
className="size-14 rounded-shape-sm object-cover"
/>
<Text slot="label">Leading image</Text>
<Text slot="description">56dp</Text>
</ListItem>
<ListItem id="video" textValue="Leading video">
<img slot="leading" src={picture} alt="" className="h-14 w-25 rounded-shape-sm" />
<Text slot="label">Leading video</Text>
<Text slot="description">100 by 56dp</Text>
</ListItem>
</List>
)
}Trailing
Put parts in the trailing slot to show them at the end of the item, in the order written: an Icon, trailing text, or icon buttons. A press on a button does not call the item's onAction.
import { Icon, IconButton, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Trailing() {
return (
<List aria-label="Downloads" variant="segmented" className="w-90">
<ListItem id="text" textValue="Trailing text">
<Text slot="label">Trailing text</Text>
<Text slot="trailing">2.4 MB</Text>
</ListItem>
<ListItem id="icon" textValue="Trailing icon">
<Text slot="label">Trailing icon</Text>
<Icon slot="trailing" name="chevron_right" className="rtl:icon-mirrored" />
</ListItem>
<ListItem id="buttons" textValue="Trailing icon buttons">
<Text slot="label">Trailing icon buttons</Text>
<Text slot="trailing">2.4 MB</Text>
<IconButton slot="trailing" aria-label="Share">
<Icon name="share" />
</IconButton>
<IconButton slot="trailing" aria-label="Delete">
<Icon name="delete" />
</IconButton>
</ListItem>
</List>
)
}Empty state
Pass renderEmptyState a function that returns what the list shows while it has no items.
import { List } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Empty() {
return (
<List
aria-label="Results"
className="w-90"
renderEmptyState={() => (
<Text className="block px-space-200 py-space-150 text-body-lg text-on-surface-variant">
No results
</Text>
)}
>
{[]}
</List>
)
}Handling actions
Set onAction on a ListItem, or on the List, to handle a click, a tap or Enter on an item. The list's onAction is called with the id of the item, and the item's own with no argument. A press on a button in the item does not call onAction.
Nothing yet
import { Icon, IconButton, List, ListItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'
const contacts = [
{ id: 'ali', name: 'Ali Connors', message: 'Brunch this weekend?' },
{ id: 'sandra', name: 'Sandra Adams', message: 'Oui oui' },
{ id: 'trevor', name: 'Trevor Hansen', message: 'Birthday gift' },
]
export default function Actions() {
const [last, setLast] = useState('Nothing yet')
return (
<div className="flex w-90 flex-col gap-space-200">
<List
aria-label="Messages"
variant="segmented"
items={contacts}
onAction={(id) => setLast(`Opened ${id}`)}
>
{(contact) => (
<ListItem textValue={contact.name}>
<Text slot="label">{contact.name}</Text>
<Text slot="description">{contact.message}</Text>
<IconButton
slot="trailing"
aria-label={`Bookmark ${contact.name}`}
onPress={() => setLast(`Bookmarked ${contact.id}`)}
>
<Icon name="bookmark" />
</IconButton>
</ListItem>
)}
</List>
<p className="m-0 text-body-md text-on-surface-variant">{last}</p>
</div>
)
}In a list that also selects, a press either selects the item or acts on it. See React Aria's Item actions.
Selection
Set selectionMode on the List to single or multiple to make its items selectable. Set the initial selection with defaultSelectedKeys, or control it with selectedKeys and onSelectionChange. The keys are the ids of the selected items. A selected item is highlighted, and its icons are filled.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
const sounds = ['Chime', 'Ripple', 'Sonar', 'Beacon']
export default function SingleSelect() {
return (
<List
aria-label="Notification sound"
variant="segmented"
className="w-90"
selectionMode="single"
defaultSelectedKeys={['Ripple']}
>
{sounds.map((sound) => (
<ListItem key={sound} id={sound} textValue={sound}>
{({ isSelected }) => (
<>
<Icon slot="leading" name={isSelected ? 'check' : 'music_note'} />
<Text slot="label">{sound}</Text>
</>
)}
</ListItem>
))}
</List>
)
}In a single-select list, a click on the selected item deselects it. Set disallowEmptySelection to prevent that.
The list also takes selectionBehavior, disabledKeys, disabledBehavior and escapeKeyBehavior. See React Aria's Selection guide.
Non-interactive list
A list with no selection mode and no actions is non-interactive: its items show no hover or pressed state. The keyboard still moves the focus through them.
import { List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function NonInteractive() {
return (
<List aria-label="Details" className="w-90">
<ListItem id="size" textValue="Size">
<Text slot="label">Size</Text>
<Text slot="trailing">2.4 MB</Text>
</ListItem>
<ListItem id="modified" textValue="Modified">
<Text slot="label">Modified</Text>
<Text slot="trailing">Nov 6, 2026</Text>
</ListItem>
<ListItem id="owner" textValue="Owner">
<Text slot="label">Owner</Text>
<Text slot="trailing">Ali Connors</Text>
</ListItem>
</List>
)
}Drag and drop
Call useDragAndDrop from @material-web/react and pass its dragAndDropHooks to the List. The hook takes the same options as React Aria's useDragAndDrop. To reorder a list, pass getItems and onReorder, as in the example below.
Each item then shows a drag handle at its start. The handle is how the keyboard drags an item, and a pointer drags the item itself.
import { List, ListItem, useDragAndDrop } from '@material-web/react'
import { Text, useListData } from 'react-aria-components'
export default function DragAndDrop() {
const list = useListData({
initialItems: [
{ id: 'ali', name: 'Ali Connors', message: 'Brunch this weekend?' },
{ id: 'sandra', name: 'Sandra Adams', message: 'Oui oui' },
{ id: 'trevor', name: 'Trevor Hansen', message: 'Birthday gift' },
{ id: 'britta', name: 'Britta Holt', message: 'Recipe to try' },
],
})
const { dragAndDropHooks } = useDragAndDrop({
getItems: (keys) => [...keys].map((key) => ({ 'text/plain': list.getItem(key)?.name ?? '' })),
onReorder(e) {
if (e.target.dropPosition === 'before') list.moveBefore(e.target.key, e.keys)
else if (e.target.dropPosition === 'after') list.moveAfter(e.target.key, e.keys)
},
})
return (
<List
aria-label="Favorites"
variant="segmented"
className="w-90"
items={list.items}
dragAndDropHooks={dragAndDropHooks}
>
{(item) => (
<ListItem textValue={item.name}>
<Text slot="label">{item.name}</Text>
<Text slot="description">{item.message}</Text>
</ListItem>
)}
</List>
)
}- While an item is dragged, a placeholder shows where it would be dropped. In a keyboard drag, the arrow keys move the placeholder.
- Pass
renderDragPreviewto the hook to replace the preview that the pointer drags. - Pass
renderDropIndicatorto the hook to replace the placeholder.
Between lists
To move an item to another list, insert it in the onInsert of the list that receives it, and remove it in the onDragEnd of the list it leaves when the dropOperation is 'move'. See React Aria's drag and drop guide.
import { List, ListItem, useDragAndDrop } from '@material-web/react'
import { isTextDropItem, Text, useListData } from 'react-aria-components'
type Task = { id: string; name: string }
function TaskList({ label, tasks }: { label: string; tasks: Task[] }) {
const list = useListData({ initialItems: tasks })
const { dragAndDropHooks } = useDragAndDrop({
getItems: (keys) => [...keys].map((key) => ({ task: JSON.stringify(list.getItem(key)) })),
acceptedDragTypes: ['task'],
getDropOperation: () => 'move',
onReorder(e) {
if (e.target.dropPosition === 'before') list.moveBefore(e.target.key, e.keys)
else if (e.target.dropPosition === 'after') list.moveAfter(e.target.key, e.keys)
},
async onInsert(e) {
const dropped = await Promise.all(
e.items.filter(isTextDropItem).map(async (item) => JSON.parse(await item.getText('task'))),
)
if (e.target.dropPosition === 'before') list.insertBefore(e.target.key, ...dropped)
else if (e.target.dropPosition === 'after') list.insertAfter(e.target.key, ...dropped)
},
async onRootDrop(e) {
const dropped = await Promise.all(
e.items.filter(isTextDropItem).map(async (item) => JSON.parse(await item.getText('task'))),
)
list.append(...dropped)
},
onDragEnd(e) {
if (e.dropOperation === 'move' && !e.isInternal) list.remove(...e.keys)
},
})
return (
<List
aria-label={label}
variant="segmented"
className="min-h-40 w-64"
items={list.items}
dragAndDropHooks={dragAndDropHooks}
renderEmptyState={() => (
<Text className="block p-space-200 text-on-surface-variant">Drop a task here</Text>
)}
>
{(task) => <ListItem>{task.name}</ListItem>}
</List>
)
}
export default function BetweenLists() {
return (
<>
<TaskList
label="To do"
tasks={[
{ id: 'tickets', name: 'Book the tickets' },
{ id: 'hotel', name: 'Find a hotel' },
{ id: 'pack', name: 'Pack the bags' },
]}
/>
<TaskList label="Done" tasks={[{ id: 'passport', name: 'Renew the passport' }]} />
</>
)
}React Aria's own hook
The useDragAndDrop hook from react-aria-components works with a List as well. With it, the drop indicator is a line where the item would be dropped, the dragged item stays in its place, and the other items do not slide.
Disabled
Set isDisabled on an item to disable it, or list its id in the disabledKeys of the list.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Disabled() {
return (
<List
aria-label="Contacts"
variant="segmented"
className="w-90"
selectionMode="single"
defaultSelectedKeys={['sandra']}
disabledKeys={['sandra', 'trevor']}
>
<ListItem id="ali" textValue="Ali Connors">
<Icon slot="leading" name="person" />
<Text slot="label">Ali Connors</Text>
<Text slot="description">Enabled</Text>
</ListItem>
<ListItem id="sandra" textValue="Sandra Adams">
<Icon slot="leading" name="person" />
<Text slot="label">Sandra Adams</Text>
<Text slot="description">Disabled and selected</Text>
</ListItem>
<ListItem id="trevor" textValue="Trevor Hansen">
<Icon slot="leading" name="person" />
<Text slot="label">Trevor Hansen</Text>
<Text slot="description">Disabled</Text>
</ListItem>
</List>
)
}Dividers
Set hasDivider to show a divider between the items. Limit dividers to uncontained lists.
import { List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Dividers() {
return (
<List aria-label="Contacts" hasDivider className="w-90">
<ListItem id="ali" textValue="Ali Connors">
<Text slot="label">Ali Connors</Text>
<Text slot="description">Brunch this weekend?</Text>
</ListItem>
<ListItem id="sandra" textValue="Sandra Adams">
<Text slot="label">Sandra Adams</Text>
<Text slot="description">Oui oui</Text>
</ListItem>
<ListItem id="trevor" textValue="Trevor Hansen">
<Text slot="label">Trevor Hansen</Text>
<Text slot="description">Birthday gift</Text>
</ListItem>
</List>
)
}Orientation
Set orientation="horizontal" to lay the items out in a row. The up and down arrow keys still move between them.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Horizontal() {
return (
<List
aria-label="Text alignment"
orientation="horizontal"
variant="segmented"
selectionMode="single"
defaultSelectedKeys={['start']}
>
<ListItem id="start" textValue="Start">
<Icon slot="leading" name="format_align_left" />
<Text slot="label">Start</Text>
</ListItem>
<ListItem id="center" textValue="Center">
<Icon slot="leading" name="format_align_center" />
<Text slot="label">Center</Text>
</ListItem>
<ListItem id="end" textValue="End">
<Icon slot="leading" name="format_align_right" />
<Text slot="label">End</Text>
</ListItem>
</List>
)
}Align list items
The parts of an item are centered vertically. In an item with three lines of text, or 88dp tall or more, they are aligned to its top. In this example, the avatar of the second item is at its top, as its supporting text wraps onto a third line.
import { List, ListItem } from '@material-web/react'
import type { ReactNode } from 'react'
import { Text } from 'react-aria-components'
function Avatar({ children }: { children: ReactNode }) {
return (
<span
slot="leading"
aria-hidden
className="grid size-10 place-items-center rounded-full bg-primary-container text-title-md text-on-primary-container"
>
{children}
</span>
)
}
export default function Align() {
return (
<List aria-label="Recent messages" variant="segmented" className="w-90">
<ListItem id="ali" textValue="Ali Connors">
<Avatar>A</Avatar>
<Text slot="label">Ali Connors</Text>
<Text slot="description">Brunch this weekend?</Text>
<Text slot="trailing">15 min</Text>
</ListItem>
<ListItem id="sandra" textValue="Sandra Adams">
<Avatar>S</Avatar>
<Text slot="label">Sandra Adams</Text>
<Text slot="description">
Wish I could come, but I am out of town this weekend and the one after
</Text>
<Text slot="trailing">1 h</Text>
</ListItem>
</List>
)
}An item is at least 56, 72 or 88dp tall, for one, two or three lines of text. An overline or supporting text adds a line to the label, and so does a label or supporting text that wraps. An item also grows with a taller leading part.
In a list that is given a height and scrolls, the items keep their heights.
Gutterless list
An item has 16dp of padding at its sides. In a container that has its own padding, replace it with a padding class on each item, such as px-0.
import { Card, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
const details = [
{ id: 'size', label: 'Size', value: '2.4 MB' },
{ id: 'modified', label: 'Modified', value: 'Nov 6, 2026' },
{ id: 'owner', label: 'Owner', value: 'Ali Connors' },
]
export default function Gutterless() {
return (
<Card variant="filled" className="w-80 px-space-300 py-space-200">
<div className="text-title-md">Details</div>
<List aria-label="File details" items={details}>
{(detail) => (
<ListItem textValue={detail.label} className="bg-transparent px-0">
<Text slot="label">{detail.label}</Text>
<Text slot="trailing">{detail.value}</Text>
</ListItem>
)}
</List>
</Card>
)
}Links
Give a ListItem an href to make it a link, such as <ListItem href="/inbox">. To send these links through a client-side router, wrap the app in RouterProvider from react-aria-components. See Routing.
import { Icon, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'
const pages = [
{ id: 'overview', label: 'Overview', description: 'What lists are for' },
{ id: 'specs', label: 'Specs', description: 'Measurements and tokens' },
{ id: 'guidelines', label: 'Guidelines', description: 'Usage and behavior' },
]
export default function Links() {
return (
<List aria-label="Material Design pages on lists" variant="segmented" className="w-90">
{pages.map((page) => (
<ListItem
key={page.id}
id={page.id}
textValue={page.label}
href={`https://m3.material.io/components/lists/${page.id}`}
target="_blank"
rel="noreferrer"
>
<Icon slot="leading" name="article" />
<Text slot="label">{page.label}</Text>
<Text slot="description">{page.description}</Text>
<Icon slot="trailing" name="open_in_new" />
</ListItem>
))}
</List>
)
}In a list with selection, how a press on a link behaves depends on the selectionBehavior. See React Aria's Links.
List controls
Checkbox
Put a Checkbox in the selection, leading or trailing slot of an item to show and toggle the item's selection. It needs no label. In a list with no selection mode, the checkbox is disabled unless you set isDisabled={false} on it.
import { Checkbox, List, ListItem } from '@material-web/react'
import { useState } from 'react'
import { Text, type Selection } from 'react-aria-components'
const contacts = [
{ id: 'ali', name: 'Ali Connors', message: 'Brunch this weekend?' },
{ id: 'sandra', name: 'Sandra Adams', message: 'Oui oui' },
{ id: 'trevor', name: 'Trevor Hansen', message: 'Birthday gift' },
]
export default function MultiSelect() {
const [selected, setSelected] = useState<Selection>(new Set(['ali']))
return (
<List
aria-label="Contacts to share with"
variant="segmented"
className="w-90"
selectionMode="multiple"
selectedKeys={selected}
onSelectionChange={setSelected}
>
{contacts.map((contact) => (
<ListItem key={contact.id} id={contact.id} textValue={contact.name}>
<Checkbox slot="selection" />
<Text slot="label">{contact.name}</Text>
<Text slot="description">{contact.message}</Text>
</ListItem>
))}
</List>
)
}Switch
A Switch or a Radio in a slot is not tied to the item's selection: give it its own name and state. A Radio still needs a RadioGroup around it.
import { Icon, List, ListItem, Switch } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function Controls() {
return (
<List aria-label="Settings" variant="segmented" className="w-90">
<ListItem id="wifi" textValue="Wi-Fi">
<Icon slot="leading" name="wifi" />
<Text slot="label">Wi-Fi</Text>
<Text slot="description">Home network</Text>
<Switch slot="trailing" aria-label="Wi-Fi" defaultSelected />
</ListItem>
<ListItem id="bluetooth" textValue="Bluetooth">
<Icon slot="leading" name="bluetooth" />
<Text slot="label">Bluetooth</Text>
<Text slot="description">Available devices</Text>
<Switch slot="trailing" aria-label="Bluetooth" />
</ListItem>
</List>
)
}Customization
Pass classes in className to restyle a List or a ListItem. A class of yours replaces the component's own class for the same property. See Styling for the classes, the states and the theme.
- Color: An item has the surface color. On a container of another color, give it
bg-transparent. - States: Style a state of an item with its variant, such as
hover:,pressed:orselected:. See States. - Every list: To restyle all the lists at once, change the theme.
Density
Add density-1, density-2 or density-3 to a list, or to an element around it. Each density step takes 2dp off the top and bottom of an item, down to a height of 48dp.
import { List, ListItem, twMerge } from '@material-web/react'
import { Text } from 'react-aria-components'
const steps = ['', 'density-1', 'density-2', 'density-3']
export default function Density() {
return (
<>
{steps.map((density) => (
<List
key={density}
aria-label={`Contacts, ${density || 'default density'}`}
variant="segmented"
className={twMerge('w-40', density)}
>
<ListItem id="density">{density || 'Default'}</ListItem>
<ListItem id="ali" textValue="Ali Connors">
<Text slot="label">Ali Connors</Text>
<Text slot="description">Brunch?</Text>
</ListItem>
</List>
))}
</>
)
}State
The className, style and children of a ListItem can be functions of its state: isHovered, isPressed, isFocused, isFocusVisible, isFocusVisibleWithin, isSelected, isDisabled, selectionMode, selectionBehavior, allowsDragging, isDragging, isDropTarget, id and state. A render function is given the item's ripple along with the children, so render the children it receives. See Children as a function.
To style by state in your own CSS, target the data attributes:
- The list sets
data-focused,data-focus-visible,data-empty,data-layoutanddata-orientation. - Each item sets
data-hovered,data-pressed,data-focused,data-focus-visible,data-focus-visible-within,data-selected,data-disabled,data-allows-dragging,data-dragginganddata-drop-target, anddata-selection-modein a list with selection.
Use cases
Material lists what people should be able to do with assistive technology:
- Navigate to a list item
- Select a list item
Interaction and style
- States: An item that can be selected or has an action shows a state layer on hover and a ripple on a press. An item that does neither shows neither, as in a non-interactive list. Keyboard focus shows a focus ring inside the item, and a press does not.
- Touch target: Every item is at least 48dp tall, at every density, and each icon button or checkbox in it has a touch target of its own. A press on an icon button does not press the item.
- Color contrast: With the default colors, the text keeps 4.5:1 contrast and the icons 3:1, at rest and selected, in the light and dark schemes at every contrast level.
- Text size: A label or supporting text that wraps adds a line, and the item grows with it. See Align list items.
- Density: Each density step takes 2dp off the top and bottom of an item, which stays at least 48dp tall.
- Motion: With reduced motion, the changes of shape and color are instant, and dragged items move to their new places at once.
- Forced colors: In forced colors, a selected item is filled with the system's highlight color, a disabled item is drawn in the gray text color, and the items of a segmented list keep an edge.
- Selection: A selected item is highlighted, and its icons are filled. Material advises a cue besides color, such as a checkbox or a leading icon: put a
Checkboxin the item'sselection,leadingortrailingslot. See Checkbox.
Focus
- The list is one tab stop. Tab moves the focus to the item focused last. Before any item has been focused, it moves to the first selected item, as Material advises, or to the first item when none is selected; going backward, to the last selected item or the last item. The next Tab leaves the list.
- In an
Autocomplete, the list takes no virtual focus: Tab moves the focus from the bar to the list. See Search.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus into the list, or out of it |
| Up or Down arrow | Move the focus to the previous or next item |
| Left or Right arrow | Move the focus into the buttons and checkboxes of an item, and back to the item |
| Home | Move the focus to the first item |
| End | Move the focus to the last item |
| Space | Select the focused item |
| Enter | Call the action of the focused item |
| Escape | Clear the selection |
- The up and down arrow keys stop at the first and the last item. Typing finds an item by its
textValue. - Set
keyboardNavigationBehavior="tab"to move through the controls of an item with Tab instead. - The left and right arrow keys are reversed in a right-to-left locale, which is set with an
I18nProvider, not withdir. - To drag an item with the keyboard, move the focus to its drag handle with the right arrow key and press Enter. The arrow keys then move the placeholder, Enter drops the item and Escape cancels. See React Aria's drag and drop accessibility.
Labeling elements
- The list is a grid, and each item a row. Name the list with
aria-labeloraria-labelledby. Material advises a name that describes the selection people can make, such as Select either bread, pita, or rice. - An item is named by its
textValuefollowed by its supporting text. Material advises a name that matches the label text and the supporting text, so give the item atextValuewith the text of its label. - In a list with selection, an item reports whether it is selected with
aria-selected, and a list with multiple selection isaria-multiselectable. A disabled item reportsaria-disabled. - A
Checkboxin theselection,leadingortrailingslot needs no label: it is named after its item. Give each icon button in an item anaria-label. See Icon button.
List
variant'standard' | 'segmented'Default'standard'Choose between standard and segmented styles
The standard and segmented styles are a visual choice, and don’t affect a list’s behavior.
An expressive list has a segmented style and round corners
Use gaps for contained lists. Gaps leverage expressive shape and containment tactics.
Use segmented gaps and filled list items to define a list group
hasDividerbooleanDefaultfalseGaps or dividers can separate lists into items and groups
Limit dividers to uncontained or complex lists, only when a stronger visual separation is necessary.
Limit the use of dividers to uncontained lists
Props of List (32)
classNameClassNameOrFunction<GridListRenderProps>Default'react-aria-GridList'The CSS className for the element. A function may be provided to compute the class based on component state.
disallowTypeAheadbooleanDefaultfalseWhether typeahead navigation is disabled.
selectionBehavior'toggle' | 'replace'Default'toggle'How multiple selection should behave in the collection.
dragAndDropHooksDragAndDropHooks<NoInfer<T>>The drag and drop hooks returned by
useDragAndDropused to enable drag and drop behavior for the GridList.renderEmptyState(props: GridListRenderProps) => ReactNodeProvides content to display when there are no items in the list.
layout'grid' | 'stack'Default'stack'Whether the items are arranged in a stack or grid.
orientation'horizontal' | 'vertical'Default'vertical'The primary orientation of the items. Usually this is the direction that the collection scrolls.
UNSTABLE_focusOnEntry'first' | 'last'Which item in the collection to focus when tabbing into the collection. Overrides default roving tab index like behavior.
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
autoFocus'first' | 'last' | booleanWhether to auto focus the gridlist or an option.
selectionMode'none' | 'single' | 'multiple'The type of selection that is allowed in the collection.
itemsIterable<T>Item objects in the collection.
escapeKeyBehavior'none' | 'clearSelection'Default'clearSelection'Whether pressing the escape key should clear selection in the grid list or not.
Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.
onAction(key: Key) => voidHandler that is called when a user performs an action on an item. The exact user event depends on the collection's
selectionBehaviorprop and the interaction modality.shouldSelectOnPressUpbooleanWhether selection should occur on press up instead of press down.
disabledKeysIterable<Key>The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
disallowEmptySelectionbooleanWhether the collection allows empty selection.
selectedKeys'all' | Iterable<Key>The currently selected keys in the collection (controlled).
defaultSelectedKeys'all' | Iterable<Key>The initial selected keys in the collection (uncontrolled).
onSelectionChange(keys: Selection) => voidHandler that is called when the selection changes.
keyboardNavigationBehavior'tab' | 'arrow'Default'arrow'Whether keyboard navigation to focusable elements within grid list items is via the left/right arrow keys or the tab key.
disabledBehavior'all' | 'selection'Default'all'Whether
disabledKeysapplies to all interactions, or only selection.childrenReactNode | ((item: T) => ReactNode)The contents of the collection.
dependenciesReadonlyArray<any>Values that should invalidate the item cache when using dynamic collections.
styleCSSProperties | (values: GridListRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', GridListRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.refRef<HTMLDivElement>
List also takes the 70 attributes and events of the element it renders.
ListItem
Props of ListItem (29)
classNameClassNameOrFunction<GridListItemRenderProps>Default'react-aria-GridListItem'The CSS className for the element. A function may be provided to compute the class based on component state.
idKeyThe unique id of the item.
valueobjectThe object value that this item represents. When using dynamic collections, this is set automatically.
textValuestringA string representation of the item's contents, used for features like typeahead.
isDisabledbooleanWhether the item is disabled.
onAction() => voidHandler that is called when a user performs an action on the item. The exact user event depends on the collection's
selectionBehaviorprop and the interaction modality.focusMode'row' | 'child'Whether the row or its first focusable child element should be focused when navigating to the row. Defaults to 'row'.
allowsArrowNavigationbooleanWhether the row should support arrow key navigation even when the containing collection uses tab keyboard navigation. Allows users to navigate between rows with arrow keys while focus is on an interactive child element within the row.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: GridListItemRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', GridListItemRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
hrefHrefA URL to link to. See MDN.
hrefLangstringHints at the human language of the linked URL. SeeMDN.
targetHTMLAttributeAnchorTargetThe target window for the link. See MDN.
relstringThe relationship between the linked resource and the current page. See MDN.
downloadboolean | stringCauses the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
pingstringA space-separated list of URLs to ping when the link is followed. See MDN.
referrerPolicy'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'How much of the referrer to send when following the link. See MDN.
routerOptionsOptions for the configured client side router.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.refRef<HTMLDivElement>
ListItem also takes the 69 attributes and events of the element it renders.