Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

List

FreeNew

Rows of records with leading, title, description and trailing slots, clickable across the row, in divided or card style with sticky group headings.

Installation

pnpm dlx shadcn@latest add @viewport/list

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

list-demo.tsx
import { Ellipsis } from "lucide-react";
import { Avatar } from "@/components/viewport/avatar";
import { Badge } from "@/components/viewport/badge";
import { List, ListGroup, ListItem } from "@/components/viewport/list";

const groups = [
  { letter: "C", people: [{ name: "Inés Carvalho", role: "Account Executive, Globex", tag: "Customer" }] },
  { letter: "L", people: [{ name: "Mara Lindqvist", role: "Head of Revenue, Northwind", tag: "Champion" }] },
  {
    letter: "O",
    people: [
      { name: "Theo Okafor", role: "Procurement Lead, Initech", tag: "Lead" },
      { name: "Adaeze Okonkwo", role: "CFO, Umbrella Health", tag: "Customer" },
    ],
  },
  { letter: "R", people: [{ name: "Priya Raman", role: "VP Operations, Hooli", tag: "Lead" }] },
  { letter: "W", people: [{ name: "Kenji Watanabe", role: "IT Director, Northgate Foods", tag: "Customer" }] },
];

export default function ListDemo() {
  return (
    <div className="h-80 w-full max-w-md overflow-y-auto rounded-2xl border border-border bg-card [--list-heading:var(--card)]">
      {groups.map((group) => (
        <ListGroup key={group.letter} title={group.letter} trailing={<span className="tabular-nums">{group.people.length}</span>}>
          <List>
            {group.people.map((person) => (
              <ListItem
                key={person.name}
                href={`#${person.name.toLowerCase().replace(/\s+/g, "-")}`}
                leading={<Avatar name={person.name} size="sm" />}
                title={person.name}
                description={person.role}
                trailing={
                  <>
                    <Badge size="sm" tone={person.tag === "Champion" ? "success" : person.tag === "Lead" ? "info" : "neutral"}>
                      {person.tag}
                    </Badge>
                    <button
                      type="button"
                      aria-label={`More actions for ${person.name}`}
                      className="grid size-7 cursor-pointer place-items-center rounded-md outline-none transition-colors hover:bg-foreground/[0.08] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
                    >
                      <Ellipsis className="size-4" aria-hidden />
                    </button>
                  </>
                }
              />
            ))}
          </List>
        </ListGroup>
      ))}
    </div>
  );
}

Props

<List>

PropTypeDefault
variant"divided" | "separated" | "plain"

`divided` draws hairlines between rows; `separated` gives each row its own card; `plain` draws nothing.

"divided"

<ListItem>

PropTypeDefault
leadingReact.ReactNode

An avatar, an icon or a checkbox at the start of the row.

—
title*React.ReactNode—
descriptionReact.ReactNode

A second, muted line.

—
trailingReact.ReactNode

A value, a badge or buttons at the end of the row.

—
hrefstring

Makes the row a link. The link is the title, stretched over the row.

—
onClick() => void

Makes the row a button.

—
currentboolean

Marks the row as the one currently open, e.g. in a master-detail layout.

—

<ListGroup>

PropTypeDefault
title*React.ReactNode

The group's heading, e.g. a letter or a date.

—
stickyboolean

Keep the heading in view while its rows scroll past.

true
trailingReact.ReactNode

A count or an action at the end of the heading.

—

Accessibility

  • The row's link is its title, stretched over the row, so it has one clear name.
  • Controls in the trailing slot stay separately focusable and clickable.
  • Groups are sections with real headings.
  • Server component with no client JavaScript.