# List

## Usage

`List` presents a collection of related entries, and `ListItem` is one row inside it. The pair renders a semantic `<ul>` or `<ol>` and lays out every row as start content, label, description, and end content, so a settings screen, an inbox, or a set of steps does not have to rebuild that row layout each time.

One row needs nothing more than a `label`:

```vue
<script setup lang="ts">
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <List header="Inbox">
    <ListItem label="Mentions" description="Comments that name you" />
    <ListItem label="Build finished" description="main passed every check" />
  </List>
</template>
```

`description` is the secondary line under the label. The `startContent` and `endContent` slots place an icon, an avatar, a badge, or an action at either end of the row, and `label` and `description` each have a same-named slot for content that needs richer markup than a string.

The list sets the density for all of its rows, and a single row can override it. `compact` uses 4px of block padding, `balanced` is the 8px default, and `spacious` uses 12px and widens the inline padding by one step as well. `hasDividers` rules a line between neighbouring rows, and the last row never draws one.

`listStyle` decides what appears in front of each row: `disc` draws a filled bullet, `circle` draws an outlined one, and `decimal` switches the list to an `<ol>` and numbers the rows, with `start` choosing the first number. The default `none` draws no marker at all.

A row becomes interactive in one of two ways. Give it `onClick` and a button appears inside the row, filling the content area, so keyboard users can tab to it and press Enter or Space; give it `href` and that same place becomes a link, with `noopener` and `noreferrer` added automatically when `target="_blank"`. Clicking another control inside the row, such as a button in `endContent`, does not run the row's own action.

`isSelected` marks the row as selected. When the row carries a role that permits `aria-selected` — `option`, `tab`, or `row`, for instance — the state is written there; otherwise it falls back to `aria-current="true"`, which is valid on any element, so assistive technology still hears which row is current. `isDisabled` makes the row inert and dims its content.

The `header` slot renders a title above the list and associates it through `aria-labelledby`, so a screen reader announces the title when it enters the list.

`edge` decides where each row's text, dividers, and hover and selection backgrounds sit relative to the list's edges and the padding of the container around it. The default `padded` keeps the row's own inline padding. `flush` removes it, so text starts on the line of a heading above the list and lines and backgrounds stop at the text. `outset` keeps text on that line and lets lines and backgrounds reach into the container's padding. `bleed` puts text on the container's padding line and runs lines and backgrounds to its edges with square corners, like table rows in a Card. A row's first content — its marker, icon, or avatar, otherwise its label — is what lines up with the heading.

`outset` and `bleed` read the padding published by the nearest container that shares it: a Card, Section, BottomSheet, a padded ScrollableArea, or a Layout region. Place the list directly in that container's padding; padding that Stack, Center, or your own styles add in between is not counted. With no such container, such as a standalone list or one in a Popover, they look like `padded`. `edgeCompensation="inline"` still works as a deprecated alias of `edge="outset"`; set `edge` in new code.

The package also exports the more general `Item` primitive. `ListItem` is that primitive rendered as an `<li>` with the density and marker from its list; use `Item` directly when the same row layout is needed outside a list, or when you need its extra controls — `as`, `align`, `labelLines`, `descriptionLines`, and `layout`. Most screens only need `List` and `ListItem`.

### Anatomy

- **List title**: Heading that labels the list.
- **Description**: Supplementary text below the title.
- **List items**: Individual entries, which may include icons or images.
- **Item description**: Additional detail for an individual list item.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Give the list a `header`. A screen reader announces it on entering the list, and sighted users get the context of the collection immediately. |
| Do | Put icons, avatars, badges, or timestamps in `startContent` and `endContent`, so the two ends of a row carry the category and the status. |
| Do | Use `isSelected` to distinguish the current row and let the component pick `aria-selected` or `aria-current` from the row's role, instead of writing ARIA by hand. |
| Do | Set `descriptionLines` when the length of the content varies, or rely on the default single-line truncation for string descriptions, so the row height does not jump. |
| Do | Use `edge` to line row text up with a heading above the list: `flush` for static rows, `outset` or `bleed` for rows inside a Card, Section, or BottomSheet. |
| Don't | Nest a second control inside an interactive row as its main action. The row's button already fills the content area, and two click targets make the focus order and the behaviour hard to predict. |
| Don't | Use a list for a single entry. A list means the entries belong together; a short paragraph reads more naturally for one item. |
| Don't | Mix interactive and static rows in one list without a visible difference, leaving users unsure which rows open something. |

