Skip to content

Table

⋯

Table composes native table sections and cells for data with row and column relationships. Table.Head renders <th> and Table.Cell renders <td>. Specialized cells display progress, trends, inline input, or selection without changing the table’s native structure.

import { Table } from "@nesra/ui/table";
export function Accounts() {
return (
<Table>
<caption>Accounts</caption>
<Table.Header>
<Table.Row>
<Table.Head scope="col">Name</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>Ada Lovelace</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);
}

Table is also exported from @nesra/ui. Its named parts are available through Table.

Table
├── Table.Header
│ └── Table.Row with Table.Head cells
│ └── Table.SortButton (optional, inside Table.Head)
├── Table.Body
│ └── Table.Row with Table.Cell or specialized cells
└── Table.Footer (optional)

Table.SortButton renders a native button and shows paired chevrons when unsorted, then an up or down arrow for the active direction. Put aria-sort="ascending" or "descending" on the active Table.Head, not on the button. The application updates the sort state and orders or fetches rows. The example cycles each selected column through unsorted, ascending, descending, and back to unsorted. Choosing another column starts ascending. Clearing sort restores the source row order.

density="directory" lets header and data row heights follow their content. It uses the existing small-medium table text, gray header surface, neutral row surface, stroke, 16px horizontal cell padding, 6px header padding, and 12px data cell padding. The Karyawan Figma measures 53px for its two-line header and about 49px for its data rows; those are observations, not fixed component sizes. The standard density remains the default. The example uses a minimum table width to demonstrate horizontal overflow while column widths follow their content.

Employee directory
EMP-003Dita Permatadita.p@nesra.ai
EMP-001Leni Yuskaleni.yuska@nesra.ai
EMP-002Michael Owenowen@nesra.ai

Cell templates: ring, graph, upside / downside

Section titled “Cell templates: ring, graph, upside / downside”

Table.RingCell, Table.GraphCell, and Table.SignalCell are reusable native <td> parts. Their ring, graph, and direction icon are rendered as SVG from row data. No image assets are needed. Table.GraphCell renders the Figma Table Cell Cell=Trend (the .Chart mini sparkline), and Table.SignalCell renders Cell=Signal.

Performance cell templates
MetricRingGraphUpside / downside
Revenue85%CompleteRevenue trend is increasingUp 12%
Expenses40%CompleteExpenses trend is decreasingDown 4%

Table.InputCell renders the Figma Cell=Input. It shows the saved value, or the placeholder with a pencil hint. Focus or typing starts a draft with Confirm and Cancel buttons. Enter or Confirm calls onValueChange with the draft. Escape or Cancel restores the saved value. The application validates the value and saves it.

Figma does not define what happens when focus leaves the cell. Nesra UI keeps an unconfirmed draft and its Confirm and Cancel buttons visible, so a change is never saved or lost without an explicit action.

Campaign budgets
CampaignBudgetSaved budget
AwarenessRp300.000
Retargeting—

layout="fixed" uses the widths in <colgroup>. The scroll container preserves those widths when the page is narrower than the table.

Account teams and regions
AccountTeamRegion
Ada LovelaceOperationsAsia Pacific
Grace HopperEngineeringEurope
Katherine JohnsonResearchNorth America

The example owns checkbox state and derives the header’s mixed state from selected rows. Pass selected to each selected Table.Row for the row surface. Table does not synchronize row and checkbox state. The 64px control column comes from the checkbox cell parts.

Account balances
AccountBalanceStatus
Ada LovelaceOperations300,000Active
Grace HopperEngineering125,000Pending
Total425,000

sticky="right" pins the action column to the right edge while the other columns scroll.

Accounts with pinned actions
AccountTeamRegionBalanceAction
Ada LovelaceOperationsAsia300,000
Grace HopperEngineeringEurope125,000
Katherine JohnsonResearchAmericas84,000

Place the table in a scrollable container. sticky on Table.Header pins header cells vertically. sticky="left" or "right" pins individual cells horizontally. For a second pinned column, pass stickyOffset equal to the width of the first pinned column to both header and data cells. Pinned headers stay above the other headers. The outside edge of the pinned group has a shadow fade.

Accounts with two pinned columns
NameTeamRegionBalance
Ada LovelaceOperationsAsia300,000
Grace HopperEngineeringEurope125,000

