List

Slant / Primitives

A plain list of rows, with hairlines between them or without.

Demo

Usage

@tuttn/slant
import { Badge, List, ListItem, StatCard, Text } from '@tuttn/slant'

// A ul with no bullets or padding, and hairlines between the rows.
<List>
  <ListItem><Text>Persist checkpoints</Text><Badge tone="success">Done</Badge></ListItem>
  <ListItem><Text>Draft the handoff</Text><Badge tone="warning">Review</Badge></ListItem>
</List>

// No hairlines: the rows sit closer, 4px above and below each.
<List divided={false}>…</List>

// Steps in order: an ol.
<List as="ol">{steps.map(step => <ListItem key={step.id}>…</ListItem>)}</List>

// Rows that aren't a list: a div of divs.
<List as="div"><ListItem as="div">…</ListItem></List>

// Components that render an li fit too.
<List>{stats.map(stat => <StatCard key={stat.label} as="li" {...stat} />)}</List>

Props

PropTypeDefaultDescription
as'ul' | 'ol' | 'div''ul'The element to render.
dividedbooleantrueHairlines between items.
…restHTMLAttributes<HTMLElement>—className, style, id, aria-* and handlers go on the ul, ol or div, and so does the ref.

Accessibility

  • The default ul is announced as a list with its item count. Use as="ol" when the order means something, and as="div" (with ListItem as="div") when the rows aren't a list.
  • List removes the bullets, and Safari's VoiceOver then stops announcing it as a list. Add role="list" where the count matters.
  • The hairlines are borders, not separators: nothing is announced between rows. Name the list with aria-label or aria-labelledby when more than one sits on a page.

List draws no box of its own: no outer border and no padding, only the hairlines between rows. The rows are List items, which spread their content to both ends. In a divided list the first row has no hairline and no space above it, so the list starts flush with whatever comes before. Put a list in a Card to give it a surface.