Skip to content

Table

A native data table in a labeled scroll region, with sortable columns and an opt-in card reflow.

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t1-cap" tabindex="0" id="t1">
  <table class="cap-table">
    <caption id="t1-cap">Capsomer across the apps</caption>
    <thead>
      <tr>
        <th scope="col"><button type="button" class="cap-table-sort">App<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col">Version</th>
        <th scope="col" data-num><button type="button" class="cap-table-sort">Components used<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num><button type="button" class="cap-table-sort">Own copies left<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num>Token warnings</th>
        <th scope="col"><button type="button" class="cap-table-sort">Reported<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#app-docs">Docs</a></th>
        <td><span class="cap-mono">0.3.0</span> <span class="cap-muted">current</span></td>
        <td data-num>9</td>
        <td data-num>2</td>
        <td data-num>3</td>
        <td data-sort="2026-09-30T12:13Z"><time datetime="2026-09-30T12:13Z">2 hours ago</time></td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#app-admin">Admin</a></th>
        <td><span class="cap-mono">0.3.0</span> <span class="cap-muted">current</span></td>
        <td data-num>14</td>
        <td data-num>0</td>
        <td data-num>0</td>
        <td data-sort="2026-09-30T13:20Z"><time datetime="2026-09-30T13:20Z">53 minutes ago</time></td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#app-site">example.com</a></th>
        <td><span class="cap-mono">0.2.1</span> <span class="cap-muted">1 behind</span></td>
        <td data-num>6</td>
        <td data-num>4</td>
        <td data-num>11</td>
        <td data-sort="2026-09-29T18:40Z"><time datetime="2026-09-29T18:40Z">yesterday</time></td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#app-store">Storefront</a></th>
        <td class="cap-muted">Tokens only</td>
        <td data-num>0</td>
        <td data-num data-sort="-1" class="cap-muted">not counted</td>
        <td data-num>0</td>
        <td data-sort="2026-09-27T09:00Z"><time datetime="2026-09-27T09:00Z">3 days ago</time></td>
      </tr>
    </tbody>
  </table>
</div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/table.css";
import { enhance } from "capsomer/behavior/table";

enhance();

Usage

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="apps-cap" tabindex="0">
  <table class="cap-table">
    <caption id="apps-cap">Capsomer across the apps</caption>
    <thead>
      <tr>
        <th scope="col" aria-sort="ascending"><button type="button" class="cap-table-sort">App<svg aria-hidden="true">[up and down arrows: .cap-table-sort-up, .cap-table-sort-down]</svg></button></th>
        <th scope="col" data-num><button type="button" class="cap-table-sort">Components used[glyph]</button></th>
        <th scope="col">Reported</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row"><a class="cap-table-open" href="/apps/docs">Docs</a></th>
        <td data-num>9</td>
        <td data-sort="2026-09-30T12:13Z"><time datetime="2026-09-30T12:13Z">2 hours ago</time></td>
      </tr>
    </tbody>
  </table>
</div>
<th scope="col" data-drop="2" data-num>Errors<span class="cap-table-note">last 24 hours</span></th>
...
<th scope="row"><a class="cap-table-open" href="/sites/example-org">example.org</a><span class="cap-table-aside" data-drop="1">example.org</span></th>
<td data-drop="2" data-num>418 of 12.3k</td>
...
</div>
<div class="cap-table-foot"><a href="/sites">All 12 sites in Sites</a></div>
import { DataTable } from "capsomer/react/table";
<DataTable caption="Payments" captionHidden rowKey={(p) => p.id} rows={payments} empty="No payments yet."
  columns={[{ key: "who", header: "Customer", cell: (p) => p.name },
            { key: "amount", header: "Amount", num: true, sortBy: (p) => p.cents, cell: (p) => p.amount }]} />

Examples

Sorted ascending

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t2-cap" tabindex="0" id="t2">
  <table class="cap-table">
    <caption id="t2-cap">Worker requests by site, today</caption>
    <thead>
      <tr>
        <th scope="col"><button type="button" class="cap-table-sort">Site<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num aria-sort="ascending"><button type="button" class="cap-table-sort">Requests<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num>Errors</th>
      </tr>
    </thead>
    <tbody>
      <tr><th scope="row">example.net</th><td data-num>1,204</td><td data-num>0</td></tr>
      <tr><th scope="row">example.com</th><td data-num>9,870</td><td data-num>2</td></tr>
      <tr><th scope="row">example.org</th><td data-num>12,310</td><td data-num>418</td></tr>
      <tr><th scope="row">capsid portal</th><td data-num>38,016</td><td data-num>5</td></tr>
    </tbody>
  </table>