## Examples

### Basic

Simple list with labels and descriptions for settings-style layouts.

```vue
<script setup lang="ts">
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <List>
    <ListItem label="Notifications" description="Manage your alerts" />
    <ListItem label="Privacy" description="Control your data" />
    <ListItem label="Security" description="Password and 2FA" />
  </List>
</template>
```

### Bulleted features

Bulleted list of feature highlights using disc markers.

```vue
<script setup lang="ts">
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <List list-style="disc">
    <ListItem label="Accessible by default" />
    <ListItem label="Themeable with StyleX" />
    <ListItem label="Composable and extensible" />
  </List>
</template>
```

### Message list

Chat-style message list with avatars, preview text, and unread badges.

```vue
<script setup lang="ts">
import { Avatar } from '@astryx-vue/core/Avatar'
import { Badge } from '@astryx-vue/core/Badge'
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <List has-dividers>
    <ListItem label="Alex Johnson" description="Hey, are we still on for lunch tomorrow?" @click="() => {}">
      <template #startContent>
        <Avatar name="Alex Johnson" :size="40" />
      </template>
      <template #endContent>
        <Badge>2</Badge>
      </template>
    </ListItem>
    <ListItem label="Sam Rivera" description="I pushed the latest changes to the repo" @click="() => {}">
      <template #startContent>
        <Avatar name="Sam Rivera" :size="40" />
      </template>
    </ListItem>
    <ListItem label="Jordan Lee" description="Can you review the design spec when you get a chance?" @click="() => {}">
      <template #startContent>
        <Avatar name="Jordan Lee" :size="40" />
      </template>
      <template #endContent>
        <Badge>5</Badge>
      </template>
    </ListItem>
  </List>
</template>
```

### Ordered steps

Numbered step-by-step instructions using decimal list markers.

```vue
<script setup lang="ts">
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <List list-style="decimal">
    <ListItem label="Install the package" description="npm install @astryxdesign/core" />
    <ListItem label="Import components" description="import { List } from '@astryxdesign/core'" />
    <ListItem label="Start building" description="Use components in your app" />
  </List>
</template>
```

### Swipe actions

A touch drag reveals Archive. A mouse drag does not start, so the same action stays in the row.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { List, ListItem } from '@astryx-vue/core/List'
import { ref } from 'vue'

const note = ref('Swipe the row on a touch screen. Archive stays in the row for keyboard and mouse.')

function archive(): void {
  note.value = 'Archived.'
}
</script>

<template>
  <List>
    <ListItem
      label="Invoice 1042"
      description="Due Friday"
      :swipe-actions="{ trailing: [{ label: 'Archive', onActivate: archive, variant: 'accent' }] }"
    >
      <template #endContent>
        <Button label="Archive" size="sm" variant="secondary" @click="archive" />
      </template>
    </ListItem>
  </List>
  <p>{{ note }}</p>
</template>
```

### Flush rows

Static rows with flush drop their inline padding, so text, dividers, and backgrounds all sit on the heading's line.

```vue
<script setup lang="ts">
import { Heading } from '@astryx-vue/core/Heading'
import { List, ListItem } from '@astryx-vue/core/List'
</script>

<template>
  <div class="list-preview__section">
    <Heading :level="4">
      Shipping
    </Heading>
    <List edge="flush" has-dividers>
      <ListItem label="Standard" description="Arrives in 5–7 days" />
      <ListItem label="Express" description="Arrives tomorrow" />
      <ListItem label="Pickup" description="Ready at the counter" />
    </List>
  </div>
