List
Rows for settings, feeds and pickers: a picture on the left, a title and a description, and a value, switch or chevron on the right. A row that does one thing on press is a real button or link that fills it. For records with many fields use a table; for label and value pairs use the data list.
Install
npx shadcn@latest add https://thrumui.dev/r/list.jsonAdds components/ui/list.tsx. Nothing else in your project changes.
import { List } from "@/components/ui/list";Props
| Prop | Type | Default | Description |
|---|---|---|---|
List: dividers | boolean | Default true | A 1 pixel rule between rows. |
List: density | "default" | "compact" | Default "default" | default rows have 12 pixels above and below their text, compact 8. |
List: framed | boolean | Default false | Put the list in a rounded bordered card panel that adapts to frosted glass. |
ListItem: disabled | boolean | Default false | Dims a static row. It is a look only: a plain row has no disabled state to announce. For a row with a button or a link, set disabled on that part instead. |
ListItemButton: selected | boolean | – | Marks the chosen row in a set with a fill, a 2 pixel bar on its start edge and aria-pressed. |
ListItemButton | ComponentProps<"button"> | – | A native button that fills the row. type defaults to button; disabled works as usual. |
ListItemLink: current | boolean | Default false | Marks the row as the current page, with the same fill and bar as a selected button and aria-current="page". |
ListItemLink: disabled | boolean | Default false | Removes the href, so the link cannot be followed, and sets aria-disabled. |
ListItemLink | ComponentProps<"a"> | – | A native link that fills the row. |
ListItemMedia | span props | – | The picture at the start: an avatar, an icon in a tile, a thumbnail. It keeps its size. |
ListItemContent | span props | – | Holds the title and the description, and takes the room left over. |
ListItemTitle | span props | – | The row's name, 14 pixels and medium weight. It wraps. |
ListItemDescription | span props | – | One or more lines under the title in the muted colour. It wraps. |
ListItemTrailing | span props | – | The end of the row: a value, a badge, a switch, a chevron. It never shrinks, so the text wraps before it. |
ListSubheader | li props | – | A small label in the list for the rows below it. |
className | string | – | On every part: extra classes, merged last. |
Motion and sound
Motion
- A pressable row fills with the accent colour over 150 ms on hover. Reduced motion: at once.
- Nothing else moves.
Sound
Silent. This component makes no sound.
Accessibility
- The list is a ul and each row an li, so a screen reader announces the list and how many rows it has.
- A pressable row is one native button or link that fills it: its name is the text inside, read in order, title then description then trailing value.
- A control in the trailing slot needs its own name. Point aria-labelledby at the row's title, as the switch in the example does. Never put a control inside a row button or link.
- Selection shows as a bar on the start edge and a fill, and is announced by aria-pressed or aria-current.
- Long titles and descriptions wrap; the trailing part keeps its width, so the two never overlap. Nothing is cut off at 160 pixels wide.
| Keys | Action |
|---|---|
| Tab | Move between the pressable rows and the controls inside rows. |
| Enter / Space | Press the focused row button, or the switch in a row. Enter follows a row link. |
Source
"use client";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
export type ListDensity = "default" | "compact";
export type ListProps = ComponentProps<"ul"> & {
/** A 1 pixel rule between rows. */
dividers?: boolean;
/** `default` rows are 12 pixels above and below their text, `compact` 8. */
density?: ListDensity;
/** Wrap the list in a rounded bordered panel surface that turns to glass with the page material. */
framed?: boolean;
};
/**
* Rows for settings, feeds and pickers: an optional picture on the left, a title and a description, and something on the
* right (a value, a switch, a chevron). A row that does one thing on press holds a `ListItemButton` or `ListItemLink`
* that fills it. It is a `<ul>`, so a screen reader announces how many rows there are.
*/
export function List({ dividers = true, density = "default", framed = false, className, ...props }: ListProps) {
return (
<ul
data-slot="list"
data-density={density}
data-surface={framed ? "panel" : undefined}
className={cn(
"group/list flex min-w-0 flex-col",
dividers && "divide-y divide-foreground/15",
framed && "rounded-lg border bg-card p-1 text-card-foreground",
className,
)}
{...props}
/>
);
}
/** The parts of a row, laid out in a line: media, content, trailing. Shared by the static row, the button and the link. */
const ROW = "relative flex w-full min-w-0 items-center gap-3 px-3 py-3 text-start group-data-[density=compact]/list:py-2";
export type ListItemProps = ComponentProps<"li"> & {
/** Dims a static row. For a row that holds a button or a link, set `disabled` on that instead. */
disabled?: boolean;
};
/** One row. Put the parts straight inside it, or inside a `ListItemButton` or `ListItemLink` when the whole row is pressable. */
export function ListItem({ disabled = false, className, ...props }: ListItemProps) {
return (
<li
data-slot="list-item"
data-disabled={disabled || undefined}
className={cn(
ROW,
// A row that holds a button or a link hands its padding to it, so the whole row is the target.
"has-[>[data-slot=list-item-button]]:p-0 has-[>[data-slot=list-item-link]]:p-0",
"data-disabled:opacity-65",
className,
)}
{...props}
/>
);
}
const PRESSABLE =
"cursor-pointer rounded-md transition-[background-color] duration-150 ease-out hover:bg-accent hover:text-accent-foreground motion-reduce:transition-none " +
"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring " +
// Selection is a bar on the start edge as well as a fill, so it does not rest on colour.
"data-selected:bg-accent data-selected:text-accent-foreground data-selected:before:absolute data-selected:before:inset-y-2 data-selected:before:start-0 data-selected:before:w-0.5 data-selected:before:bg-primary";
export type ListItemButtonProps = ComponentProps<"button"> & {
/** Marks the row as the chosen one in a set, with a bar on its start edge and `aria-pressed`. */
selected?: boolean;
};
/** A row that does one thing when pressed: open a setting, pick an item. A native button that fills the row. */
export function ListItemButton({ selected, type = "button", className, ...props }: ListItemButtonProps) {
return (
<button
data-slot="list-item-button"
data-selected={selected || undefined}
aria-pressed={selected}
type={type}
className={cn(ROW, PRESSABLE, "disabled:cursor-not-allowed disabled:text-muted-foreground disabled:opacity-70 disabled:hover:bg-transparent", className)}
{...props}
/>
);
}
export type ListItemLinkProps = ComponentProps<"a"> & {
/** Marks the row as the current page, with a bar on its start edge and `aria-current="page"`. */
current?: boolean;
/** A link that cannot be followed: it loses its `href` and says so with `aria-disabled`. */
disabled?: boolean;
};
/** A row that goes somewhere. A native link that fills the row. */
export function ListItemLink({ current = false, disabled = false, href, className, ...props }: ListItemLinkProps) {
return (
<a
data-slot="list-item-link"
data-selected={current || undefined}
aria-current={current ? "page" : undefined}
aria-disabled={disabled || undefined}
href={disabled ? undefined : href}
className={cn(ROW, PRESSABLE, "aria-disabled:cursor-not-allowed aria-disabled:text-muted-foreground aria-disabled:opacity-70 aria-disabled:hover:bg-transparent", className)}
{...props}
/>
);
}
/** The picture at the start of a row: an avatar, an icon in a tile, a thumbnail. It keeps its size when the text wraps. */
export function ListItemMedia({ className, ...props }: ComponentProps<"span">) {
return <span data-slot="list-item-media" className={cn("flex flex-none items-center justify-center", className)} {...props} />;
}
/** The title and description. It takes the room left over and wraps. */
export function ListItemContent({ className, ...props }: ComponentProps<"span">) {
return <span data-slot="list-item-content" className={cn("flex min-w-0 flex-1 flex-col gap-0.5", className)} {...props} />;
}
export function ListItemTitle({ className, ...props }: ComponentProps<"span">) {
return <span data-slot="list-item-title" className={cn("text-sm font-medium wrap-break-word", className)} {...props} />;
}
export function ListItemDescription({ className, ...props }: ComponentProps<"span">) {
return <span data-slot="list-item-description" className={cn("text-sm text-muted-foreground wrap-break-word", className)} {...props} />;
}
/** What sits at the end of a row: a value, a badge, a switch, a chevron. It never shrinks, so the content wraps instead of running under it. */
export function ListItemTrailing({ className, ...props }: ComponentProps<"span">) {
return <span data-slot="list-item-trailing" className={cn("flex flex-none items-center gap-2 text-sm text-muted-foreground tabular-nums", className)} {...props} />;
}
/** A label for the rows below it, inside the list. */
export function ListSubheader({ className, ...props }: ComponentProps<"li">) {
return <li data-slot="list-subheader" className={cn("px-3 pt-4 pb-1 text-xs font-medium text-muted-foreground first:pt-1", className)} {...props} />;
}Files and dependencies
- Adds
components/ui/list.tsx- Packages
- None
- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-03First release.