Components
Table
Responsive data table for lists, comparisons, and structured records.
Examples
Sticky header
maxHeight turns the table into a vertical scroll region, and stickyHeader keeps the column headings pinned while the rows scroll beneath them.
Composition
Anatomy
- <Table>
- <TableCaption />
- <TableHeader>
- <TableRow>
- <TableHead />
- <TableRow>
- <TableBody>
- <TableRow>
- <TableCell />
- <TableRow>
- <TableFooter>
- <TableRow>
- <TableCell />
- <TableRow>
Clickable rows
TableRowLink turns the whole row into its hit area: the row paints --cui-table-row-hover-background on hover and the focus ring while the link has focus. It renders a button; pass render={<a href />} to navigate. Other buttons, links, and checkboxes in the row stay clickable above it.
- <Table>
- <TableBody>
- <TableRow>
- <TableCell>
- <TableRowLink />
- <TableCell>
- <TableRow>
- <TableBody>
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/table.tsx.
npx shadcn@latest add https://control-ui.dev/r/table.jsonDependencies
Raw code
Primary installed source
"use client";
import { useRender } from "@base-ui/react/use-render";import type { ComponentProps, CSSProperties } from "react";import type { RenderProp } from "@/components/control-ui/control-props";import type { TableKnobStyle } from "@/components/control-ui/knob-contracts/table-knobs";import { cn } from "@/components/control-ui/lib/cn";import { ScrollArea } from "@/components/control-ui/ui/scroll-area";
export type TableProps = Omit<ComponentProps<"table">, "style"> & { style?: CSSProperties & TableKnobStyle } & { containerClassName?: string; maxHeight?: string; /** Pins the header cells while the body scrolls under `maxHeight`; they paint `--cui-table-header-sticky-background`. */ stickyHeader?: boolean;};
export type TableHeaderProps = Omit<ComponentProps<"thead">, "style"> & { style?: CSSProperties & TableKnobStyle };
export type TableBodyProps = Omit<ComponentProps<"tbody">, "style"> & { style?: CSSProperties & TableKnobStyle };
export type TableFooterProps = Omit<ComponentProps<"tfoot">, "style"> & { style?: CSSProperties & TableKnobStyle };
export type TableRowProps = Omit<ComponentProps<"tr">, "style"> & { style?: CSSProperties & TableKnobStyle };
export type TableHeadProps = Omit<ComponentProps<"th">, "style"> & { style?: CSSProperties & TableKnobStyle };
export type TableCellProps = ComponentProps<"td"> & { style?: CSSProperties & TableKnobStyle };
export type TableRowLinkProps = Omit<ComponentProps<"button">, "style"> & { render?: RenderProp<ComponentProps<"button">>; style?: CSSProperties & TableKnobStyle;};
export type TableCaptionProps = Omit<ComponentProps<"caption">, "style"> & { style?: CSSProperties & TableKnobStyle };
export function Table({ className, containerClassName, maxHeight, stickyHeader = false, ...props }: TableProps) { return ( <div data-control-ui="table" data-control-family="table" data-slot="container" className={cn("relative w-full", containerClassName)}> <ScrollArea maxHeight={maxHeight} mask={!stickyHeader} lockAxis={maxHeight ? undefined : "y"} aria-label={props["aria-label"]} aria-labelledby={props["aria-labelledby"]} > <table data-control-ui="table" data-control-family="table" data-slot="root" data-sticky-header={stickyHeader ? "true" : undefined} className={cn("w-full caption-bottom", className)} {...props} /> </ScrollArea> </div> );}
export function TableHeader({ className, ...props }: TableHeaderProps) { return <thead data-control-ui="table" data-control-family="table" data-slot="header" className={className} {...props} />;}
export function TableBody({ className, ...props }: TableBodyProps) { return <tbody data-control-ui="table" data-control-family="table" data-slot="body" className={className} {...props} />;}
export function TableFooter({ className, ...props }: TableFooterProps) { return <tfoot data-control-ui="table" data-control-family="table" data-slot="footer" className={className} {...props} />;}
export function TableRow({ className, ...props }: TableRowProps) { return <tr data-control-ui="table" data-control-family="table" data-slot="row" className={className} {...props} />;}
export function TableHead({ className, ...props }: TableHeadProps) { return ( <th data-control-ui="table" data-control-family="table" data-slot="head" className={cn("whitespace-nowrap align-middle [&:has([role=checkbox])]:pe-0", className)} {...props} /> );}
export function TableCell({ className, ...props }: TableCellProps) { return ( <td data-control-ui="table" data-control-family="table" data-slot="cell" className={cn("whitespace-nowrap align-middle [&:has([role=checkbox])]:pe-0", className)} {...props} /> );}
export function TableCaption({ className, ...props }: TableCaptionProps) { return <caption data-control-ui="table" data-control-family="table" data-slot="caption" className={className} {...props} />;}
export function TableRowLink({ render, ...props }: TableRowLinkProps) { return useRender({ defaultTagName: "button", render, props: { type: render ? undefined : "button", ...props, "data-control-ui": "table", "data-control-family": "table", "data-slot": "row-link", "data-focus-ring": "none", }, });}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-table-background | <color> | transparent |
--cui-table-foreground | <color> | var(--foreground) |
--cui-table-border-color | <color> | var(--border) |
--cui-table-border-width | <length> | var(--control-rim-width) |
--cui-table-cell-padding | <length-percentage> | calc(var(--spacing) * 2) |
--cui-table-head-height | <length-percentage> | var(--control-h-lg) |
--cui-table-row-hover-background | <color> | oklch(from var(--foreground) l c h / 0.03) |
--cui-table-row-selected-background | <color> | oklch(from var(--foreground) l c h / 0.05) |
--cui-table-header-foreground | <color> | var(--muted-foreground) |
--cui-table-footer-background | <color> | oklch(from var(--foreground) l c h / 0.03) |
--cui-table-header-sticky-background | <color> | var(--background) |
--cui-table-header-sticky-shadow | * | inset 0 calc(var(--cui-table-border-width) * -1) 0 var(--cui-table-border-color) |