Table
A table displays data in rows and columns, with support for sorting, selection, and keyboard navigation.
Import
import { UNSTABLE_Table as Table } from "@cfa/react-core";Live Editor
Examples
Dynamic Collections
Use the items prop to pass an array of objects to Table.Body with a render function. This works like .map() but is more performant because it only re-renders rows that have changed, rather than the entire list.
Striped Variant
Use the variant="striped" prop to alternate row background colors for better readability.
Compact
Use the compact prop to reduce row height and cell padding.
Text Alignment
Use the textAlign prop on Table.Cell to align cell content. Supported values are "start" (default), "center", and "end".
Row Links
Use the href prop on Table.Row to make entire rows navigable. This is useful for tables where each row represents a resource the user can navigate to.
Single Selection
Enable single row selection by setting selectionMode="single".
Multiple Selection
Enable multiple row selection by setting selectionMode="multiple".
Replace Selection Behavior
By default, selection uses selectionBehavior="toggle" which renders checkboxes and allows additive selection. Set selectionBehavior="replace" to select rows on click. Clicking a new row deselects the previous one.
Disabled Rows
Use the disabledKeys prop to prevent interaction with specific rows. Disabled rows are excluded from selection.
Sortable Columns
Use sortDescriptor and onSortChange to control sorting. Mark sortable columns with allowsSorting and add sort indicator icons to show direction.
Empty State
Use the renderEmptyState prop to display a message when there are no items to display.
Async Loading
Use renderEmptyState to show a loading indicator while fetching data. Once the data resolves, the table automatically renders the rows.
Props
Visit the Documentation Site for the full list of props.
| Name | Type | Default | Description |
|---|---|---|---|
| compact | boolean | false | Whether the table uses compact sizing |
| variant | "default" | "striped" | "default" | Visual style variant of the table |
| aria-describedby | string | - | Identifies the element (or elements) that describes the object. |
| aria-details | string | - | Identifies the element (or elements) that provide a detailed, extended description for the object. |
| aria-label | string | - | Defines a string value that labels the current element. |
| aria-labelledby | string | - | Identifies the element (or elements) that labels the current element. |
| children | ReactNode | - | The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. |
| className | ClassNameOrFunction<TableRenderProps> | 'react-aria-Table' | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| defaultSelectedKeys | "all" | Iterable<Key> | - | The initial selected keys in the collection (uncontrolled). |
| dir | string | - | - |
| disabledBehavior | DisabledBehavior | "all" | Whether `disabledKeys` applies to all interactions, or only selection. |
| disabledKeys | Iterable<Key> | - | A list of row keys to disable. |
| disallowEmptySelection | boolean | - | Whether the collection allows empty selection. |
| dragAndDropHooks | DragAndDropHooks<object> | - | The drag and drop hooks returned by `useDragAndDrop` used to enable drag and drop behavior for the Table. |
| escapeKeyBehavior | "clearSelection" | "none" | 'clearSelection' | Whether pressing the escape key should clear selection in the table or not. Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually. |
| hidden | boolean | - | - |
| inert | boolean | - | - |
| lang | string | - | - |
| onAnimationEnd | AnimationEventHandler<HTMLTableElement> | - | - |
| onAnimationEndCapture | AnimationEventHandler<HTMLTableElement> | - | - |
| onAnimationIteration | AnimationEventHandler<HTMLTableElement> | - | - |
| onAnimationIterationCapture | AnimationEventHandler<HTMLTableElement> | - | - |
| onAnimationStart | AnimationEventHandler<HTMLTableElement> | - | - |
| onAnimationStartCapture | AnimationEventHandler<HTMLTableElement> | - | - |
| onAuxClick | MouseEventHandler<HTMLTableElement> | - | - |
| onAuxClickCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onClick | MouseEventHandler<HTMLTableElement> | - | - |
| onClickCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onContextMenu | MouseEventHandler<HTMLTableElement> | - | - |
| onContextMenuCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onDoubleClick | MouseEventHandler<HTMLTableElement> | - | - |
| onDoubleClickCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onGotPointerCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onGotPointerCaptureCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onLostPointerCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onLostPointerCaptureCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onMouseDown | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseDownCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseEnter | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseLeave | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseMove | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseMoveCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseOut | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseOutCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseOver | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseOverCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseUp | MouseEventHandler<HTMLTableElement> | - | - |
| onMouseUpCapture | MouseEventHandler<HTMLTableElement> | - | - |
| onPointerCancel | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerCancelCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerDown | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerDownCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerEnter | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerLeave | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerMove | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerMoveCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerOut | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerOutCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerOver | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerOverCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerUp | PointerEventHandler<HTMLTableElement> | - | - |
| onPointerUpCapture | PointerEventHandler<HTMLTableElement> | - | - |
| onRowAction | (key: Key) => void | - | Handler that is called when a user performs an action on the row. |
| onScroll | UIEventHandler<HTMLTableElement> | - | - |
| onScrollCapture | UIEventHandler<HTMLTableElement> | - | - |
| onSelectionChange | (keys: Selection) => void | - | Handler that is called when the selection changes. |
| onSortChange | (descriptor: SortDescriptor) => any | - | Handler that is called when the sorted column or direction changes. |
| onTouchCancel | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchCancelCapture | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchEnd | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchEndCapture | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchMove | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchMoveCapture | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchStart | TouchEventHandler<HTMLTableElement> | - | - |
| onTouchStartCapture | TouchEventHandler<HTMLTableElement> | - | - |
| onTransitionCancel | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionCancelCapture | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionEnd | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionEndCapture | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionRun | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionRunCapture | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionStart | TransitionEventHandler<HTMLTableElement> | - | - |
| onTransitionStartCapture | TransitionEventHandler<HTMLTableElement> | - | - |
| onWheel | WheelEventHandler<HTMLTableElement> | - | - |
| onWheelCapture | WheelEventHandler<HTMLTableElement> | - | - |
| render | DOMRenderFunction<"table" | "div", TableRenderProps> | - | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: * You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). * Only a single root DOM element can be rendered (no fragments). * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. |
| selectedKeys | "all" | Iterable<Key> | - | The currently selected keys in the collection (controlled). |
| selectionBehavior | SelectionBehavior | "toggle" | How multiple selection should behave in the collection. |
| selectionMode | SelectionMode | - | The type of selection that is allowed in the collection. |
| shouldSelectOnPressUp | boolean | - | Whether selection should occur on press up instead of press down. |
| slot | string | - | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. |
| sortDescriptor | SortDescriptor | - | The current sorted column and direction. |
| style | StyleOrFunction<TableRenderProps> | - | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. |
| translate | "yes" | "no" | - | - |