</div>

Sorted descending

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t3-cap" tabindex="0" id="t3">
  <table class="cap-table">
    <caption id="t3-cap">Errors by site, last 24 hours</caption>
    <thead>
      <tr>
        <th scope="col"><button type="button" class="cap-table-sort">Site<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num aria-sort="descending"><button type="button" class="cap-table-sort">Errors<svg width="10" height="12" viewBox="0 0 10 12" aria-hidden="true"><path class="cap-table-sort-up" d="M5 1 9 5H1z" /><path class="cap-table-sort-down" d="M5 11 1 7h8z" /></svg></button></th>
        <th scope="col" data-num>Error rate</th>
      </tr>
    </thead>
    <tbody>
      <tr><th scope="row">example.org</th><td data-num>418</td><td data-num>3.4%</td></tr>
      <tr><th scope="row">capsid portal</th><td data-num>5</td><td data-num>0.01%</td></tr>
      <tr><th scope="row">example.com</th><td data-num>2</td><td data-num>0.02%</td></tr>
      <tr><th scope="row">example.net</th><td data-num>0</td><td data-num>0%</td></tr>
    </tbody>
  </table>
</div>

A row focused

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t4-cap" tabindex="0" id="t4">
  <table class="cap-table">
    <caption id="t4-cap">Deploys today</caption>
    <thead>
      <tr>
        <th scope="col">Site</th>
        <th scope="col">Version</th>
        <th scope="col">By</th>
        <th scope="col">When</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#deploy-capsid">capsid</a></th>
        <td class="cap-mono">366b902</td>
        <td>Merged by you</td>
        <td><time datetime="2026-09-30T13:20Z">53 minutes ago</time></td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#deploy-billing">billing</a></th>
        <td class="cap-mono">a91c4e0</td>
        <td>billing-driver</td>
        <td><time datetime="2026-09-30T13:58Z">15 minutes ago</time></td>
      </tr>
    </tbody>
  </table>
</div>

Columns that can drop, a link to the rest

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t5-cap" tabindex="0" id="t5">
  <table class="cap-table">
    <caption id="t5-cap">Sites</caption>
    <thead>
      <tr>
        <th scope="col">Site</th>
        <th scope="col">Status</th>
        <th scope="col" data-num>Uptime<span class="cap-table-note">7 days</span></th>
        <th scope="col" data-drop="2">Live deploy</th>
        <th scope="col" data-drop="2" data-num>Errors<span class="cap-table-note">last 24 hours</span></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#site-portal">capsid dashboard</a><span class="cap-table-aside" data-drop="1">dashboard.capsid.dev</span></th>
        <td><span class="cap-status" data-tone="ok"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M8 1a7 7 0 1 0 0 14A7 7 0 1 0 8 1zM3.9 9l3 3 5.2-5.6-1.4-1.4-3.8 4.2-1.6-1.6z"/></svg>Up</span></td>
        <td data-num>99.96%</td>
        <td data-drop="2"><span class="cap-mono">366b902</span> <span class="cap-muted">53 minutes ago</span></td>
        <td data-drop="2" data-num>5 of 38.0k · 0.01%</td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#site-example-org">example.org</a><span class="cap-table-aside" data-drop="1">example.org</span></th>
        <td><span class="cap-status" data-tone="crit"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M5 1h6l4 4v6l-4 4H5l-4-4V5zM7.2 4h1.6v5H7.2zM7.2 10.4h1.6V12H7.2z"/></svg>Down</span></td>
        <td data-num>96.10%</td>
        <td data-drop="2"><span class="cap-mono">a91c4e0</span> <span class="cap-muted">15 minutes ago</span></td>
        <td data-drop="2" data-num>418 of 12.3k · 3.40%</td>
      </tr>
      <tr>
        <th scope="row"><a class="cap-table-open" href="#site-example-net">example.net</a><span class="cap-table-aside" data-drop="1">example.net</span></th>
        <td><span class="cap-status" data-tone="ok"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M8 1a7 7 0 1 0 0 14A7 7 0 1 0 8 1zM3.9 9l3 3 5.2-5.6-1.4-1.4-3.8 4.2-1.6-1.6z"/></svg>Up</span></td>
        <td data-num>100.00%</td>
        <td data-drop="2"><span class="cap-status" data-tone="nodata" title="No Cloudflare token for this site"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><circle cx="8" cy="8" r="6.2" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M5 8h6" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>No data<span class="cap-sr-only">: no Cloudflare token for this site</span></span></td>
        <td data-drop="2" data-num><span class="cap-status" data-tone="nodata" title="No Cloudflare token for this site"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><circle cx="8" cy="8" r="6.2" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M5 8h6" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>No data<span class="cap-sr-only">: no Cloudflare token for this site</span></span></td>
      </tr>
    </tbody>
  </table>
