Skip to content
Product block

Expandable Detail Rows

Rows that open into a full-width detail panel via colSpan, with aria-expanded and aria-controls wired to the detail row.

205 lineslucide-reactAdded 8 Aug 2026Updated 10 Sept 2026
  • table
  • expandable
  • accordion
  • detail
  • rows

What's included

  • components/data-table-expandable.tsx
  • Needs lucide-react

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add data-table-expandable

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

ExpandCustomerPlanStatus
Northwind Ltdops@northwind.comTeamActive
Contosobilling@contoso.ioProActive
Initechadmin@initech.devProTrialing

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/data-table-expandable.tsx
'use client'

/**
 * <DataTableExpandable> — rows that open to reveal detail.
 *
 * The alternative to a detail drawer when the extra fields are few enough
 * to read in place. Two things worth copying rather than reinventing:
 *
 *  - The detail lives in its own <tr> with a `colSpan` covering the table,
 *    which is the only way to put a full-width panel inside a table without
 *    breaking column alignment.
 *  - The trigger carries `aria-expanded` and `aria-controls` pointing at
 *    the detail row's id. A chevron that rotates but announces nothing
 *    leaves a screen-reader user unable to tell the row opened.
 *
 * Multiple rows can be open at once — this is for comparing, and an
 * accordion that closes the row you were reading defeats the purpose.
 */

import * as React from 'react'
import { ChevronRight, Mail, Calendar, CreditCard } from 'lucide-react'

export interface ExpandableRow {
  id: string
  name: string
  email: string
  plan: string
  status: string
  joined: string
  lastPayment: string
  notes: string
}

export interface DataTableExpandableProps {
  rows?: ExpandableRow[]
  className?: string
}

const DEFAULT_ROWS: ExpandableRow[] = [
  {
    id: '1',
    name: 'Northwind Ltd',
    email: 'ops@northwind.com',
    plan: 'Team',
    status: 'Active',
    joined: '12 Mar 2024',
    lastPayment: '$490 on 1 Aug 2026',
    notes: 'Migrated from the legacy plan in June. Renewal is annual.',
  },
  {
    id: '2',
    name: 'Contoso',
    email: 'billing@contoso.io',
    plan: 'Pro',
    status: 'Active',
    joined: '3 Jan 2025',
    lastPayment: '$190 on 28 Jul 2026',
    notes: 'Requested SSO — flagged for the Team upgrade conversation.',
  },
  {
    id: '3',
    name: 'Initech',
    email: 'admin@initech.dev',
    plan: 'Pro',
    status: 'Trialing',
    joined: '22 Jul 2026',
    lastPayment: '—',
    notes: 'Trial ends 21 Aug. Two seats active out of five.',
  },
]

export function DataTableExpandable({
  rows = DEFAULT_ROWS,
  className = '',
}: DataTableExpandableProps) {
  const [open, setOpen] = React.useState<Set<string>>(() => new Set())

  function toggle(id: string) {
    setOpen((prev) => {
      const next = new Set(prev)
      if (next.has(id)) next.delete(id)
      else next.add(id)
      return next
    })
  }

  return (
    <div className={`overflow-hidden rounded-2xl border border-border/60 bg-card/60 ${className}`}>
      <div className="relative overflow-x-auto">
        <table className="w-full border-collapse text-sm">
          <thead>
            <tr className="border-b border-border/60 bg-muted/30">
              <th scope="col" className="w-10 px-4 py-3">
                <span className="sr-only">Expand</span>
              </th>
              <th scope="col" className="px-4 py-3 text-start font-semibold">
                Customer
              </th>
              <th scope="col" className="px-4 py-3 text-start font-semibold">
                Plan
              </th>
              <th scope="col" className="px-4 py-3 text-start font-semibold">
                Status
              </th>
            </tr>
          </thead>

          <tbody>
            {rows.map((row) => {
              const expanded = open.has(row.id)
              const detailId = `row-detail-${row.id}`

              return (
                <React.Fragment key={row.id}>
                  <tr
                    className={`border-b border-border/40 transition-colors ${
                      expanded ? 'bg-muted/20' : 'hover:bg-muted/30'
                    }`}
                  >
                    <td className="px-4 py-3">
                      <button
                        type="button"
                        onClick={() => toggle(row.id)}
                        aria-expanded={expanded}
                        aria-controls={detailId}
                        aria-label={`${expanded ? 'Collapse' : 'Expand'} details for ${row.name}`}
                        className="rounded-lg p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
                      >
                        <ChevronRight
                          aria-hidden
                          className={`h-4 w-4 transition-transform duration-200 ${
                            // Mirrored only while closed; down is down in RTL.
                            expanded ? 'rotate-90' : 'rtl:rotate-180'
                          }`}
                        />
                      </button>
                    </td>

                    <td className="px-4 py-3">
                      <span className="block font-medium">{row.name}</span>
                      <span className="block text-xs text-muted-foreground">{row.email}</span>
                    </td>
                    <td className="px-4 py-3 text-muted-foreground">{row.plan}</td>
                    <td className="px-4 py-3 text-muted-foreground">{row.status}</td>
                  </tr>

                  {expanded ? (
                    <tr id={detailId} className="border-b border-border/40 bg-muted/10">
                      {/* Spans every column so the panel is full width without
                          disturbing the header's column widths. */}
                      <td colSpan={4} className="px-4 py-4">
                        <div className="grid gap-4 sm:grid-cols-3">
                          <DetailField
                            icon={<Calendar className="h-3.5 w-3.5" />}
                            label="Joined"
                            value={row.joined}
                          />
                          <DetailField
                            icon={<CreditCard className="h-3.5 w-3.5" />}
                            label="Last payment"
                            value={row.lastPayment}
                          />
                          <DetailField
                            icon={<Mail className="h-3.5 w-3.5" />}
                            label="Billing contact"
                            value={row.email}
                          />
                        </div>

                        <p className="mt-4 rounded-xl bg-background/60 p-3 text-sm text-muted-foreground">
                          {row.notes}
                        </p>
                      </td>
                    </tr>
                  ) : null}
                </React.Fragment>
              )
            })}
          </tbody>
        </table>
      </div>
    </div>
  )
}

