Skip to content

Add support for Caption to Table #2073

@scurker

Description

@scurker

Table Caption Support

Overview

Add support for table captions to the existing Table component, providing a semantic and accessible way to label and describe tables with optional visibility control.

Problem Statement

The current Cauldron Table component lacks support for the HTML <caption> element, which is the most semantic and accessible way to provide a title or description for a table. While tables can currently be labeled using aria-label or aria-labelledby, the <caption> element offers several advantages:

  • Native semantics vs aria (via aria-label or aria-labelledby)
  • Better document structure

This enhancement would give developers the flexibility to choose the most appropriate labeling method for their use case while following accessibility best practices.

Component Design

Visual Design

TBD by @dequelabs/design-team

Interface / Props

interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
  // ...existing props

  /** 
   * Caption content for the table. Provides an accessible label for the table.
   */
  caption?: React.ReactNode;

  /** 
   * When a caption is set, visually hides the caption.
   */
  captionHidden?: boolean;

}

Accessibility

Labeling Hierarchy:

The table component should follow this precedence for labeling:

  • <caption> element (when provided)
  • aria-labelledby (when caption not provided)
  • aria-label (when neither caption nor aria-labelledby provided)

We should update documentation to reflect these semantics.

Responsiveness

TBD by @dequelabs/design-team

Usage Examples

<Table caption="Descriptive Caption of Table Contents">
  ...
</Table>

Referencing Implementations

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcAn issue proposing a new significant change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions