Item
updatedYou've built this row a hundred times. Here's the last one. A row of media, title, description and actions, in five variants and five sizes.
Open Props in the corner of the example to try variant and size. The variants are Input's: ghost (default) is transparent, outline a border, soft a fill, subtle a fill and a border, filled a fill with a line underneath, and switching never moves the content. size goes from xs to xl and sets the row's density: padding, gap and media. Text keeps its size, so a compact row still reads at body size, and a text-body-sm of your own on a part is just a class. The media box follows --item-media on the root, and a size-* class on an ItemMedia wins over it.
Installation
Usage
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from '@/components/ui/item'
</script>
<template>
<Item variant="outline">
<ItemContent>
<ItemTitle>Two-step sign-in</ItemTitle>
<ItemDescription>Ask for a code from your phone as well as your password.</ItemDescription>
</ItemContent>
<ItemActions>
<Button variant="outline" color="neutral" size="sm">Turn on</Button>
</ItemActions>
</Item>
</template>
ItemMedia: an icon, image or avatar at the startItemContent: holdsItemTitleandItemDescription, takes the free spaceItemActions: controls at the endItemHeader,ItemFooter: full-width rows above and below
Long text stays in its column. The description keeps two lines by default. A title is a flex row, so an icon or a badge can sit beside its text; to cut a long title with an ellipsis put line-clamp-1 on ItemTitle, or wrap the text in a <span class="truncate">. A plain truncate on the title clips without the ellipsis.
Examples
Media
variant="icon" puts an icon on a muted square, and variant="image" crops an image to a square. With a description, the media lines up with the title instead of the middle of the row.
Group
ItemGroup stacks items, and ItemSeparator divides them.
Links
With as-child, the whole row becomes your link, with hover and press feedback. as="button" does the same for actions.
Header and footer
API Reference
Item
class is also accepted on every part and merged over its classes with tailwind-merge.
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging the item's attributes and classes onto it — a link, for instance. |
| as | "div" | AsTag | ComponentThe element or component to render. |
| variant | "ghost" | NonNullable<"ghost" | "outline" | "soft" | "filled" | "subtle" | null | undefined>Surface of the row, Select's set: |
| size | "md" | ItemSizePadding, gap, radius, text and media size, from |
| Slot | Scope and description |
|---|---|
| default | {}Media, content, actions, and a header or footer that take the full width. |
ItemMedia
| Prop | Default | Type and description |
|---|---|---|
| variant | "default" | NonNullable<"default" | "icon" | "image" | null | undefined>
|
| Slot | Scope and description |
|---|---|
| default | {}An icon, an image or an avatar. |
ItemActions
| Slot | Scope and description |
|---|---|
| default | {}Buttons and controls at the row's end. |
ItemContent
| Slot | Scope and description |
|---|---|
| default | {}The title and description. |
ItemDescription
| Slot | Scope and description |
|---|---|
| default | {}Secondary text, two lines at most. |
ItemFooter
| Slot | Scope and description |
|---|---|
| default | {}A full-width row under the content. |
ItemGroup
| Slot | Scope and description |
|---|---|
| default | {}Items and separators. The group is a list, and its items list items; pass |
ItemHeader
| Slot | Scope and description |
|---|---|
| default | {}A full-width row above the content. |
ItemSeparator
No props, events, slots or exposed members.
ItemTitle
| Slot | Scope and description |
|---|---|
| default | {}The row's title. |
class is also accepted on every part and merged over its classes with tailwind-merge.
Props
- asChild
booleanRender the single child instead of a wrapper, merging the item's attributes and classes onto it — a link, for instance.- as
"div" AsTag | ComponentThe element or component to render.aorbuttonmakes the whole row pressable, with a state layer.- variant
"ghost" NonNullable<"ghost" | "outline" | "soft" | "filled" | "subtle" | null | undefined>Surface of the row, Select's set:outline,soft,filled,ghostandsubtle.- size
"md" ItemSizePadding, gap, radius, text and media size, fromxstoxl.
Slots
- default
{}Media, content, actions, and a header or footer that take the full width.
Props
- variant
"default" NonNullable<"default" | "icon" | "image" | null | undefined>iconframes an icon on a muted square,imagecrops an image to a square; both follow the item's size.
Slots
- default
{}An icon, an image or an avatar.
Slots
- default
{}Buttons and controls at the row's end.
Slots
- default
{}The title and description.
Slots
- default
{}Secondary text, two lines at most.
Slots
- default
{}A full-width row under the content.
Slots
- default
{}Items and separators. The group is a list, and its items list items; passrole="group"for rows that are links or buttons.
Slots
- default
{}A full-width row above the content.
Slots
- default
{}The row's title.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| item | data-variant, data-size | The row. |
| item-group | — | A list of items. |
| item-separator | — | A line between two items. |
| item-media | data-variant | An icon, image or avatar at the start. |
| item-content | — | The title and description. |
| item-title | — | The title. |
| item-description | — | Secondary text, clamped to two lines. |
| item-actions | — | Controls at the end. |
| item-header | — | A full-width row above. |
| item-footer | — | A full-width row below. |
Accessibility
ItemGroup is a list, and its items are list items. Rows that are links or buttons can't be list items, so give their ItemGroup role="group" and an aria-label, as in the links example.