</div>
<div class="cap-table-foot"><a href="#sites">All 6 sites in Sites</a></div>

Row hover and selected, a footer, a caption underneath

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t6-cap" tabindex="0" id="t6">
  <table class="cap-table" data-caption="bottom">
    <caption id="t6-cap">Invoices this month, one selected</caption>
    <thead>
      <tr>
        <th scope="col"><span class="cap-sr-only">Select</span></th>
        <th scope="col">Invoice</th>
        <th scope="col">Status</th>
        <th scope="col" data-num>Amount</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><label class="cap-check"><input type="checkbox" name="ids" value="INV001" /><span class="cap-sr-only">Select INV001</span></label></td>
        <th scope="row">INV001</th>
        <td>Paid</td>
        <td data-num>$250.00</td>
      </tr>
      <tr data-state="selected" id="t6-selected">
        <td><label class="cap-check"><input type="checkbox" name="ids" value="INV002" checked /><span class="cap-sr-only">Select INV002</span></label></td>
        <th scope="row">INV002</th>
        <td>Pending</td>
        <td data-num>$150.00</td>
      </tr>
      <tr>
        <td><label class="cap-check"><input type="checkbox" name="ids" value="INV003" /><span class="cap-sr-only">Select INV003</span></label></td>
        <th scope="row">INV003</th>
        <td>Unpaid</td>
        <td data-num>$350.00</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <th scope="row" colspan="3">Total</th>
        <td data-num>$750.00</td>
      </tr>
    </tfoot>
  </table>
</div>

Sticky header, scrolling inside its region

<div class="cap-table-wrap" data-cap="table" data-sticky role="region" aria-labelledby="t7-cap" tabindex="0" id="t7">
  <table class="cap-table">
    <caption id="t7-cap">Deploy log</caption>
    <thead>
      <tr><th scope="col">Deploy</th><th scope="col">Site</th><th scope="col" data-num>Duration</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row" class="cap-mono">366b902</th><td>capsid portal</td><td data-num>41 s</td></tr>
      <tr><th scope="row" class="cap-mono">a91c4e0</th><td>example.org</td><td data-num>38 s</td></tr>
      <tr><th scope="row" class="cap-mono">7d02be1</th><td>example.net</td><td data-num>52 s</td></tr>
      <tr><th scope="row" class="cap-mono">5be9a10</th><td>example.com</td><td data-num>33 s</td></tr>
      <tr><th scope="row" class="cap-mono">0c41f77</th><td>capsid portal</td><td data-num>44 s</td></tr>
      <tr><th scope="row" class="cap-mono">e8830d2</th><td>example.org</td><td data-num>36 s</td></tr>
      <tr><th scope="row" class="cap-mono">12ab9c3</th><td>example.net</td><td data-num>49 s</td></tr>
      <tr><th scope="row" class="cap-mono">9f6e4d8</th><td>example.com</td><td data-num>31 s</td></tr>
      <tr><th scope="row" class="cap-mono">b3d1705</th><td>capsid portal</td><td data-num>43 s</td></tr>
      <tr><th scope="row" class="cap-mono">44c7a29</th><td>example.org</td><td data-num>40 s</td></tr>
      <tr><th scope="row" class="cap-mono">6a05e1f</th><td>example.net</td><td data-num>51 s</td></tr>
      <tr><th scope="row" class="cap-mono">d92b3c6</th><td>example.com</td><td data-num>35 s</td></tr>
    </tbody>
  </table>
</div>

Nothing to show, and comfortable density

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t8-cap" tabindex="0" data-density="comfortable" id="t8">
  <table class="cap-table">
    <caption id="t8-cap">Open incidents</caption>
    <thead>
      <tr><th scope="col">Incident</th><th scope="col">Site</th><th scope="col" data-num>Age</th></tr>
    </thead>
    <tbody>
      <tr><td colspan="3" class="cap-table-empty">No open incidents.</td></tr>
    </tbody>
  </table>
</div>

A row checkbox above the row link