function DetailField({
  icon,
  label,
  value,
}: {
  icon: React.ReactNode
  label: string
  value: string
}) {
  return (
    <div>
      <span className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
        {icon}
        {label}
      </span>
      <span className="mt-1 block text-sm">{value}</span>
    </div>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Install: npm i lucide-react
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/data-table-expandable.tsx and import it where you need the section:

import { DataTableExpandable } from '@/components/data-table-expandable'

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
rowsExpandableRow[]DEFAULT_ROWS
classNamestring''

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

data-table-expandable.html
<!--
  Expandable Detail Rows — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<div class="overflow-hidden rounded-2xl border border-border/60 bg-card/60 ">
  <div class="relative overflow-x-auto">
    <table class="w-full border-collapse text-sm">
      <thead>
        <tr class="border-b border-border/60 bg-muted/30">
          <th scope="col" class="w-10 px-4 py-3">
            <span class="sr-only">Expand</span>
          </th>
          <th scope="col" class="px-4 py-3 text-start font-semibold">Customer</th>
          <th scope="col" class="px-4 py-3 text-start font-semibold">Plan</th>
          <th scope="col" class="px-4 py-3 text-start font-semibold">Status</th>
        </tr>
      </thead>
      <tbody>
        <tr class="border-b border-border/40 transition-colors hover:bg-muted/30">
          <td class="px-4 py-3">
            <button type="button" aria-expanded="false" aria-controls="row-detail-1" aria-label="Expand details for Northwind Ltd" class="rounded-lg p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
              <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right h-4 w-4 transition-transform duration-200 rtl:rotate-180" aria-hidden="true">
                <path d="m9 18 6-6-6-6"></path>
              </svg>
            </button>
          </td>
          <td class="px-4 py-3">
            <span class="block font-medium">Northwind Ltd</span>
            <span class="block text-xs text-muted-foreground">ops@northwind.com</span>
          </td>
          <td class="px-4 py-3 text-muted-foreground">Team</td>
          <td class="px-4 py-3 text-muted-foreground">Active</td>
        </tr>
        <tr class="border-b border-border/40 transition-colors hover:bg-muted/30">
          <td class="px-4 py-3">
            <button type="button" aria-expanded="false" aria-controls="row-detail-2" aria-label="Expand details for Contoso" class="rounded-lg p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
              <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right h-4 w-4 transition-transform duration-200 rtl:rotate-180" aria-hidden="true">
                <path d="m9 18 6-6-6-6"></path>
              </svg>
            </button>
          </td>
          <td class="px-4 py-3">
            <span class="block font-medium">Contoso</span>
            <span class="block text-xs text-muted-foreground">billing@contoso.io</span>
          </td>
          <td class="px-4 py-3 text-muted-foreground">Pro</td>
          <td class="px-4 py-3 text-muted-foreground">Active</td>
        </tr>
        <tr class="border-b border-border/40 transition-colors hover:bg-muted/30">
          <td class="px-4 py-3">
            <button type="button" aria-expanded="false" aria-controls="row-detail-3" aria-label="Expand details for Initech" class="rounded-lg p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
              <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-right h-4 w-4 transition-transform duration-200 rtl:rotate-180" aria-hidden="true">
                <path d="m9 18 6-6-6-6"></path>
              </svg>
            </button>
          </td>
          <td class="px-4 py-3">
            <span class="block font-medium">Initech</span>
            <span class="block text-xs text-muted-foreground">admin@initech.dev</span>
          </td>
          <td class="px-4 py-3 text-muted-foreground">Pro</td>
          <td class="px-4 py-3 text-muted-foreground">Trialing</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

7 more blocks in Data Tables

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Data Tables

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Data Tables blocks

View category
Open the full page for this block

Sortable Selectable Table

Type-aware sorting with aria-sort, a header checkbox that goes properly indeterminate, and selection that survives a re-sort.

Data Tables297 lines1 dep
Open the full page for this block

Table Search & Filter Bar

Search, filter count and view switch, with active filters shown as removable chips so a filtered table never looks unfiltered.

Data Tables180 lines1 dep
Open the full page for this block

Column Show, Hide & Reorder

Reordering that works from the keyboard rather than by drag alone, pinned columns that cannot be hidden or moved, and a guard so the last visible column cannot be unchecked into a blank table.

Data Tables219 lines1 dep
Open the full page for this block

Bulk Action Bar

The selection bar that asks the question most tables skip: this page, or all 1,284 rows the filter matches. Typed confirmation above a threshold, an undo with the window counting down, and a select-all that names its own scope.

Data Tables405 lines1 dep
Open the full page for this block

Inline Editable Table

Edit cells in the grid with staged changes, per-cell validation, the original value kept beside the attempt, and a save that counts what is still pending.

Data Tables301 lines1 dep
Open the full page for this block

Grouped Table with Subtotals

Collapsible group headers that carry their own subtotals while collapsed, with a grand total that sums every row rather than only the visible ones.

Data Tables238 lines1 dep