Lists are continuous, vertical indexes of text or images.
The List component is composed of items containing primary and supplemental actions, which are represented by icons and text. Lists are optimized for reading comprehension. A list consists of a single continuous column of subdivisions called rows that contain items of content.
Basic List
A List is a wrapper for multiple ListItem elements which can behave as text, links, or buttons.
<Gridcontainerjustify="center">
<Griditemxs={12}sm={10}md={8}>
<List>
<ListItembutton>
<ListItemTextprimary="Inbox"/>
</ListItem>
<ListItembutton>
<ListItemTextprimary="Drafts"/>
</ListItem>
</List>
<Divider/>
<List>
<ListItembutton>
<ListItemTextprimary="Trash"/>
</ListItem>
</List>
</Grid>
</Grid>
List of Links
In a simple navigational scenario, define ListItems as links be either:
Including a href prop
Including the link prop and passing a custom link component, such as from a routing library
This will allow the a to inherit the ListItem default styling. For more complex design patterns, do not supply the href or link props, and wrap ListItem children with custom components as needed.
<Gridcontainerjustify="center">
<Griditemxs={12}sm={10}md={8}component="nav">
<List>
<ListItemhref="#">
<ListItemTextprimary="Home"/>
</ListItem>
<ListItemhref="#">
<ListItemTextprimary="Products"/>
<List>
<ListItemhref="#"padding={{ left:4}}>
<ListItemTextprimary="Whizbang"/>
</ListItem>
<ListItemhref="#"padding={{ left:4}}>
<ListItemTextprimary="Thingamajig"/>
</ListItem>
</List>
</ListItem>
<ListItemhref="#">
<ListItemTextprimary="Contact Us"/>
</ListItem>
</List>
</Grid>
</Grid>
List with Avatar Icons
This example illustrates using ListItemAvatar and Avatar to contain an icon, the secondaryListItemText prop, and use of selected on ListItem to highlight a current item.
{" — Let's get together and grill some burgers..."}
</>
}
/>
</ListItem>
</List>
Data Lists
The datalist property is a structural variant for <List/> that offers three layouts intended for non-table key/value pairs.
Using datalist limits the allowed <List/> children to only <ListText> and it is expected that both a primary and secondary value are provided, where primary becomes the "key" and secondary becomes the "value".
String content or React elements can be provided to the primary or secondary prop, as is also valid in regular Lists. This allows flexibility in formatting as well as allowing icons or extra actions to be provided. Be aware that adding non-text content may create a need to resolve for any alignment side effects.
Vertical (default)
Keys and values stay in row alignment until the container width is reduced below the computed or supplied datalistBreakpoint and then the value drops below the key into stacked alignment.
Additional Properties
The following are valid only for the vertical layout.
dataKeyWidth
Value: numerical, intended to be max-allowed character width for the key.
If not passed, this is computed by looping through all list items and finding the longest key by character count.
datalistBreakpoint
Value: string, recommended to be set in rem
Determines at what total list width to break the value below the key.
If not passed, this is set to 20rem as default unless the dataKeyWidth is passed or computed to be greater than 16, in which case this is recomputed to allow more space to prevent the value column becoming far too narrow before breaking.
Multi-column layout is applied when the container width allows, switching to stacked layout with similar appearance to vertical within narrow containers/mobile views.