How it works
A card with no outer border, a muted 12px header over the only hairline and no lines between rows. The first column is a round chevron button; when a row opens, the chevron fills with the accent and turns 90°, and the row and its detail share one filled panel with rounded corners. The detail is a following <tr><td colSpan> that opens with grid-template-rows 0fr to 1fr (a table row cannot be scaled, so this is the one layout transition) while its content drops in from 8px above and fades in; closing is faster. renderDetail(row, { open }) lets the detail animate its own content on every opening. Details render on first expansion and are then kept; collapsed ones are visibility: hidden. With maxHeight the header sticks and a new detail below the fold scrolls into view after opening.
Use it for
- Extra information that does not fit in the list but is not worth a page: an order's payment and notes, a file's version history, a ticket's activity.
- Checking items one by one without leaving the list: reconciling orders, reviewing queues.
- Too many columns: move the secondary ones into the detail and keep four or five key columns.
Look elsewhere when
- Large details (long forms, tabs, big images): open a drawer or a detail page instead.
- Genuine parent and child data (category and subcategory): use a tree table.
- Information every row must show: make it a column, not something hidden behind an expand.
Usage
import { ExpandTable } from './ExpandTable.jsx'
const columns = [
{ key: 'item', title: 'Order' },
{ key: 'amount', title: 'Amount', width: 80, align: 'right', render: (r) => `$${r.amount.toFixed(2)}` },
{ key: 'status', title: 'Status', width: 100 },
]
const rows = [
{ id: 'o1', item: 'Coffee beans', amount: 29.7, status: 'Shipped', pay: 'Card', eta: 'Wed, Nov 26' },
{ id: 'o2', item: 'Trail sneakers', amount: 84, status: 'Delivered', pay: 'Gift card', eta: 'Sat, Nov 22' },
]
export function RecentOrders() {
return (
<ExpandTable
title="Recent orders"
subtitle="This week"
columns={columns}
rows={rows}
rowKey={(r) => r.id}
// open is true while this row is open: use it to replay animations inside the detail on every opening
renderDetail={(r, { open }) => (
<p>
Paid by {r.pay}, arrives {r.eta}
</p>
)}
accordion
rowLabel={(r) => `Order ${r.item}`}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
columns | { key, title, width?, align?, render? }[] | — | Column definitions: key (also the default field to read), title, width, align and render for custom cells. |
rows | T[] | — | The data rows. |
rowKey | (row) => string | number | — | A unique identifier for each row. |
renderDetail | (row, { open }) => ReactNode | — | Content of the detail panel. Rendered on first opening and then kept. The second argument says whether the row is open now, so the detail can replay its own animation (a progress line, a chart) on each opening. |
expanded | (string | number)[] | — | Controlled: keys of the expanded rows. Omit it to let the component keep them. |
defaultExpanded | (string | number)[] | [] | Initially expanded rows when uncontrolled. |
onExpandedChange | (keys) => void | — | Called when rows expand or collapse. |
accordion | boolean | false | Accordion mode: expanding a row collapses the others. |
expandOnRowClick | boolean | true | Clicking anywhere on the row also expands it. Buttons, links and inputs in the row do not trigger it, nor does data-no-expand. |
isRowExpandable | (row) => boolean | — | Rows returning false have no detail: no chevron and nothing to open. |
maxHeight | number | string | — | Maximum height of the table area including the header. Beyond it, rows scroll inside the frame and the header sticks. A number is px. |
rowLabel | (row) => string | “Row N” | Row name used in the chevron button's accessible name, for example (row) => `Order ${row.no}`, read as “Details of Order R1124-0931”. |
emptyText | ReactNode | 'No data' | Text shown when there is no data. |
title | ReactNode | — | Card title shown in the title row. A string title also names the table for screen readers when label is not given. |
subtitle | ReactNode | — | Muted qualifier after the title, such as a period ("This week"). |
icon | ReactNode | — | Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden). |
actions | ReactNode | — | Controls at the right end of the title row (buttons, a switch, a menu). |
label | string | — | Table name for screen readers (the <caption>). Defaults to title when title is a string. |
labels | object | — | Replaces built-in text (details, row, toggle). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accessibility
- The chevron is a <button> with aria-expanded and aria-controls, named like “Details of Order R1124-0931”; Tab visits each row and Enter or Space toggles.
- Clicking the whole row is only a mouse shortcut; keyboard and screen readers use the chevron, with the same function.
- A collapsed detail is visibility: hidden and its row aria-hidden, so nothing inside can be focused or read.
- Expansion is not colour alone: the chevron turns from right to down and the detail really appears below.
- The focus ring wraps the 28px round chevron; on touch screens the header and chevron column grow to 44px.
- Reduced motion makes details appear and disappear directly, and scrolling into view is not smooth.
Motion
Opening: grid rows 0fr to 1fr and a fade over 360ms ease-out, content from 8px above in the same time; the chevron turns 90° with a light spring (360ms) and fills with the accent. Closing: 160ms ease-in. In the demo, the tracker line grows with scaleX over 900ms cubic-bezier(0.22, 1, 0.36, 1) and each dot pops as the line reaches it.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
ExpandTable.jsxexpand-table.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