Table reads only semantic color roles, so the same markup follows the page theme. Apply .dark or data-theme="dark" to <html> or a containing element (color roles). The roles follow Figma’s Table Cell, .table mini chart, .Chart mini and Signal components.

Part Figma variable CSS token
Header cell Foundation/bg-gray, Text/text-body --nesra-foundation-bg-gray, --nesra-text-body
Data cell and border Foundation/bg-neutral, Stroke/stroke-border --nesra-foundation-bg-neutral, --nesra-stroke-border
Sort icon Icon/icon-muted --nesra-icon-muted
Supporting text Text/text-support --nesra-text-support
Ring: red, orange, green Categorical/Red/base, Orange/base, Green/base --nesra-categorical-{red,orange,green}-base
Ring track Action/primary-disabled --nesra-action-primary-disabled
Graph line, marker Stroke/stroke-success, Stroke/stroke-destructive --nesra-stroke-success, --nesra-stroke-destructive
Graph area Categorical/Green/base, Categorical/Red/base 10% --nesra-categorical-{green,red}-base, faded to transparent
Signal triangle Icon/icon-success, Icon/icon-destructive --nesra-icon-success, --nesra-icon-destructive
Input placeholder, value Text/text-support, Text/text-body --nesra-text-support, --nesra-text-body
Input pencil, editing underline Icon/icon-muted, Stroke/stroke-border --nesra-icon-muted, --nesra-stroke-border
Input confirm, cancel Icon/icon-success, Icon/icon-destructive --nesra-icon-success, --nesra-icon-destructive
Checkbox, checked Action/primary-default, Icon/icon-on-brand --nesra-action-primary-default, --nesra-icon-on-brand
Checkbox, unchecked Foundation/bg-neutral, Stroke/stroke-brand-primary --nesra-foundation-bg-neutral, --nesra-stroke-brand-primary
Checkbox, disabled Foundation/bg-disabled, Icon/icon-disabled --nesra-foundation-bg-disabled, --nesra-icon-disabled
Sort button and checkbox focus Box Shadow/Focus ring shadow-nesra-focus-ring

In Dark the checked checkbox inverts to a light fill with a dark check, and the cell surfaces become gray-950 and gray-800. The ring keeps the same categorical hues in both modes, while the graph and signal colors use the Dark success and destructive roles. In Light, the green and orange ring arcs are below 3:1 against white, so the visible percentage carries the value. Pinned-column fades and the sticky header shadow use --nesra-shadow-lg-01, which is darker in Dark.

  • Provide a <caption> or another accessible table name. Use scope="col" or scope="row" on headers. Use native id and headers for complex associations.
  • Table.CheckHead and Table.CheckCell require a label. They render named Base UI checkboxes. The application handles onCheckedChange and keeps header, row, and checkbox state aligned.
  • Table.Row selected changes the row surface and sets data-selected. It does not select data.
  • Native table navigation follows the browser. Editing, pagination, virtualization, and any grid keyboard model belong to the application.
  • Table.InputCell requires a label that names the row and column, such as “Budget for Awareness”. Confirm and Cancel are native buttons named by the Confirm and Cancel interface translations. Escape inside an editing input does not reach a surrounding dialog.
  • Table.SortButton is a native button, so Enter and Space activate onClick. It has a visible focus ring. Keep its text label meaningful and set aria-sort only on the currently sorted <th>. The application manages direction and row order.

Renders a native <table> and forwards table attributes and its ref. TableRoot is the flat alias.

Prop Type Default Effect
layout "auto" | "fixed" "auto" Chooses the browser’s table layout algorithm. Use <colgroup> for explicit widths with fixed.
density "default" | "directory" "default" Uses standard sizing or lets header and data row heights follow their content.

Native children, className, style, and table attributes remain available.

Renders <thead> and forwards native section attributes and its ref.

Prop Type Default Effect
sticky boolean false Pins descendant header cells to the top of a vertically scrolling container and applies a bottom shadow.

Use a scroll container with a bounded height for vertical scrolling. Pinned column headers remain above other sticky headers.

Renders <tbody> and forwards native section attributes and its ref. It adds no component-specific props. Native tbody attributes, className, and children remain available.

Renders <tfoot> and forwards native section attributes and its ref. It adds no component-specific props. Native tfoot attributes, className, and children remain available.

Renders <tr> and forwards native row attributes and its ref.

Prop Type Default Effect
selected boolean false Changes the row surface and sets data-selected. The application still owns selection state.

Native tr attributes, className, and children remain available.

