Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Data List for Vue UI SDK

Label and value pairs for one record, like an order or a user profile, marked up as a real dl. A data list for Vue and UI SDK apps.

On this page9 sections

A data list shows the facts about one thing as pairs of a label and a value: the customer on an order page, the plan and region of a server, the fields of a profile. Labels sit beside their values, or above them in a narrow column.

When there are many records with the same fields and people compare them down a column, use a Table instead. For a list of things people open or act on, an Item fits better.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Data List anatomy: root, item, item label, item value

Usage

<script setup lang="ts">
import {
  DataList, DataListItem, DataListItemLabel, DataListItemValue,
} from "@/components/ui/data-list";
</script>
const data = [
  { label: "New Users", value: "234" },
  { label: "Sales", value: "£3,450" },
  { label: "Revenue", value: "£12,340" },
];

const DataListDemo = () => (
  <DataList>
    {data.map((item) => (
      <DataListItem key={item.label}>
        <DataListItemLabel>{item.label}</DataListItemLabel>
        <DataListItemValue>{item.value}</DataListItemValue>
      </DataListItem>
    ))}
  </DataList>
);

Each DataListItem holds one label and one value. Besides the usual HTML attributes, DataList takes one prop of its own, orientation, which is horizontal unless you set it.

Accessibility

DataList renders a dl, and each item is a div that groups a dt for the label and a dd for the value, a layout HTML allows inside a description list. Browsers pass that structure on to assistive technology as terms and their definitions, and the component adds no role, ARIA attribute or focus stop of its own. What stays with you: keep one label and one value in each item, and don't use render to swap a label or value for another element, which drops the dt or dd. An icon-only button in a label needs an aria-label, as in the Info tip demo.

Demos

Info tip

Three metrics, each with a small info button after its label that opens a Toggle Tooltip holding one line about the number, such as what Sales counts. The tooltip opens on click or tap, so it works on a phone, and each button's aria-label names its metric. Use it when a figure needs a sentence of definition, which would clutter the list if it were printed under every row.

Preview width

Orientation horizontal

A first name, a last name and an email address, with each label in a column at least 6rem wide and its value filling the rest of the row. This is the default, set here as orientation="horizontal" for clarity. It reads best on a profile or an order summary whose values are a word or two long.

Preview width

Orientation vertical

The same three fields with orientation set to vertical, so each label sits above its value and the gap between them shrinks. Pick it for a narrow sidebar, a card on a phone, or values that wrap over several lines, where a column of labels would squeeze them. Labels lose their minimum width here, since each one has a line to itself.

Preview width

Separator

A contact record of five fields, from first name to street address, with divide-y on DataList drawing a line between items. The line is Tailwind's bottom border on every item but the last, not a separate component. Add it once a list is long enough that the eye loses which value belongs to which label, and leave it off a list of three.

Preview width

With badge

An account summary where status shows as an outline Badge reading Active, plan as a solid Pro badge, and region as plain text. Use badges for the one or two values people scan for, a state or a tier, and keep everything else as text so the badges still stand out.

Preview width

FAQ

Does the Data List render a dl, dt and dd?

It does. DataList renders a dl, each DataListItem a div, and the label and value inside it a dt and a dd. HTML allows a div to wrap each term and its description inside a dl, so the markup is valid and each item can take its own classes for spacing or a border.

Browsers expose the dt and dd to assistive technology as a term and its definition. The component adds no role or ARIA attribute on top, and nothing in it takes focus.

Should I use a Data List or a Table?

Use a Data List to describe one record, such as one customer, one invoice or one deployment, with a label for each fact. Use a Table when there are many records with the same fields and people compare, sort or scan them down a column.

A detail page often has both: a Data List with the order's summary at the top and a Table of its line items under it.

How do I put Data List labels beside or above their values?

Set orientation on DataList. With horizontal, the default, each label sits in a column at least 6rem wide with its value beside it. With vertical, the label stacks above the value and the gap between them shrinks, which suits narrow screens and long values.

The prop changes each item, while the list always runs top to bottom. It has no responsive form, so to switch at a breakpoint, pass orientation from your own media query state. Compare the Orientation horizontal and Orientation vertical demos.

How do I line up the values in a Data List when one label is long?

Give every label the same fixed width. A DataListItemLabel is at least 6rem wide and never shrinks, so a label longer than that pushes its own value further right than the others, and the values stop forming a straight column.

Add a width class such as w-40 to each DataListItemLabel, or change the label's min-w-24 to a wider value once in components/ui/data-list. In the vertical orientation this doesn't come up, because each label sits on its own line.

Why does a long email or URL overflow my Data List?

An email address, a URL or an ID has no spaces to wrap at, and the value is a flex item, which by default won't shrink below its longest unbroken word. In a narrow container it runs past the edge.

Add truncate to that DataListItemValue to cut the text with an ellipsis, or break-all to wrap it onto more lines. If you truncate, put the full value in a title attribute or a copy button so it can still be read.

Can a Data List value contain a badge, a link or a button?

Yes. DataListItemValue renders a dd that takes any children, so a Badge, a link, a copy button or an avatar can go where the text would. The With badge demo shows a status and a plan as badges.

In the horizontal orientation each item centers its label and value vertically, so a badge or a button taller than a line of text stays level with its label. Keep a badge's word meaningful on its own, because its color doesn't reach a screen reader.

How do I add dividers between Data List items?

Add divide-y to the classes of DataList. Tailwind gives every item but the last a bottom border, which draws a line between each pair, as the Separator demo does.

Each item has 0.5rem of padding above and below, and the list adds a 0.25rem gap between items, so the line sits a little closer to the item above it. Add gap-0 next to divide-y if you want the space on both sides of the line to match.

How do I add an info tooltip to a Data List label?

Put an icon-only button inside DataListItemLabel, wrap it in a Toggle Tooltip, and give the button an aria-label that names the metric, such as "Info about Sales". The Info tip demo does this for three figures.

A toggle tooltip opens on click or tap, so it works on a phone, which has no hover to open an ordinary tooltip. Add inline-flex and items-center to the label's classes so the icon sits on the same line as the text.

API Reference

DataList

PropType
orientation?"horizontal" | "vertical"

Layout of each item. The list itself is always stacked. horizontal places label and value in a row. vertical stacks label above value.

Type
"horizontal" | "vertical"
Default
"horizontal"
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

DataListItem

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

DataListItemLabel

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

DataListItemValue

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.