Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Data display

Table

A data table with column headers, optional sorting and a sticky header.

Selector: mui-table

Import
import { Table } from '@mushilu-san/ui/data-display';
PreviewCode

Loading example…

Overview

Table renders a native <table> from columns and rows. Columns marked sortable get a sort button in the header, and sortChange emits the new key and direction.

Each header cell has scope="col", and the sorted column carries aria-sort. Set caption to name the table for screen readers.

When to use

  • Records with the same fields that users compare or sort.
  • Data with more than a few columns, where a list would be hard to scan.

When not to use

  • Layout of unrelated content. Use a Grid or a Stack. Use Grid instead.
  • A short list of single values. Use a list of text.

Guidelines

Do

  • Give the table a caption that says what it lists.
  • Right-align numbers so they compare easily.

Don't

  • Do not use a table for layout.
  • Do not sort on a column the user cannot see the meaning of.

Accessibility

Roles and attributes

ElementRoleNotes
hostregionScrollable region when the table is wider than its box.
header cellcolumnheader (native)scope="col". aria-sort on the sorted column.

Keyboard

KeysAction
TabShiftTabMoves focus between sort buttons.
EnterSpaceSorts by the focused column.
  • Keep the header row meaningful when read out, and avoid merged cells, which screen readers handle poorly.

API

Table

Selector: mui-table

NameTypeDefaultDescription
columnsrequiredTableColumn[]— Column definitions.
rowsrequiredreadonly Record<string, unknown>[]— Row data — each row is a plain record keyed by column key.
captionstring | undefined— Visible caption; also provides the region's accessible name.
stickyHeaderbooleanfalse Pin the header row when the table scrolls. Accepts attribute presence, e.g. <… stickyHeader>.
NameTypeDescription
sortChangeSortState Emitted whenever the user clicks a sortable column header.

CSS parts

  • ::part(caption)
  • ::part(root)
  • ::part(scroll)
  • ::part(sort-btn)
  • ::part(sort-icon)
  • ::part(table)
  • ::part(tbody)
  • ::part(td)
  • ::part(th)
  • ::part(thead)
  • ::part(tr)

Tokens

  • --mui-color-surface
  • --mui-color-border
  • --mui-color-text-muted
  • --mui-color-focus-ring
  • --mui-font-size-sm