<div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="t-rowcheck-cap" tabindex="0" id="t-rowcheck">
  <table class="cap-table">
    <caption id="t-rowcheck-cap">Posts, each row opens its detail and can be ticked</caption>
    <thead>
      <tr>
        <th scope="col"><span class="cap-sr-only">Select</span></th>
        <th scope="col">Post</th>
        <th scope="col">Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><label class="cap-check"><input type="checkbox" name="ids" value="p1" /><span class="cap-sr-only">Select Why the editor waits</span></label></td>
        <th scope="row"><a class="cap-table-open" href="#post-p1">Why the editor waits</a></th>
        <td>Published</td>
      </tr>
      <tr>
        <td><label class="cap-check"><input type="checkbox" name="ids" value="p2" /><span class="cap-sr-only">Select The uptime strip</span></label></td>
        <th scope="row"><a class="cap-table-open" href="#post-p2">The uptime strip</a></th>
        <td>Draft</td>
      </tr>
    </tbody>
  </table>
</div>

Region 560 px wide: the host, the deploy and the errors have gone

<main class="specimen-page">
  <div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="drop-cap" tabindex="0" id="t-drop">
    <table class="cap-table">
      <caption id="drop-cap">Sites</caption>
      <thead>
        <tr>
          <th scope="col">Site</th>
          <th scope="col">Status</th>
          <th scope="col" data-num>Uptime<span class="cap-table-note">7 days</span></th>
          <th scope="col" data-drop="2">Live deploy</th>
          <th scope="col" data-drop="2" data-num>Errors<span class="cap-table-note">last 24 hours</span></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row"><a class="cap-table-open" href="#site-portal">capsid dashboard</a><span class="cap-table-aside" data-drop="1">dashboard.capsid.dev</span></th>
          <td><span class="cap-status" data-tone="ok"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M8 1a7 7 0 1 0 0 14A7 7 0 1 0 8 1zM3.9 9l3 3 5.2-5.6-1.4-1.4-3.8 4.2-1.6-1.6z"/></svg>Up</span></td>
          <td data-num>99.96%</td>
          <td data-drop="2"><span class="cap-mono">366b902</span></td>
          <td data-drop="2" data-num>5 of 38.0k</td>
        </tr>
        <tr>
          <th scope="row"><a class="cap-table-open" href="#site-example-org">example.org</a><span class="cap-table-aside" data-drop="1">example.org</span></th>
          <td><span class="cap-status" data-tone="crit"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M5 1h6l4 4v6l-4 4H5l-4-4V5zM7.2 4h1.6v5H7.2zM7.2 10.4h1.6V12H7.2z"/></svg>Down</span></td>
          <td data-num>96.10%</td>
          <td data-drop="2"><span class="cap-mono">a91c4e0</span></td>
          <td data-drop="2" data-num>418 of 12.3k</td>
        </tr>
      </tbody>
    </table>
  </div>
</main>

Narrow: the table scrolls in its region

<main class="specimen-page">
  <h1 id="narrow-h">Sites</h1>
  <div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="narrow-h" tabindex="0" id="t-narrow">
    <table class="cap-table">
      <thead>
        <tr>
          <th scope="col">Site</th>
          <th scope="col">Status</th>
          <th scope="col" data-num>Latency</th>
          <th scope="col">Live deploy</th>
          <th scope="col">Backup age</th>
          <th scope="col">Probe</th>
        </tr>
      </thead>
      <tbody>
        <tr><th scope="row">capsid portal</th><td>Up</td><td data-num>84 ms</td><td class="cap-mono">366b902</td><td>4.2 hours</td><td>HTTP 200, 40 seconds ago</td></tr>
        <tr><th scope="row">example.org</th><td>Down</td><td data-num>no answer</td><td class="cap-mono">a91c4e0</td><td>not reported</td><td>no answer, 40 seconds ago</td></tr>
      </tbody>
    </table>
  </div>
</main>

Reflow opt-in: one card per row when narrow

<main class="specimen-page">
  <h1 id="reflow-h">Sites</h1>
  <div class="cap-table-wrap" data-cap="table" role="region" aria-labelledby="reflow-h" tabindex="0" data-reflow id="t-reflow">
    <table class="cap-table">
      <thead>
        <tr>
          <th scope="col">Site</th>
          <th scope="col">Status</th>
          <th scope="col" data-num>Latency</th>
          <th scope="col">Live deploy</th>
          <th scope="col">Backup age</th>
        </tr>
      </thead>
      <tbody>
        <tr><th scope="row">capsid portal</th><td data-label="Status">Up</td><td data-num data-label="Latency">84 ms</td><td data-label="Live deploy" class="cap-mono">366b902</td><td data-label="Backup age">4.2 hours</td></tr>
        <tr><th scope="row">example.org</th><td data-label="Status">Down</td><td data-num data-label="Latency">no answer</td><td data-label="Live deploy" class="cap-mono">a91c4e0</td><td data-label="Backup age">not reported</td></tr>
      </tbody>
    </table>
  </div>
