Overview
Reference usage
A semantic list container (<ul role="list">) for a homogeneous collection of records. DataList owns the list element, the list reset, and the empty state; it delegates row chrome (padding, dividers, density) to the row primitive. Each record is rendered through the children snippet, which must render an <li> — StackedListItem is the recommended row.
Reach for DataList when you have a vertical list of like records. For key–value metadata about a single entity use DescriptionList; for tabular rows and columns use Table.
Usage
A list-level density is inherited by every StackedListItem row that does not set its own density prop. The empty snippet renders inside a component-owned <li class="cinder-data-list-empty">, so it needs no inline styling.
Day groups
Pass groupBy to put consecutive rows under a header band: it returns { key, label, detail } for an item, and consecutive items with one key share a header (Today · Monday, Nov 2, with Central time at the right). Each group is a nested list named by its header, so a screen reader announces the day. Pass items already sorted; they are not reordered.
statusColumn keeps the 128px status column for rows that have no status, so titles line up down the whole list.
Rows that change while you watch
Pass insertionAnnouncement to make the list live: a new row, such as a run that starts while the page is open, appears at the top of its group, and the function receives the number of new rows and returns the text (1 new run) that a polite live region speaks and draws as an accent status strip above the first group. Before any row arrives the region takes no space, so the first render announces and draws nothing, and the list holds the reader's place when the strip appears. Rows inserted above the viewport do not move what the reader is looking at: browsers with scroll anchoring already hold the position, and the list scrolls by the difference where they do not. A list scrolled to its top is left alone, so the new row is seen.
Long values
The list wraps unbroken values (an identifier) anywhere by default, and StackedListItem rows clamp their titles at two lines, so no value widens the list past its frame.
- Alice Chen
- Bob Osei
- Carol Mwangi
When to use
- Rendering a vertical list of like records where each row shares the same layout.
- Pairing with StackedListItem rows for leading/title/description/meta/trailing content.
- Showing a dedicated empty state when the collection has no items.
- Grouping rows under day headers, or announcing rows that arrive while the list is on screen.
- Presenting key-value metadata for a single entity — use description-list instead.
- Rendering tabular data with rows and columns — use table instead.
Examples
Basic data list
A list of homogeneous records. DataList is the semantic `<ul role="list">` container; each row is a StackedListItem with a title and trailing meta. Row chrome (padding, dividers, density) is owned by the row, so content stays compactly aligned instead of stretching to the viewport edges.
Day groups with a shared status column
groupBy puts consecutive rows under a header band that names a nested list, and statusColumn keeps the status column for rows with nothing to report so titles line up.
Empty state fallback
When items is empty, the empty snippet renders inside a component-owned `<li class="cinder-data-list-empty">` — centered, muted padding, no inline styles required.
A row inserted while you watch
insertionAnnouncement makes the list live: a new run appears at the top of its group, a polite live region says "1 new run", and the page does not change size or lose its place.
Props
Name | Type | Default | Description |
|---|---|---|---|
items required | T[] | The records to render. Each is passed to children. | |
key required | (item: T) => string | number | Key extractor for stable DOM reconciliation. Svelte uses this to identify
each row when the list is reordered, filtered, or updated. Without a key,
rows are matched by index and the wrong row instances may receive updated
props, causing O(n) churn and incorrect rendering.
``svelte
<DataList {items} key={(m) => m.id}>
`` | |
density | 'comfortable' | 'condensed' | List-level density inherited by StackedListItem rows that do not set their
own density prop. Omit to let each row use its own default. A per-row
density always overrides this list-level value.
Note: when passing a variable that may be undefined, spread conditionally
because exactOptionalPropertyTypes is enabled:
{...(density ? { density } : {})} | |
statusColumn | boolean | Keep the status column's width for every row that has no status (a workflow, an agent with
nothing to report), so titles line up down the whole list. A row's own statusColumn wins. | |
groupBy | (item: T) => DataListGroup | Group consecutive items under a header band, newest group first as the items arrive. Each group is a nested list named by its header, so a screen reader announces the day. Items are not reordered; pass them already sorted. | |
insertionAnnouncement | (count: number) => string | Announce rows inserted while the list is on screen. Called with the number of new rows; the
returned text (1 new run) is spoken politely through a live region that is also drawn as a
status strip above the first group. The first render announces nothing. Rows inserted above
the viewport do not move what the reader is looking at. | |
children required | snippet | Row renderer. MUST render an <li> (the list root is a <ul role="list">).
StackedListItem is the recommended row — it renders an <li> with
leading/title/description/meta/trailing slots. | |
empty | snippet | Rendered when items is empty. The component automatically wraps the
snippet output in <li class="cinder-data-list-empty">.
Do NOT wrap in an <li> yourself — the component provides the <li>
wrapper automatically. Pass only inner content (e.g. a <p>, a <div>,
or plain text). Contrast with children, which must render an <li>. |