51 — Data display
Description List
Facts about one thing, each a term and its value, side by side or one over the other.
- Patient
- María Fernanda Ruiz
- Date of birth
- 12 March 1988
- Treatment
- Frozen embryo transfer
- Doctor
- Dr. Ana Ramírez
Installation
pnpm dlx @human-kit/design add description-listnpx @human-kit/design add description-listyarn dlx @human-kit/design add description-listbunx @human-kit/design add description-listThe command copies the files to src/lib/components/ui/description-list. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as DescriptionList from '$lib/components/ui/description-list';
</script>
<DescriptionList.Root>
<DescriptionList.Item>
<DescriptionList.Term>Patient</DescriptionList.Term>
<DescriptionList.Details>María Fernanda Ruiz</DescriptionList.Details>
</DescriptionList.Item>
</DescriptionList.Root> Guidelines
- Use a description list for the facts of one thing: a patient, an invoice, an order. For many things with the same facts, use a table.
- Use the
horizontallayout where there is width: the terms line up in a column and the eye runs down the values. - Use
verticalin a narrow column, a side panel or a card, where a column of terms would leave the values no room. - Turn
dividedon for a long list read row by row. Five facts or fewer read well without lines. - Set
termWidthto the longest term, so no term wraps and the values start close to them. - Write an empty value as a dash or as "Not given", never as a blank: a blank reads as a fact still loading.
Accessibility
- It renders a native
<dl>, with each term in a<dt>and each value in a<dd>, so a screen reader reads each value with its term. Itemis a<div>around one pair, which HTML allows inside a<dl>and which keeps the pair together in the layout.- A term with more than one value takes several
Detailsin the sameItem. - The order in the code is the order read aloud: the term always comes before its value, in both layouts.
API reference
DescriptionList.Root
| Prop | Type | Default |
|---|---|---|
layout | 'horizontal' | 'vertical' The terms in a column beside the values, or each term over its value. | 'horizontal' |
divided | boolean A thin line between the items. Rows grow from 24px to 32px. | false |
termWidth | string The width of the terms column, in the horizontal layout. Any CSS length. | '8rem' |
Plus every attribute of a <dl>.
DescriptionList.Item
| Prop | Type | Default |
|---|---|---|
class | string Classes merged onto the row. | — |
Plus every attribute of a <div>. It reads the layout of the root, so it has no props of its own.
DescriptionList.Term
| Prop | Type | Default |
|---|---|---|
class | string Classes merged onto the term. | — |
Plus every attribute of a <dt>.
DescriptionList.Details
| Prop | Type | Default |
|---|---|---|
class | string Classes merged onto the value. | — |
Plus every attribute of a <dd>.