Skip to content

Refactor Table to schema-driven columns for typed projection and built-in formatting #158

Open

Description

@coloneljade

Problem

Table's public API takes columns as headers: string[] and rows as data: ComponentChild[][]. Three issues fall out of this shape:

  1. Lost types at the call site. Consumers who have a typed record array (Employee[], Order[], etc.) must project to ComponentChild[][] themselves. The positional dependency between headers[i] and data[i][j] is invisible to the type system — typo a column order or miscount cells and the table renders silently miscolumned data.
  2. Repeated formatting work. Every consumer re-implements the same display logic — number alignment, currency formatting, date rendering, monospace IDs — at the call site. There's no place for the library to provide sensible defaults.
  3. rowHeader: boolean is leading-only. It marks the first column as <th scope=\"row\">, but real tables often want a non-leading column (an ID, a name) as the row header.

Impact

  • Every typed-data consumer carries the same projection-and-formatting boilerplate.
  • The positional API silently breaks when columns are reordered without matching changes to the data array.
  • Foundation work for DataTable (#milestone:DataTable) — the editable variant cannot cleanly compose on top of the current shape because it needs schema metadata (column type, validators, accessor key) per column.

Suggested Approach

Introduce a typed column descriptor and replace the positional API:

interface ITableColumn<T> {
  key: keyof T & string;
  label: string;
  type?: 'text' | 'number' | 'date' | 'currency';
  render?: (row: T) => ComponentChild;
  rowHeader?: boolean;
  align?: 'start' | 'end' | 'center';
}

interface ITableProps<T> extends IBaseProps {
  caption: string;
  columns: ITableColumn<T>[];
  rows: T[];
  rowKey?: (row: T) => string;
  // striped, dense, captionHidden unchanged
}
  • key: indexes the row to extract the cell value
  • type: drives default formatting and alignment (numbers right-align, currency uses Intl.NumberFormat, dates use Intl.DateTimeFormat)
  • render: escape hatch for custom display (overrides type)
  • rowHeader: any column can opt into <th scope=\"row\">
  • rowKey: takes the typed row, not rendered cells

Default formatting per type:

  • text (default): plain text, left-aligned
  • number: Intl.NumberFormat, right-aligned
  • currency: requires a currency: string (ISO 4217); right-aligned
  • date: Intl.DateTimeFormat

This is a prerequisite for the DataTable milestone — the editable variant defines IDataTableColumn<T> extends ITableColumn<T> with editable, validate, and editor-specific props, sharing all structural pieces.

Migration

Breaking change to a public component. In-repo migration covers dev/sections/TableSection.tsx, tests/table.test.tsx, and tests/a11y/table.a11y.test.tsx — handled in the same PR.

For external consumers (apps depending on auldrant-ui):

Before After
headers={['Name', 'Age']} columns={[{ key: 'name', label: 'Name' }, { key: 'age', label: 'Age', type: 'number' }]}
data={[[u.name, u.age], ...]} rows={users}
rowHeader (first column only) columns[0].rowHeader: true (any column)
rowKey={(row, i) => ...} reading rendered cells rowKey={(row) => row.id} typed against T

Migration note for the release: the new API requires a typed row array. Consumers projecting from disparate sources can use a mapping pass (rows.map(r => ({ name: r.name, age: r.age, ... }))) before passing to <Table>.

Activity

  1. added
    enhancement
    on May 3, 2026
  2. changed the title [-]Tabular form editors require consumers to orchestrate cells, focus, and label wiring[/-] [+]Refactor Table to schema-driven columns for typed projection and built-in formatting[/+] on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions