Skip to content
loseta

Recipes

Data table

A data table is a native table with selection, status and row actions. Sorting, filtering, pagination and bulk actions stay in consumer JavaScript.

Recipe, not a registry item. Install the composition pieces withloseta add table checkbox badge button. There is no data-table class to install.

Invoices

Default

Recent invoices
Invoice Status Method Amount Actions
INV-001 Paid Credit card $250.00
INV-002 Pending PayPal $150.00
INV-003 Unpaid Bank transfer $350.00
<div class="table-container" style="border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden">
  <table class="table">
    <caption class="sr-only">Recent invoices</caption>
    <thead>
      <tr>
        <th scope="col"><input class="checkbox" type="checkbox" aria-label="Select all invoices"></th>
        <th scope="col" aria-sort="ascending">Invoice</th>
        <th scope="col">Status</th>
        <th scope="col">Method</th>
        <th scope="col">Amount</th>
        <th scope="col"><span class="sr-only">Actions</span></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><input class="checkbox" type="checkbox" aria-label="Select INV-001"></td>
        <td>INV-001</td>
        <td><span class="badge" data-variant="outline">Paid</span></td>
        <td>Credit card</td>
        <td>$250.00</td>
        <td><button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Open actions for INV-001"><span aria-hidden="true">···</span></button></td>
      </tr>
      <tr aria-selected="true">
        <td><input class="checkbox" type="checkbox" aria-label="Select INV-002" checked></td>
        <td>INV-002</td>
        <td><span class="badge" data-variant="secondary">Pending</span></td>
        <td>PayPal</td>
        <td>$150.00</td>
        <td><button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Open actions for INV-002"><span aria-hidden="true">···</span></button></td>
      </tr>
      <tr>
        <td><input class="checkbox" type="checkbox" aria-label="Select INV-003"></td>
        <td>INV-003</td>
        <td><span class="badge" data-variant="destructive">Unpaid</span></td>
        <td>Bank transfer</td>
        <td>$350.00</td>
        <td><button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Open actions for INV-003"><span aria-hidden="true">···</span></button></td>
      </tr>
    </tbody>
  </table>
</div>

Selection

Use native checkboxes with an accessible name per row. Mark a selected row witharia-selected="true"; the table styles the row without requiring a custom class. A header checkbox can select the visible page, but the select-all state is consumer behavior.

Sorting

Put aria-sort="ascending", "descending" or"none" on the active column header and update it when the sort changes. The CSS does not draw an arrow, so include a visible indicator or anaria-label that explains the current order.

html
<th scope="col" aria-sort="ascending">
  Invoice
  <span class="sr-only">sorted ascending</span>
</th>

Row actions

Compose the actions trigger with dropdown-menu. The trigger needs an accessible name that identifies the row; the menu carries the open state and keyboard behavior in consumer JavaScript.

html
<button class="btn" data-variant="ghost" data-size="icon-sm"
  aria-label="Open actions for INV-002" aria-expanded="false">
  <span aria-hidden="true">···</span>
</button>

Composition notes

  • Put the table in .table-container so narrow screens can scroll it.
  • Use <th scope="col"> for headers and a <caption> for the table name.
  • Do not hide the table header to save space; keep the column meaning available.
  • Pagination is a separate composition with pagination; it is not built into the table.

loseta is MIT licensed. Built with native CSS, no runtime. Inspired byshadcn/ui.