Lists
Lists are continuous, vertical indexes of text or images.
Introduction
Joy UI provides four list-related components:
List
: A wrapper for list items (defaulting asul
).ListItem
: A common list item (default asli
).ListItemButton
: Ans action element to be used inside a list item.ListItemDecorator
: A decorator of a list item, usually used to display an icon.ListItemContent
: A container inside a list item, used to display text content.ListDivider
: A separator between list items.
- Home
<ListItemButton selected />
Playground
Color
Component
After installation, you can start building with this component using the following basic elements:
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
export default function MyApp() {
return (
<List aria-labelledby="basic-list-demo">
<ListItem>Hello, world!</ListItem>
<ListItem>Bye bye, world!</ListItem>
</List>
);
}
Basic usage
Use the List
and ListItem
components to create a basic, non-interactive, list.
Make sure to use a meaningful name that describe the content of the list in the aria-labelledby
prop.
- 1 red onion
- 2 red peppers
- 120g bacon
size="sm"
- Home
- Projects
- Settings
size="md"
- Home
- Projects
- Settings
size="lg"
- Home
- Projects
- Settings
Decorator
Use the ListItemDecorator
component to add supporting icons or elements to the list item.
It comes with a minimum set width that you can adjust via the --List-decorator-width
CSS variable within the List
component.
- 🧅 1 red onion
- 🍤 2 Shrimps
- 🥓 120g bacon
Ellipsis content
When dealing with long content, use the ListItemComponent
together with <Typography noWrap>
to show ellipsis.
Brunch this weekend?
I'll be in your neighborhood doing errands this Tuesday.
Summer BBQ
Wish I could come, but I'm out of town this Friday.
Divider
The ListDivider
component comes with four inset
patterns:
- Default (without providing the
inset
prop): stretches from edge to edge of the list. inset="gutter"
: from the start of the decorator to the end of the content.inset="startDecorator"
: from the start of the decorator to the end of the list.inset="startContent"
: from the start of the content to the end of the list.
(default)
- Mabel Boyle
- Boyd Burt
inset="gutter"
- Mabel Boyle
- Boyd Burt
inset="startDecorator"
- Mabel Boyle
- Boyd Burt
inset="startContent"
- Mabel Boyle
- Boyd Burt
Sticky item
To have a sticky list item, use a List
as a child of the Sheet
component.
Then, on the item you wish to stick, add the sticky
prop.
The Sheet
component automatically adjusts the sticky
list item to have the same background so that the content does not overflow when scroll.
It works by default on both light and dark modes.
- Category 1
- Subitem 1
- Subitem 2
- Subitem 3
- Subitem 4
- Subitem 5
- Subitem 6
- Subitem 7
- Subitem 8
- Subitem 9
- Subitem 10
- Category 2
- Subitem 1
- Subitem 2
- Subitem 3
- Subitem 4
- Subitem 5
- Subitem 6
- Subitem 7
- Subitem 8
- Subitem 9
- Subitem 10
- Category 3
- Subitem 1
- Subitem 2
- Subitem 3
- Subitem 4
- Subitem 5
- Subitem 6
- Subitem 7
- Subitem 8
- Subitem 9
- Subitem 10
- Category 4
- Subitem 1
- Subitem 2
- Subitem 3
- Subitem 4
- Subitem 5
- Subitem 6
- Subitem 7
- Subitem 8
- Subitem 9
- Subitem 10
- Category 5
- Subitem 1
- Subitem 2
- Subitem 3
- Subitem 4
- Subitem 5
- Subitem 6
- Subitem 7
- Subitem 8
- Subitem 9
- Subitem 10
Nested list
Use the nested
prop, within the ListItem
component, to create a nested list.
Note that layout and spacing of the nested list remain intact, as if it isn't nested.
The nested list inherits the list size
and a few other CSS variables, such as --List-radius
and --List-item-radius
from the root List
component to adjust the design consistently.
Toggle small nested list
- Category 1
- Subitem 1
- Subitem 2
- Category 2
- Subitem 1
- Subitem 2
Changing the semantic element
To control which HTML tag should be rendered in a given, one-off, situation, use the component
prop.
<List component="ol">
Non-list
In the example below, we're rendering a List
as a HTML <nav>
element.
- Clickable item
- Open a new tab
Secondary action
To add a secondary action to the ListItemButton
, wrap it in a ListItem
component and then add the desired start or end action elements to it.
- Item 1
- Item 2
The ListItemButton
and the secondary action render as siblings, that way, the semantic rendered element is appropriately adjusted.
<ul> {/* List */}
<li> {/* ListItem */}
<div role="button"> {/* ListItemButton */}
<button> {/* IconButton */}
Selected
Use the selected
prop to signal whether a ListItemButton
is selected or not.
It applies color="primary"
and a few extra styles (e.g. font weight) to visually communicate the selected state.
- Home
- Apps
- Settings
CSS variables
Play around with all the CSS variables available in the list component to see how the design changes.
You can use those to customize the component on both the sx
prop and the theme.
- Home
- Products
Online people
- Mabel Boyle
- Boyd Burt
<List >
CSS Variables
Settings
- MB
Murphy Bates
Apple ID, iCloud, Media & Purchase
- iCloud+ Feature Updates
- Apple TV+ Free Year Available
- Wi-Fi
Mars
- Bluetooth
On
- Cellular
- Inbox
1,950
- Starred
- Categories
- Social
4,320
- Updates
22,252
Collapsible list
Inspired by Gatsby's documentation sidenav.
This example uses the start action (a prop of ListItem
) prop to create a collapsible button.
- Documentation
- Overview
- Quick Start
Tutorial
9How-to Guides
39
Navigation menu
Inspired by the APG Navigation Menubar design pattern. This example uses a combination of horizontal and vertical lists to form the navigation menu bar.
It also supports keyboard navigation, inspired by the Roving UX technique.
- Home
- About
- Admissions