</template>
```

### Edge in a card

Interactive rows in a Card use outset so text lines up with the heading while backgrounds keep their room; bleed runs rows to the card's edges with square corners, like table rows.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { List, ListItem } from '@astryx-vue/core/List'
import { VStack } from '@astryx-vue/core/Stack'
import { ref } from 'vue'

const outsetSelected = ref('mentions')
const bleedSelected = ref('mentions')
</script>

<template>
  <div class="list-preview__stack">
    <Card :width="360">
      <VStack :gap="2">
        <Heading :level="4">
          Outset rows
        </Heading>
        <List edge="outset" has-dividers>
          <ListItem
            label="Mentions"
            description="Comments that name you"
            :is-selected="outsetSelected === 'mentions'"
            @click="outsetSelected = 'mentions'"
          />
          <ListItem
            label="Follows"
            description="New followers this week"
            :is-selected="outsetSelected === 'follows'"
            @click="outsetSelected = 'follows'"
          />
        </List>
      </VStack>
    </Card>
    <Card :width="360">
      <VStack :gap="2">
        <Heading :level="4">
          Bleed rows
        </Heading>
        <List edge="bleed" has-dividers>
          <ListItem
            label="Mentions"
            description="Comments that name you"
            :is-selected="bleedSelected === 'mentions'"
            @click="bleedSelected = 'mentions'"
          />
          <ListItem
            label="Follows"
            description="New followers this week"
            :is-selected="bleedSelected === 'follows'"
            @click="bleedSelected = 'follows'"
          />
        </List>
      </VStack>
    </Card>
  </div>
</template>
```

## Props

### List

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `density` | `ListDensity` | `'balanced'` | Spacing density for the rows: compact (4px of block padding), balanced (8px), or spacious (12px, which also widens the inline padding by one step). A single row can override it with its own `density`. |
| `hasDividers` | `boolean` | `false` | Whether to rule a line between neighbouring rows. The last row never draws one, and rows lose their rounded corners while dividers are on. |
| `edge` | `'padded' \| 'flush' \| 'outset' \| 'bleed'` | `'padded'` | Where each row's text, dividers, and hover and selection backgrounds sit relative to the list's edges and the padding of the container around it. `padded` keeps the row's own inline padding. `flush` removes it, so text starts on the line of a heading above the list and lines and backgrounds stop at the text. `outset` keeps text on that line and lets lines and backgrounds reach into the container's padding. `bleed` puts text on the container's padding line and runs lines and backgrounds to its edges with square corners, like table rows. A row's first content — its marker, icon, or avatar, otherwise its label — is what lines up with the heading. `outset` and `bleed` read the padding published by the nearest container that shares it (Card, Section, BottomSheet, a padded ScrollableArea, or a Layout region) and look like `padded` when there is none. |
| `edgeCompensation` | `'inline'` | - | Deprecated: use `edge="outset"`, which this sets. Still works; `edge` wins when both are set. |
| `listStyle` | `ListMarkerStyle` | `'none'` | The marker drawn in front of each row: none, disc (filled bullet), circle (outlined bullet), or decimal (numbers). `decimal` renders the list as an `<ol>`. |
| `start` | `number` | `1` | The first number of an ordered list, only used when `listStyle="decimal"`. It is written both to the `start` attribute of the `<ol>` and to the CSS counter. |
| `header` | `string` | - | Plain-text title rendered above the list and associated with it through `aria-labelledby`. Use the `header` slot for rich content. |

