List
A list component for displaying structured data with items, actions, and keyboard navigation
Installation
Terminal
Import
Component.tsx
Basic
A basic list with simple text items.
Use the `List` component with `List.Content` and `List.Item` for a simple list.
With Icons
A list with icon prefixes for each item.
Use the `prefixElement` prop to add icons or other elements at the beginning of list items.
Variant
A list with primary variant.
Use the `variant` prop to make the list items primary.
```tsx
<List variant="primary">...</List>
```
With Labels And Dividers
A list with sections and dividers.
Use `List.Label` to add section titles and `List.Divider` to separate sections.
```tsx
<List>
<List.Label>Navigation</List.Label>
<List.Content>...</List.Content>
<List.Divider />
<List.Label>System</List.Label>
<List.Content>...</List.Content>
</List>
```
Nested List
A list with collapsible nested items.
Use `List.SubTrigger` to create a collapsible section and `parentId` on nested content to link them together.
```tsx
<List>
<List.Content>
<List.Item>
<List.Value>Home</List.Value>
</List.Item>
<List.SubTrigger id="docs">
<List.Value>Documents</List.Value>
</List.SubTrigger>
<List.Content parentId="docs">...</List.Content>
<List.Item>
<List.Value>Calendar</List.Value>
</List.Item>
</List.Content>
</List>
```
Size
A list with large size.
Use the `size` prop to make the list items large.
```tsx
<List size="large">...</List>
```
Default Open Nested List
A list with pre-expanded nested content.
Use the `defaultOpen` prop on `List.SubTrigger` to make nested content visible by default.
```tsx
<List>
<List.Content>
<List.Item>
<List.Value>Home</List.Value>
</List.Item>
<List.SubTrigger id="docs" defaultOpen>
<List.Value>Documents</List.Value>
</List.SubTrigger>
<List.Content parentId="docs">...</List.Content>
<List.Item>
<List.Value>Calendar</List.Value>
</List.Item>
</List.Content>
</List>
```
With Reference Lines
A list with indentation reference lines for better visualization of the nesting structure.
Use the `shouldShowReferenceLine` prop on the List component to display vertical reference lines that help
visualize the hierarchical structure.
With Shortcuts
A list with keyboard shortcut hints.
Use the `shortcut` prop to display keyboard shortcuts next to list items.
```tsx
<List>
<List.Content>
<List.Item shortcut={{ keys: "H" }}>
<List.Value>Home</List.Value>
</List.Item>
<List.Item shortcut={{ keys: "D" }}>
<List.Value>Documents</List.Value>
</List.Item>
<List.Item shortcut={{ modifier: "command", keys: "," }}>
<List.Value>Settings</List.Value>
</List.Item>
</List.Content>
</List>
```
With Selection Enabled
A list with selection functionality.
Use the `selection` prop on the List component to enable selection functionality. This example
demonstrates radio-like behavior (single selection) with ability to deselect.
NOTE: This example uses a custom implementation to override the component's internal selection state.
Selected item: doc1
With Disabled Items
A list with disabled items.
Use the `disabled` prop to make items non-interactive.
```tsx
<List>
<List.Content>
<List.Item disabled>
<List.Value>Mail (Maintenance)</List.Value>
</List.Item>
</List.Content>
</List>
```
Non Collapsible Nested List
A nested list with non-collapsible sub-sections.
Use the `disableCollapse` prop on `List.SubTrigger` to prevent toggling of the sub-list.
```tsx
<List>
<List.Content>
<List.SubTrigger id="docs" defaultOpen disableCollapse>
<List.Value>Documents</List.Value>
</List.SubTrigger>
<List.Content parentId="docs">...</List.Content>
</List.Content>
</List>
```
Multi Level Nested List
A list with multiple levels of nesting.
You can create deeply nested structures by using multiple layers of `List.SubTrigger` and `List.Content` with appropriate `parentId` props.
Nested List With Selection
A nested list with selection functionality.
Combine the selection mode with nested lists to create hierarchical selectable content.
Selected items: root1nested2
With As Prop
WithAsProp: Demonstrates using the `as` prop to render List.Content and List.Item as different HTML elements.
Use cases:
- `List.Content as="ul"` with `List.Item as="li"` for semantic HTML lists
- `List as="nav"` for navigation wrapper
- Custom elements for specific use cases
Note: For proper HTML structure, use `as` on `List.Content` for list containers (ul/ol),
not on the `List` root which serves as the outer wrapper.
```tsx
<List>
<List.Content as="ul">
<List.Item as="li">Item 1</List.Item>
<List.Item as="li">Item 2</List.Item>
</List.Content>
</List>
```
Non Interactive
NonInteractive: Demonstrates a non-interactive list for display purposes only.
- When `interactive={false}`, list items use `div` as default element instead of `button`.
- Hover effects and active states are disabled.
- Useful for read-only lists, documentation, or static content display.
```tsx
<List interactive={false}>
<List.Content>...</List.Content>
</List>
```
API reference
| ListBase | Type | Default |
|---|---|---|
size | undefined |"default" |"large" | - |
as | ElementType<any, keyof IntrinsicElements> |undefined | - |
interactive | boolean |undefined | - |
selection | boolean |undefined | - |
shouldShowReferenceLine | boolean |undefined | - |
variant | undefined |"default" |"primary" | - |
| ListContentProps | Type | Default |
as | ElementType<any, keyof IntrinsicElements> |undefined | - |
parentId | string |undefined | - |
| ListItemProps | Type | Default |
active | boolean |undefined | - |
as | ElementType<any, keyof IntrinsicElements> |undefined | - |
classNames | { icon?: string |undefined; root?: string |undefined; shortcut?: string |undefined; } |undefined | - |
disabled | boolean |undefined | - |
href | string |undefined | - |
id | string |undefined | - |
parentId | string |undefined | - |
prefixElement | ReactNode | - |
selected | boolean |undefined | - |
shortcut | { keys?: ReactNode; modifier?: KbdKey |KbdKey[] |undefined; } |undefined | - |
suffixElement | ReactNode | - |
target | string |undefined | - |
rel | string |undefined | - |
ref | ((instance: HTMLElement |null) => void) |RefObject<HTMLElement> |null |undefined | - |
| ListSubTriggerProps | Type | Default |
active | boolean |undefined | - |
classNames | { chevron?: string |undefined; icon?: string |undefined; root?: string |undefined; } |undefined | - |
defaultOpen | boolean |undefined | - |
disableCollapse | boolean |undefined | - |
disabled | boolean |undefined | - |
id | string |undefined | - |
parentId | string |undefined | - |
prefixElement | ReactNode |((isOpen: boolean) => ReactNode) | - |
suffixElement | ReactNode |((isOpen: boolean) => ReactNode) | - |
ref | ((instance: HTMLButtonElement |null) => void) |RefObject<HTMLButtonElement> |null |undefined | - |