Skip to content

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".

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.

NameTypeDefaultDescription
compactbooleanfalseWhether the table uses compact sizing
variant"default" | "striped""default"Visual style variant of the table
aria-describedbystring-Identifies the element (or elements) that describes the object.
aria-detailsstring-Identifies the element (or elements) that provide a detailed, extended description for the object.
aria-labelstring-Defines a string value that labels the current element.
aria-labelledbystring-Identifies the element (or elements) that labels the current element.
childrenReactNode-The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows.
classNameClassNameOrFunction<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).
dirstring--
disabledBehaviorDisabledBehavior"all"Whether `disabledKeys` applies to all interactions, or only selection.
disabledKeysIterable<Key>-A list of row keys to disable.
disallowEmptySelectionboolean-Whether the collection allows empty selection.
dragAndDropHooksDragAndDropHooks<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.
hiddenboolean--
inertboolean--
langstring--
onAnimationEndAnimationEventHandler<HTMLTableElement>--
onAnimationEndCaptureAnimationEventHandler<HTMLTableElement>--
onAnimationIterationAnimationEventHandler<HTMLTableElement>--
onAnimationIterationCaptureAnimationEventHandler<HTMLTableElement>--
onAnimationStartAnimationEventHandler<HTMLTableElement>--
onAnimationStartCaptureAnimationEventHandler<HTMLTableElement>--
onAuxClickMouseEventHandler<HTMLTableElement>--
onAuxClickCaptureMouseEventHandler<HTMLTableElement>--
onClickMouseEventHandler<HTMLTableElement>--
onClickCaptureMouseEventHandler<HTMLTableElement>--
onContextMenuMouseEventHandler<HTMLTableElement>--
onContextMenuCaptureMouseEventHandler<HTMLTableElement>--
onDoubleClickMouseEventHandler<HTMLTableElement>--
onDoubleClickCaptureMouseEventHandler<HTMLTableElement>--
onGotPointerCapturePointerEventHandler<HTMLTableElement>--
onGotPointerCaptureCapturePointerEventHandler<HTMLTableElement>--
onLostPointerCapturePointerEventHandler<HTMLTableElement>--
onLostPointerCaptureCapturePointerEventHandler<HTMLTableElement>--
onMouseDownMouseEventHandler<HTMLTableElement>--
onMouseDownCaptureMouseEventHandler<HTMLTableElement>--
onMouseEnterMouseEventHandler<HTMLTableElement>--
onMouseLeaveMouseEventHandler<HTMLTableElement>--
onMouseMoveMouseEventHandler<HTMLTableElement>--
onMouseMoveCaptureMouseEventHandler<HTMLTableElement>--
onMouseOutMouseEventHandler<HTMLTableElement>--
onMouseOutCaptureMouseEventHandler<HTMLTableElement>--
onMouseOverMouseEventHandler<HTMLTableElement>--
onMouseOverCaptureMouseEventHandler<HTMLTableElement>--
onMouseUpMouseEventHandler<HTMLTableElement>--
onMouseUpCaptureMouseEventHandler<HTMLTableElement>--
onPointerCancelPointerEventHandler<HTMLTableElement>--
onPointerCancelCapturePointerEventHandler<HTMLTableElement>--
onPointerDownPointerEventHandler<HTMLTableElement>--
onPointerDownCapturePointerEventHandler<HTMLTableElement>--
onPointerEnterPointerEventHandler<HTMLTableElement>--
onPointerLeavePointerEventHandler<HTMLTableElement>--
onPointerMovePointerEventHandler<HTMLTableElement>--
onPointerMoveCapturePointerEventHandler<HTMLTableElement>--
onPointerOutPointerEventHandler<HTMLTableElement>--
onPointerOutCapturePointerEventHandler<HTMLTableElement>--
onPointerOverPointerEventHandler<HTMLTableElement>--
onPointerOverCapturePointerEventHandler<HTMLTableElement>--
onPointerUpPointerEventHandler<HTMLTableElement>--
onPointerUpCapturePointerEventHandler<HTMLTableElement>--
onRowAction(key: Key) => void-Handler that is called when a user performs an action on the row.
onScrollUIEventHandler<HTMLTableElement>--
onScrollCaptureUIEventHandler<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.
onTouchCancelTouchEventHandler<HTMLTableElement>--
onTouchCancelCaptureTouchEventHandler<HTMLTableElement>--
onTouchEndTouchEventHandler<HTMLTableElement>--
onTouchEndCaptureTouchEventHandler<HTMLTableElement>--
onTouchMoveTouchEventHandler<HTMLTableElement>--
onTouchMoveCaptureTouchEventHandler<HTMLTableElement>--
onTouchStartTouchEventHandler<HTMLTableElement>--
onTouchStartCaptureTouchEventHandler<HTMLTableElement>--
onTransitionCancelTransitionEventHandler<HTMLTableElement>--
onTransitionCancelCaptureTransitionEventHandler<HTMLTableElement>--
onTransitionEndTransitionEventHandler<HTMLTableElement>--
onTransitionEndCaptureTransitionEventHandler<HTMLTableElement>--
onTransitionRunTransitionEventHandler<HTMLTableElement>--
onTransitionRunCaptureTransitionEventHandler<HTMLTableElement>--
onTransitionStartTransitionEventHandler<HTMLTableElement>--
onTransitionStartCaptureTransitionEventHandler<HTMLTableElement>--
onWheelWheelEventHandler<HTMLTableElement>--
onWheelCaptureWheelEventHandler<HTMLTableElement>--
renderDOMRenderFunction<"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).
selectionBehaviorSelectionBehavior"toggle"How multiple selection should behave in the collection.
selectionModeSelectionMode-The type of selection that is allowed in the collection.
shouldSelectOnPressUpboolean-Whether selection should occur on press up instead of press down.
slotstring-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.
sortDescriptorSortDescriptor-The current sorted column and direction.
styleStyleOrFunction<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"--