|Kit

DataList

A key/value description list on a semantic dl, for profile and detail pages. Labels line up in a column, stack above their values, or switch with the list's width. Pure Server Component.

DataList shows a record as pairs of a label and a value: "Login: jdoe", "Campus: Paris", "Status: Active". It renders a real <dl>, each pair a <div> holding a <dt> and a <dd>, so a screen reader announces it as a description list. It's a pure Server Component, with no state and no "use client".

Pass the rows as data, or compose DataList.Item, DataList.Label and DataList.Value when a value needs more than the data form gives it. The two mix: the data rows come first, then the children.

import { DataList } from "@42-central/ui-react/data-list";

<DataList
  data={[
    { label: "Login", value: "jdoe" },
    { label: "Campus", value: "Paris" },
  ]}
>
  <DataList.Item>
    <DataList.Label>Status</DataList.Label>
    <DataList.Value>
      <Badge color="green" variant="light">Active</Badge>
    </DataList.Value>
  </DataList.Item>
</DataList>;

Playground

DataList

Loading preview

Props

Code

<DataList
  orientation="horizontal"
  size="md"
  withDivider={false}
  muted={false}
/>

Full prop browser

DataList

Values

A value is any node: text, a Badge, an Avatar, a Copy button. In a row, the label and the value share their first baseline, so a one-line label stays level with a badge or with the first line of a value that wraps.

Student
Jane Doe
Login
jdoe
Campus
Paris
Status
Active
Blackhole absorption
In 112 days, on March 14, 2027

Code

<DataList withDivider>
  <DataList.Item>
    <DataList.Label>Student</DataList.Label>
    <DataList.Value>
      <span className="inline-flex items-center gap-2">
        <Avatar size="sm" name="Jane Doe" color="teal" />
        Jane Doe
      </span>
    </DataList.Value>
  </DataList.Item>
  <DataList.Item>
    <DataList.Label>Login</DataList.Label>
    <DataList.Value>
      <span className="inline-flex items-center gap-1">
        jdoe
        <Copy value="jdoe" size="xs" variant="subtle" />
      </span>
    </DataList.Value>
  </DataList.Item>
  <DataList.Item>
    <DataList.Label>Status</DataList.Label>
    <DataList.Value>
      <Badge color="green" variant="light">Active</Badge>
    </DataList.Value>
  </DataList.Item>
  {/* … */}
</DataList>

Orientation

horizontal, the default, puts the labels in a column beside their values. Each item is a row of the list's own grid (CSS subgrid), so the labels line up down the list whatever their length. vertical stacks each label above its value.

Login
jdoe
Campus
Paris
Email
jdoe@student.42.fr

Code

<DataList orientation="vertical" data={profile} />

Responsive

responsive stacks the items while the list is narrower than 24rem and lays them out as rows from there. It measures the list itself, not the viewport, so the same list switches in a narrow sidebar and stays horizontal in a wide main column. Resize the frame below to see it switch.

Login
jdoe
Campus
Paris
Cursus
42cursus · level 7.42
Email
jdoe@student.42.fr

Code

<DataList orientation="responsive" withDivider data={profile} />

The switch is a CSS container query, so it works without JavaScript and in a Server Component. It gives the list container-type: inline-size, which means the list's width can't come from its content: it fills its parent like any block. In a row that shrinks to fit (a flex item with no width), give it a width or flex-1, or it collapses.

Label width

By default the label column is as wide as the widest label, up to 40% of the list (fit-content(40%)); a longer label wraps. labelWidth sets the column instead. A number is in pixels, and a string is any grid track size: "10rem", "30%", "max-content", "minmax(8rem, 1fr)". It only applies to rows, so a vertical list ignores it.

Login
jdoe
Campus
Paris

Code

<DataList labelWidth="12rem" data={profile} />

Dividers

withDivider draws a hairline between items, never above the first or below the last, so the list sits flush in a card.

Login
jdoe
Campus
Paris
Email
jdoe@student.42.fr

Code

<Card>
  <DataList withDivider data={profile} />
</Card>

Sizes

size sets the font size on the same scale as Text (md is text-base), and the gaps that go with it. The default is md.

Login
jdoe
Campus
Paris
Login
jdoe
Campus
Paris

Code

<DataList size="xs" data={profile} />
<DataList size="lg" data={profile} />

Muted labels

Labels are the secondary text colour at medium weight, a step below the values, which are the primary colour. muted steps them further back, to the muted shade at normal weight, for a page where the values matter more than their names.

Login
jdoe
Campus
Paris

Code

<DataList muted data={profile} />

Accessibility

  • The list is a <dl>. Each item is a <div> holding one <dt> (the label) and one <dd> (the value), the grouping HTML allows inside a <dl>. Screen readers announce the list, its number of items, and each term with its description.
  • Keep one DataList.Label per item, and put several values in one DataList.Value rather than adding <dd>s.
  • DataList.Item must be a direct child of the list, as HTML requires, so don't wrap items in another element.
  • The layout uses logical properties, so the label column moves to the right under dir="rtl".

Anatomy

  • DataList: the <dl>, the grid both columns live on. It takes every layout prop.
  • DataList.Item: a <div>, one label/value pair.
  • DataList.Label: the <dt>.
  • DataList.Value: the <dd>.

Every part takes testId, rendered as data-testid on its element. A data row takes one too: it lands on the row's item, and its label and value get -label and -value after it (login, login-label, login-value). See Testing.

<DataList testId="profile" data={[{ label: "Login", value: "jdoe", testId: "login" }]} />;

screen.getByTestId("login-value"); // the <dd>

API

DataList accepts every dl prop plus:

Prop

Type

DataListEntry:

Prop

Type

DataList.Item, DataList.Label and DataList.Value take every prop of their element (div, dt, dd), plus asChild and testId.

Changelog

v0.30.0
  • New DataList: a key/value list on a <dl>, with horizontal, vertical or responsive orientation

    #477

On this page