</main>

API reference

Table

PropTypeRequiredDoes
captionReactNodeYesNames the region and the table. Hidden from sight with captionHidden, still read out.
captionHiddenboolean
captionBottombooleanThe caption under the table in muted type (shadcn caption-bottom).
labelledBystringName the region from a heading outside it instead of the caption (a panel's h2).
reflowReflowCard reflow below 640 px, or medium (860) or wide (1100). Opt-in (table.md).
stickybooleanThe header row stays while the region scrolls inside --cap-table-max-h.
density"compact" | "comfortable"
classNamestring
tableClassNamestring
childrenReactNodethead, tbody and tfoot.

DataTable

PropTypeRequiredDoes
columnsreadonly Column<T>[]Yes
rowsreadonly T[]Yes
rowKey(row: T) => stringYes
emptyReactNodeYesOne brief sentence when there are no rows.
sorted{ key: string; direction: SortDirection }The column the rows arrive sorted by, if any.
selected(row: T) => booleanA selected row (data-state="selected").
footReactNodeA totals row.
classNamestring
captionReactNodeYesNames the region and the table. Hidden from sight with captionHidden, still read out.
captionHiddenboolean
captionBottombooleanThe caption under the table in muted type (shadcn caption-bottom).
labelledBystringName the region from a heading outside it instead of the caption (a panel's h2).
reflowReflowCard reflow below 640 px, or medium (860) or wide (1100). Opt-in (table.md).
stickybooleanThe header row stays while the region scrolls inside --cap-table-max-h.
density"compact" | "comfortable"
tableClassNamestring

Functions

FunctionSignatureDoes
sortValue(cell: Element | undefined): string | numberThe value a cell sorts by: its data-sort attribute when it has one (a timestamp, a raw count), else its text. A plain number, with or without thousands separators, sorts as a number.
compareValues(a: string | number, b: string | number): number
sortRows(table: HTMLTableElement, index: number, direction: SortDirection): voidSorts every tbody's rows of table by column index. Stable: equal rows keep their order.
columnIndex(th: HTMLTableCellElement): numberThe column a header cell heads, counting the colspans before it.
sortByHeader(th: HTMLTableCellElement, direction?: SortDirection | undefined): SortDirectionSorts by the column of th: ascending first, then toggling. Only one header carries aria-sort at a time (APG sortable table). Returns the new direction.
enhance(root?: ParentNode): () => voidAttaches to every [data-cap="table"] under root that is not attached yet. Returns a function that detaches them all. A table already marked sorted (aria-sort in its markup) is expected to arrive in that order; it is not re-sorted on attach.

CSS variables

VariableDefault
--cap-table-max-h24rem

Parts and data attributes

ClassIs
.cap-tablethe root
.cap-table-asidea part
.cap-table-emptya part
.cap-table-foota part
.cap-table-notea part
.cap-table-opena part
.cap-table-sorta part
.cap-table-sort-downa part
.cap-table-sort-upa part
.cap-table-wrapa part
AttributeValues
data-captionbottom
data-drop1
data-labelpresent or absent
data-numpresent or absent
data-reflow medium narrow wide
data-stateselected
data-stickypresent or absent
data-wrappresent or absent
StateRead from
:activethe platform
:focus-visiblethe platform
:hoverthe platform
[aria-expanded="true"]an attribute
[aria-selected="true"]an attribute
[aria-sort="ascending"]an attribute
[aria-sort="descending"]an attribute

Accessibility

KeyDoes
TabReaches the scroll region, then each sort button, then each row's link
Arrow keys, on the focused regionScroll the table
Enter or Space on a sort buttonSorts by that column, ascending first, then toggling
Enter on a row's linkOpens the row's detail
  • The region's name comes from the caption or the panel heading, so a screen reader says what scrolls.
  • The region's focus ring is inset, so a panel's rounded clip never hides it.
  • aria-sort on exactly one header; the button inside has the column's name.
  • Forced colors: the sort glyph is drawn in CanvasText; focus rings are outlines and stay.

Last checked by hand: not yet. Reflow with a screen reader: not yet, so no app uses it. Automated: see the site's Tests page.