### ListItem

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string \| number` | - | The primary text identifying the row. A string or a number truncates to one line; use the `label` slot for rich content. |
| `description` | `string \| number` | - | Secondary text below the label, also truncated to one line. Use the `description` slot for multiple lines or rich content. |
| `density` | `ItemDensity` | - | Overrides the density of the surrounding `List`. When omitted the row inherits the list's density, or balanced outside a list. |
| `onClick` | `(event: MouseEvent) => void` | - | Click handler. It renders a button that fills the row's content area and enables the hover and pressed states. Write `@click` in a template. |
| `interactiveRef` | `MaybeRefOrGetter` | - | A ref to a control inside the row that already carries its keyboard access and action, such as a checkbox in `startContent`. The row becomes an enlarged click target that forwards surface clicks to that control and renders no button of its own, so it adds no second tab stop. Mutually exclusive with `onClick` and `href`, which are ignored while it is set. |
| `href` | `string` | - | Link URL. A link element is rendered inside the row. |
| `target` | `'_blank' \| '_self'` | - | Where the link opens, only used with `href`. `_blank` automatically adds `noopener` and `noreferrer`. |
| `rel` | `string` | - | Link relationship tokens, merged and de-duplicated with the ones added automatically. |
| `isDisabled` | `boolean` | `false` | Disabled state. The row becomes inert, its content dims, and `aria-disabled="true"` is written. A row that carries its own `role` is left non-inert, because its parent owns the interaction. |
| `isSelected` | `boolean` | `false` | Selected state. Written as `aria-selected="true"` when the role permits it, and as `aria-current="true"` otherwise. An `aria-current` you pass yourself wins. |

### Item

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `string \| Component` | `'div'` | The root element. Give a component only when the row carries a `role`, so the parent keeps keyboard access and the row adds no second tab stop. |
| `align` | `'center' \| 'start'` | `'center'` | Vertical alignment of the start and end content slots. Use `start` when either end is taller than one line of text. |
| `labelLines` | `number` | - | Maximum lines before the label truncates. A string label truncates to one line when this is omitted; slot content is never truncated. |
| `descriptionLines` | `number` | - | Maximum lines before the description truncates. A string description truncates to one line when this is omitted; slot content is left alone in a stacked layout. |
| `layout` | `'stacked' \| 'inline'` | `'stacked'` | How the label and description sit together. `inline` shares one line and ellipsizes the description first, keeping the row height fixed for hosts such as a trigger. |
| `isHighlighted` | `boolean` | `false` | The highlighted appearance, which is what keyboard focus and hover paint. Menu-like components use it for the row they have moved to. |

`Item` also accepts everything `ListItem` accepts: `label`, `description`, `density`, `onClick`, `interactiveRef`, `href`, `target`, `rel`, `isDisabled`, and `isSelected`.

`swipeActions` are the actions a touch drag reveals. `leading` opens when the row is dragged toward its end, and `trailing` opens toward its start. `swipeBehavior` defaults to `reveal`, which stays open after release. `commit` slides out and runs the outermost action once the drag passes the threshold, and that side should hold one action. A mouse drag does not start, so each action also needs a control in the row itself.

## Slots

### List

| Name | Description |
| --- | --- |
| `default` | The entries of the list, usually `ListItem`. |
| `header` | Content rendered above the list, associated with it through `aria-labelledby`. |

### ListItem / Item

| Name | Description |
| --- | --- |
| `startContent` | Content before the label: an icon, an avatar, or a checkbox. |
| `label` | Rich content replacing the `label` prop. It is exempt from the automatic truncation. |
| `description` | Rich content replacing the `description` prop. |
| `endContent` | Content after the label: a badge, a timestamp, or a chevron. |
| `marker` | The marker drawn at the head of the row as a direct child. `Item` exposes it; `ListItem` fills it from the list's `listStyle`. |

## Exposed

| Name | Signature | Description |
| --- | --- | --- |
| `element` | `ComputedRef` | The list element itself. A list with a header is wrapped, and this is still the list element inside the wrapper. |

`ListItem` and `Item` also expose <code>element</code> (the root element), <code>focus()</code>, and <code>blur()</code>; focusing lands on the control inside the row that can actually take focus.

## Native attributes

### List

The root element is a `<ul>`, or an `<ol>` when <code>listStyle="decimal"</code>. A header adds a wrapper element around it.

The following go to the list element:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.

The component writes `role="list"`, `data-density`, `data-dividers`, `data-list-style`, and `data-edge` (the resolved `padded`, `flush`, `outset`, or `bleed`), plus `data-edge-compensation` while the deprecated prop is set. Without a rendered header an `aria-labelledby` you pass is kept; with one, the list's own header takes over.

### ListItem / Item

The root element is a `<div>` by default, and an `<li>` for `ListItem`.

The following go to the root element:

- HTML attributes such as `role` and `id`.
- `aria-*` attributes. An `aria-current` you pass wins over the one derived from the selected state.
- `data-*` attributes.
- `class`.
- `style`.

The component writes `data-density`, `data-align`, `data-interactive`, `data-selected`, `data-disabled`, `data-highlighted`, `data-inert`, `aria-disabled`, and the derived `aria-selected` / `aria-current`. Those are not overridden by an attribute of the same name passed in.
