GhostTable
GhostTable composes native <table> markup for static data. Import GhostTable from @ghostvue/themes for cell padding, row rules, header styling, and a focus ring on its scroll region; the section and cell parts come from @ghostvue/vue and stay unstyled imports. To style the table yourself, see Advanced: headless composition.
Searchable team directory with status badges, row actions, loading and empty states, and a named horizontal-scroll region.
The team directory wraps themed GhostTable in a GhostCard. Each member's name is a row header (scope="row"), so screen readers announce it with every cell in the row. Status uses GhostBadge and row actions use a GhostDropdownMenu whose icon-only trigger is named per member. Search filters local data; when nothing matches, a GhostEmptyState spans the body and offers to clear the search. Refresh marks the table aria-busy and swaps rows for GhostSkeleton placeholders, and a polite status announces the result once.
The table uses contain-horizontal with scroll-label="Team members". The example gives the table a 30rem minimum width through its own class, so on a phone the columns keep their alignment and the named region scrolls instead of squeezing the cells. The example styles only its own content (the member name block and the end-aligned actions column); the recipe supplies cell padding, row rules, column header styling, and a token focus ring on the region.
Row headers
Themed service health table whose row headers name each record, with compact block padding for multiline rows.
Put the value that identifies each record in a GhostTableHeaderCell with scope="row". Screen readers then announce "Search" with that row's status and uptime, rather than a bare "Degraded". The recipe keeps row headers at body text size and semibold, so they read as the first cell of the record rather than as part of the column header band.
The recipe centres every cell on its row, so plain text lines up with a badge, a button, or an avatar in the next cell. That suits rows of single-line values. These rows wrap, so the example sets vertical-align: baseline on its body cells: the service name and uptime then sit on the first line of the status cell. Use the same override, or top, in any table of wrapping prose.
The notes wrap, so each row is several lines tall on a phone. The example sets the cell padding to --ghost-space-inset-xs, one step down the spacing scale, so those rows stay compact and the three columns fit a 320px screen. Every other recipe value is unchanged. To make every themed control and table in a subtree compact, set data-ghost-density="compact" instead; see density.
Horizontal containment
Themed deployments table that scrolls inside a caption-named region instead of widening the page.
The <table> itself never scrolls. A table that cannot fit its container widens the page unless you opt in with contain-horizontal. That wraps the table in a scroll container with role="region" and tabindex="0", so keyboard users can focus it and pan with the arrow keys. The page itself never scrolls sideways.
Use contain-horizontal when cells should not wrap: routes, identifiers, or columns that must stay aligned at every width. Prefer wrapping, or fewer columns, for prose. The row headers example above fits a phone without a region.
The region needs a name:
- With a visible caption, omit
scroll-label. The region usesaria-labelledbyon the caption, as in this example. - Without a caption, for example when a card heading already titles the table, set
scroll-label. The team directory usesscroll-label="Team members".
Summary table with totals
Themed seat usage table with row headers, a totals footer, and end-aligned tabular figures.
Column headers use smaller, muted text and a stronger divider than body rows. Row headers in the body and the GhostTableFoot total keep the body text size. Numeric columns in this sample align on the end edge with tabular figures, through a class on those cells. With containHorizontal, the scroll region shows the token focus ring, drawn inside its edge so a clipping ancestor cannot cut it off.
API
GhostTable
| Prop | Type | Default | Description |
|---|---|---|---|
containHorizontal | boolean | false | When true, wraps the table in a scroll container for explicit horizontal overflow. The table itself never receives implicit overflow. |
scrollLabel | string | — | Accessible name for the horizontal scroll region. When omitted and GhostTableCaption is rendered, the scroll region uses aria-labelledby on the caption id. |
| Slot | Slot props | Description |
|---|---|---|
default | — | GhostTableCaption, GhostTableHead, GhostTableBody, and GhostTableFoot content. |
@ghostvue/themes adds no props, events, or slots to the headless GhostTable API, which it forwards.
Native attributes fall through to the <table> element. Exposes element: HTMLTableElement | null.
Parts
| Component | Element | Props |
|---|---|---|
GhostTableCaption | caption | fallthrough |
GhostTableHead | thead | fallthrough |
GhostTableBody | tbody | fallthrough |
GhostTableFoot | tfoot | fallthrough |
GhostTableRow | tr | fallthrough |
GhostTableHeaderCell | th | scope?: 'col' | 'row' | 'colgroup' | 'rowgroup' |
GhostTableCell | td | fallthrough |
Each part exposes element for its native host.
Accessibility
Use GhostTableCaption when the table needs a name. Set scope on GhostTableHeaderCell when header relationships are not implicit. Sorting, filtering, and selection are out of scope; compose controls inside cells when needed. For sorting, selection, and paging built in, see GhostDataTable.
Advanced: headless composition
The headless parts from @ghostvue/vue render the same native markup with no styles. Use them with your own table CSS, or use the useGhostTable* composables to bind the contract to elements you already render.
Headless table
Always place rows inside GhostTableHead, GhostTableBody, or GhostTableFoot. Explicit <tbody> avoids browser-inserted section mismatches during SSR hydration.
Caption, header row, and explicit tbody semantics.
Composable use
Native table hosts with useGhostTable hooks.
Styling hooks
Hooks follow existing data-part conventions:
ghost-table/data-part="root"/data-ghost-tableon the tableghost-table-scroll-container/data-part="scroll-container"when containment is enabled- Section and cell classes:
ghost-table-head,ghost-table-body,ghost-table-row, etc.
Specification: GhostTable specification.