A list is a continuous, vertical index of text and images: a headline per row, with an overline, supporting text, and leading and trailing content such as an icon, an avatar or a time. Rows are one, two or three lines tall, and can be selected, one at a time or several.
Usage
Each item has an id and a headline. By default a row is a button that selects it, and
choosing another row moves the selection.
import { createList } from 'material';
const list = createList({
ariaLabel: 'Ideas for today',
items: [
{ id: 'walk', headline: 'Morning walk' },
{ id: 'read', headline: 'Read a chapter' },
{ id: 'cook', headline: 'Try a new recipe' },
],
});
document.body.append(list.element);
<m-list aria-label="Ideas for today">
<m-list-item value="walk">Morning walk</m-list-item>
<m-list-item value="read">Read a chapter</m-list-item>
<m-list-item value="cook">Try a new recipe</m-list-item>
</m-list>
import { List, ListItem } from 'material/react';
export function Example() {
return (
<List ariaLabel="Ideas for today">
<ListItem value="walk">Morning walk</ListItem>
<ListItem value="read">Read a chapter</ListItem>
<ListItem value="cook">Try a new recipe</ListItem>
</List>
);
}
<script setup lang="ts">
import { MList, MListItem } from 'material/vue';
</script>
<template>
<MList aria-label="Ideas for today">
<MListItem value="walk">Morning walk</MListItem>
<MListItem value="read">Read a chapter</MListItem>
<MListItem value="cook">Try a new recipe</MListItem>
</MList>
</template>
<script lang="ts">
import { List, ListItem } from 'material/svelte';
</script>
<List ariaLabel="Ideas for today">
<ListItem value="walk">Morning walk</ListItem>
<ListItem value="read">Read a chapter</ListItem>
<ListItem value="cook">Try a new recipe</ListItem>
</List>
import { List, ListItem } from 'material/solid';
export function Example() {
return (
<List ariaLabel="Ideas for today">
<ListItem value="walk">Morning walk</ListItem>
<ListItem value="read">Read a chapter</ListItem>
<ListItem value="cook">Try a new recipe</ListItem>
</List>
);
}
Examples
Anatomy
supportingText and overline make a row two or three lines tall; lines sets it. leading
and trailing are { type, content }: an icon, avatar, image or video leading, and
an icon or text trailing. { kind: 'subheader' } titles a group and { kind: 'divider' }
separates one, inset to line up with the text. trackSelection: false makes the rows
display only.
import { createList } from 'material';
const list = createList({
ariaLabel: 'Places',
trackSelection: false,
items: [
{ kind: 'subheader', headline: 'Places to explore' },
{
id: 'trail',
headline: 'Mountain trail',
supportingText: '5 km loop',
leading: { type: 'icon', content: locationIcon },
trailing: { type: 'text', content: '40 min' },
},
{ kind: 'divider', inset: true },
{
id: 'garden',
headline: 'Botanical garden',
supportingText: 'Open until 6 pm',
leading: { type: 'icon', content: locationIcon },
trailing: { type: 'text', content: '15 min' },
},
],
});
document.body.append(list.element);
<m-list aria-label="Places" selection="none">
<m-list-item kind="subheader">Places to explore</m-list-item>
<m-list-item value="trail" supporting-text="5 km loop" trailing-text="40 min">Mountain trail</m-list-item>
<m-list-item kind="divider" inset></m-list-item>
<m-list-item value="garden" supporting-text="Open until 6 pm" trailing-text="15 min">Botanical garden</m-list-item>
</m-list>
<script type="module">
const list = document.querySelector('m-list');
list.querySelector('m-list-item[value="trail"]').setAttribute('leading-icon', locationIcon);
list.querySelector('m-list-item[value="garden"]').setAttribute('leading-icon', locationIcon);
</script>
import { List, ListItem } from 'material/react';
import { locationIcon } from './app';
export function Example() {
return (
<List ariaLabel="Places" selection="none">
<ListItem kind="subheader">Places to explore</ListItem>
<ListItem value="trail" supportingText="5 km loop" leadingIcon={locationIcon} trailingText="40 min">Mountain trail</ListItem>
<ListItem kind="divider" inset />
<ListItem value="garden" supportingText="Open until 6 pm" leadingIcon={locationIcon} trailingText="15 min">Botanical garden</ListItem>
</List>
);
}
<script setup lang="ts">
import { MList, MListItem } from 'material/vue';
import { locationIcon } from './app';
</script>
<template>
<MList aria-label="Places" selection="none">
<MListItem kind="subheader">Places to explore</MListItem>
<MListItem value="trail" supporting-text="5 km loop" :leading-icon="locationIcon" trailing-text="40 min">Mountain trail</MListItem>
<MListItem kind="divider" inset />
<MListItem value="garden" supporting-text="Open until 6 pm" :leading-icon="locationIcon" trailing-text="15 min">Botanical garden</MListItem>
</MList>
</template>
<script lang="ts">
import { List, ListItem } from 'material/svelte';
import { locationIcon } from './app';
</script>
<List ariaLabel="Places" selection="none">
<ListItem kind="subheader">Places to explore</ListItem>
<ListItem value="trail" supportingText="5 km loop" leadingIcon={locationIcon} trailingText="40 min">Mountain trail</ListItem>
<ListItem kind="divider" inset />
<ListItem value="garden" supportingText="Open until 6 pm" leadingIcon={locationIcon} trailingText="15 min">Botanical garden</ListItem>
</List>
import { List, ListItem } from 'material/solid';
import { locationIcon } from './app';
export function Example() {
return (
<List ariaLabel="Places" selection="none">
<ListItem kind="subheader">Places to explore</ListItem>
<ListItem value="trail" supportingText="5 km loop" leadingIcon={locationIcon} trailingText="40 min">Mountain trail</ListItem>
<ListItem kind="divider" inset />
<ListItem value="garden" supportingText="Open until 6 pm" leadingIcon={locationIcon} trailingText="15 min">Botanical garden</ListItem>
</List>
);
}
Several selected
multiSelect lets rows be selected together, and initialSelection (or an item's
selected) sets the rows that start selected. A disabled row cannot be selected or focused.
import { createList } from 'material';
const list = createList({
ariaLabel: 'Countries',
multiSelect: true,
initialSelection: ['fr', 'jp'],
items: [
{ id: 'fr', headline: 'France' },
{ id: 'de', headline: 'Germany', disabled: true },
{ id: 'jp', headline: 'Japan' },
],
});
document.body.append(list.element);
<m-list aria-label="Countries" selection="multiple">
<m-list-item value="fr" selected>France</m-list-item>
<m-list-item value="de" disabled>Germany</m-list-item>
<m-list-item value="jp" selected>Japan</m-list-item>
</m-list>
import { List, ListItem } from 'material/react';
export function Example() {
return (
<List ariaLabel="Countries" selection="multiple">
<ListItem value="fr" selected>France</ListItem>
<ListItem value="de" disabled>Germany</ListItem>
<ListItem value="jp" selected>Japan</ListItem>
</List>
);
}
<script setup lang="ts">
import { MList, MListItem } from 'material/vue';
</script>
<template>
<MList aria-label="Countries" selection="multiple">
<MListItem value="fr" selected>France</MListItem>
<MListItem value="de" disabled>Germany</MListItem>
<MListItem value="jp" selected>Japan</MListItem>
</MList>
</template>
<script lang="ts">
import { List, ListItem } from 'material/svelte';
</script>
<List ariaLabel="Countries" selection="multiple">
<ListItem value="fr" selected>France</ListItem>
<ListItem value="de" disabled>Germany</ListItem>
<ListItem value="jp" selected>Japan</ListItem>
</List>
import { List, ListItem } from 'material/solid';
export function Example() {
return (
<List ariaLabel="Countries" selection="multiple">
<ListItem value="fr" selected>France</ListItem>
<ListItem value="de" disabled>Germany</ListItem>
<ListItem value="jp" selected>Japan</ListItem>
</List>
);
}
A choice emits select with { item, value, element, action, originalEvent, component, preventDefault, defaultPrevented } before the selection moves;
preventDefault() leaves it where it was. Choosing the selected row again deselects it. The
web component dispatches activate with { value }, then change with { value, values }
when the selection moved. A trailing control or custom slot holds the app's own control; a
component instance — anything with an element, such as createSwitch({}) — contributes its
element. A control with no accessible name of its own takes the row's headline as its name and
the supporting text as its description; a name the app gave always wins. With trackSelection,
a checkable control is the row's action too: a click on the row reaches it, and the row's
selected state follows the control's. A non-checkable trailing control stays independent, and a
click on it does not select the row. A trailing control is sized by its content; a
control that fills its container, such as a slider, is not a list-row control and goes
outside the row. renderItem(item, index) renders a row the app's
way. The list renders every item; for long or remote data, use
vlist.
Single-select listbox (withSingleSelectListbox)
For a list where the user picks one option with the WAI-ARIA single-select listbox pattern
(rather than action rows or multi-select checkboxes), wrap a trackSelection: true, multiSelect: false
list with withSingleSelectListbox from material/components/list:
import { createList, withSingleSelectListbox } from 'material/components/list';
const list = withSingleSelectListbox(
createList({
ariaLabel: 'Billing cycle',
trackSelection: true,
multiSelect: false,
initialSelection: ['annual'],
items: [
{ id: 'monthly', headline: 'Monthly', supportingText: '$12 / month' },
{ id: 'annual', headline: 'Annual', supportingText: '$10 / month, billed yearly' },
],
}),
{ indicator: 'leading' }, // 'leading' (default) | 'trailing' — places an inert radio indicator
);
- Accessibility (
role="listbox"/role="option"): Setsrole="listbox"on the list,role="option"witharia-selected="true" | "false"on each selectable row, and a single rovingtabindex="0"stop on the selected (or first enabled) option. - Manual activation:
ArrowDown,ArrowRight,ArrowUp,ArrowLeft,Home,End, and printable-character typeahead move focus across enabled options and update the rovingtabindex="0"while focus is inside the listbox (onfocusout,tabindex="0"syncs back to the selected option);Space,Enter, or a pointer click activates and selects the option (settingaria-selected="true"and firingselect). - Constraints: Refuses
multiSelect: true, rows with interactive secondary actions, and link rows (href). Pages that do not importwithSingleSelectListboxpay0 B.
For a lean standalone popup rather than a list in the page, the opt-in
material/components/listbox entry (with material/styles/listbox) provides a synchronous
single-selection popup following the APG select-only combobox pattern: flat text options,
separate active and committed state, keyboard and typeahead interaction, disabled options and
top-layer placement. Import is SSR-safe; construction is client-only.
API
Options
itemsThe rows, subheaders and dividers
ListItem[][]renderItemRenders a row's content
(item, index) => HTMLElementtrackSelectionRows are buttons that select; false, display only
booleantruemultiSelectSeveral rows selected at once
booleanfalseinitialSelectionThe ids selected at creation
(string | number)[]undefinedariaLabelThe list's accessible name
stringundefinedanimateWhether scrollToItem() and scrollToIndex() scroll smoothly by default
booleanfalseclassAdditional CSS classes
stringundefinedprefixPrefix for CSS class names
string'mtrl'componentNameComponent name used in class generation
string'list'Items
kindA row by default
'item' | 'subheader' | 'divider'idThe row's id; its index without one
string | numberheadlineThe row's text; text, title or name stand in for it
stringoverline / supportingTextThe line above and the lines below the headline
stringlinesThe row's height; inferred from the text without it
1 | 2 | 3leading{ type: 'icon' | 'avatar' | 'image' | 'video' | 'text' | 'control' | 'custom', content }. A component instance — anything with an element, such as createSwitch({}) — contributes its element
ListSlottrailingThe same, at the end. A control with no accessible name of its own takes the row's headline as its name and the supporting text as its description; a name the app gave always wins. With trackSelection, a checkable control is the row's action too: a click on the row reaches it, and the row's selected state follows the control's
ListSlotselected / disabledSelected at creation; not selectable
booleaninsetA divider lined up with the text
booleanMethods
getSelectedItems() / getSelectedItemIds()The selection
ListItem[] / string[]isItemSelected(id)Whether a row is selected
booleanselectItem(id) / deselectItem(id)Adds a row to the selection, or removes it
ListComponentsetSelection(ids) / clearSelection()Replaces or clears the selection
ListComponentrefresh()Renders the items again, from the array the list holds
Promise<ListComponent>getAllItems() / getVisibleItems()The items, all of them in both cases
ListItem[]scrollToItem(id, position?, animate?)Scrolls a row into view: 'start', 'center' or 'end'
ListComponentscrollToIndex(index, position?, animate?)The same, by index
Promise<ListComponent>isLoading() / hasNextPage()Always false
booleanon(event, handler) / off(event, handler)Events
ListComponentdestroy()Removes the list and its listeners
voidEvents
selectA row was chosen, before the selection moves
{ item, value, element, action, originalEvent, component, preventDefault, defaultPrevented }loadThe items were rendered, at creation and on refresh()
{ items, loading, hasNext, hasPrev, component }scrollThe list scrolled
{ event, element, originalEvent }element is always the row; action is the row's primary button, the node that carried the
activation.
Styling
A selected row has the secondary-container color and 16dp corners.
.mtrl-list { }
.mtrl-list__content, .mtrl-list__subheader, .mtrl-list__divider, .mtrl-list__divider--inset, .mtrl-list__empty { }
.mtrl-list__item, .mtrl-list__item--two-line, .mtrl-list__item--three-line { }
.mtrl-list__item--selected, .mtrl-list__item--disabled, .mtrl-list__action { }
.mtrl-list__text, .mtrl-list__overline, .mtrl-list__headline, .mtrl-list__supporting { }
.mtrl-list__leading, .mtrl-list__leading--icon, .mtrl-list__leading--avatar, .mtrl-list__leading--image, .mtrl-list__leading--video { }
.mtrl-list__trailing, .mtrl-list__trailing--icon, .mtrl-list__trailing--text { }
Measurements
From Compose's ListItem and ListTokens:
| Attribute | Value |
|---|---|
| Row | 56dp one line, 72dp two, 88dp three; 16dp between its parts |
| Padding | 8dp top and bottom (12dp for three lines), 16dp at the sides |
| Text | Headline Body Large on-surface; overline Label Small and supporting text Body Medium, on-surface-variant |
| Leading | Icon 24dp; avatar 40dp; image 56dp; video 100 × 56dp (114 × 64dp in three lines) |
| Trailing text | Label Small |
| Subheader | Label Large, on-surface-variant |
| Divider | 1dp outline-variant; inset 72dp from the start and 16dp from the end |
| Focus | A 2dp secondary ring inside the row |