Renders <th> and forwards native header attributes and its ref. Set scope="col" for a column header.

Prop Type Default Effect
alignment "start" | "center" | "end" "start" Aligns text horizontally.
sticky "left" | "right" — Pins the header cell to that horizontal edge.
stickyOffset number | string — Offsets the pinned cell. Numbers are CSS pixels.

Renders a native <button type="button"> inside Table.Head and forwards button attributes and its ref. The text child names the action. Its icon is decorative. This part does not set aria-sort, change sort state, or order rows.

Prop Type Default Effect
direction "none" | "ascending" | "descending" "none" Shows paired chevrons, an up arrow, or a down arrow.
onClick Native button handler — Reports activation to the application.

Renders <td> and forwards native cell attributes and its ref. Place text or components in children to compose cell content.

Prop Type Default Effect
alignment "start" | "center" | "end" "start" Aligns text horizontally.
sticky "left" | "right" — Pins the data cell to that horizontal edge.
stickyOffset number | string — Offsets the pinned cell. Numbers are CSS pixels.

For two or more pinned columns, set stickyOffset to the total width of preceding pinned columns on the same edge. Both cell parts accept native attributes, className, style, and refs.

Renders a 20px SVG progress ring, percentage, and optional supporting text in a native <td>. The ring is red below 50%, orange from 50% to below 75%, and green from 75% upward.

Prop Type Default Effect
value number Required Percentage, clamped to 0–100.
supportingText string — Adds a muted line under the visible percentage.

Renders a 112 × 56px SVG sparkline in a native <td>. The supplied label names the chart for assistive technology.

Prop Type Default Effect
values readonly number[] Required Plots at least two finite values from left to right.
direction "up" | "down" Required Uses green or red to convey trend direction.
label string Required Accessible description of metric and trend.

Renders the 20px Figma Signal triangle, up or down, and a visible change in a native <td>. Direction is also available as screen-reader text, so color and icon shape are not the only cues.

Prop Type Default Effect
direction "up" | "down" Required Shows green up or red down direction.
value string Required Displays the change, including its unit.

Renders a native <input> with optional Confirm and Cancel buttons in a native <td>.

Prop Type Default Effect
label string Required Names the input for assistive technology.
value string — Sets the controlled saved value.
defaultValue string "" Sets the initial uncontrolled saved value.
onValueChange (value: string) => void — Receives the draft on Enter or Confirm.
onValueCancel () => void — Reports Escape or Cancel.
placeholder string — Shows in text-support while the value is empty.
disabled boolean false Disables the input and its buttons.
inputProps Native input props — Forwards attributes such as inputMode, maxLength, or name.

The cell has data-cell-template="input" and data-editing while a draft is open.

All four templates forward native cell attributes, alignment, sticky, stickyOffset, className, style, and refs, like Table.Cell.

Renders a 64px wide <th> with a Base UI Checkbox. Forwards native header attributes and its ref, except children. scope defaults to "col". The checkbox is centered in the cell.

Prop Type Default Effect
label string Required Names the checkbox for assistive technology.
checked boolean — Sets controlled selection.
defaultChecked boolean — Sets initial uncontrolled selection.
indeterminate boolean — Shows mixed selection, such as some rows selected.
disabled boolean — Disables the checkbox and applies the inactive cell surface.
onCheckedChange (checked: boolean, details: CheckboxRootChangeEventDetails) => void — Reports a checkbox change. Update controlled selection in the application.
sticky "left" | "right" — Pins the selection column to a horizontal edge.
stickyOffset number | string — Offsets the pinned cell. Numbers are CSS pixels.

Renders a 64px wide <td> with a centered Base UI Checkbox. Forwards native data cell attributes and its ref except children. Use a row-specific label such as "Select Ada".

Prop Type Default Effect
label string Required Names this row’s checkbox.
checked boolean — Sets controlled row selection.
defaultChecked boolean — Sets initial uncontrolled row selection.
indeterminate boolean — Shows a mixed checkbox state.
disabled boolean — Disables the checkbox and applies the inactive cell surface.
onCheckedChange (checked: boolean, details: CheckboxRootChangeEventDetails) => void — Reports a checkbox change to application state.
sticky "left" | "right" — Pins the selection column to a horizontal edge.
stickyOffset number | string — Offsets the pinned cell. Numbers are CSS pixels.

See Layout and Colors for the underlying Light and Dark tokens.