<!-- Generated from src/docs/list-rows.mdx by scripts/build-docs.ts. Do not edit. -->

# Lists and tables

Use a table to compare information across columns, or a list to browse items and act on them. Shade keeps rows aligned and makes their links and buttons easier to use.

## Choose a component

| Component          | When to use it                                                                                                                                                                |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Table`            | People need to compare the same details across many items, such as members' names, email addresses, and statuses.                                                             |
| `List`             | People browse items such as posts, members, or settings. A row can show a title, description, picture, link, or extra buttons.                                                |
| `RowPrimaryAction` | An existing custom row needs a main link or button that people can click from anywhere in the row. Use it inside `ListItem`; use its `TableRowAction` name inside `TableRow`. |
| `rowSurface`       | You need Shade's row backgrounds on custom markup that cannot use the components above. This is a styling helper; your code still needs to handle actions and touch presses.  |

These components work in pages, cards, dialogs, and settings. Rows with no
main action, such as comments, can still contain buttons. Leave those rows
without a hover background so they do not look clickable.

## Make a row clickable

A row's **main action** is what happens when someone clicks it: for example,
opening a post. Other controls, such as an Edit button, checkbox, or drag handle,
keep their own actions. Clicking one of those controls must not also open the row.

Shade keeps standard links, buttons, form controls and their labels above the
row's clickable area automatically. Mark a custom control with
`data-row-secondary` so it gets the same treatment. Put the marker on the
control itself, so gaps around it still open the row.

### Lists

Put the main link or button in `ListItemContent asChild`. Put other
buttons in `ListItemActions`. Shade makes the whole row, including its
highlighted edges, activate the main link or button.

Use `hover={false}` on `ListItem` when only the individual controls
should look clickable. This hides the row highlight and stops empty row space from activating the
main control. Its buttons and links still work normally when clicked directly.

### Custom rows

Use `ListItem asChild` to keep an existing `li` or `div` as the row.
Wrap its main link or button in `RowPrimaryAction asChild`:

```tsx
<ListItem asChild>
  <li>
    <RowPrimaryAction asChild>
      <a href="/members/ada">Ada Lovelace</a>
    </RowPrimaryAction>
  </li>
</ListItem>
```

`asChild` keeps the link or button you provide rather than adding another
button around it. The link still opens its own URL, including in a new tab.
For an action rather than a destination, use a button with an `onClick` handler.

### Table rows

Use `TableRowAction asChild` around the main link or button in a `TableRow`:

```tsx
<TableRow>
  <TableCell className="static">
    <TableRowAction asChild>
      <a href="/posts/example">Example post</a>
    </TableRowAction>
  </TableCell>
  <TableCell>Published</TableCell>
</TableRow>
```

The rest of the row now opens the same link. A row with no main link, button,
or row click handler gets no hover background. Column headings and table
footers get no hover background either.

For new code, use links for destinations and buttons for actions. When updating
an older clickable `div` or `span`, `RowPrimaryAction` also makes it focusable
and lets Enter or Space activate it.

## Shared defaults

Rows behave the same in the current and upcoming Admin UI, with `admin7Design`
on or off. `TableRow` and `ListItem` handle highlighting, touch presses,
and clicks on the empty space around the main link. You do not need to repeat
that code in each screen. Your screen still decides where a link goes, what a
button does, and who is allowed to use it.

A row’s own `onClick` takes precedence over forwarding to its main control.
Remove handlers that only click the main link; Shade already does that and
preserves modifier keys. Keep handlers that perform a different row action.

## Spacing and dividing lines

Line up row content with the page or section heading and with the table's
column headings. Keep spacing between columns, but remove padding at the
outside edges. Row content stays in the same place when highlighted.

The rounded background extends **16px on each side** into the space beside the
list. If there is less room, reduce the extension so it fits. It should not be
cut off or create a horizontal scrollbar. Keep existing scrolling, fixed
columns, and rendering of long lists working as before.

When a row is highlighted, hide the dividing lines immediately above and
below it. Keep the line below the column headings and any border around the
whole card or table. Hiding a line must not change row height.

## Hover, keyboard, selection, and touch

| When someone…                                     | What the row does                                                                                                                        |
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Moves the pointer over a clickable row            | Shows the rounded background and hides the dividing lines above and below it.                                                            |
| Tabs to a link or button in a clickable row       | Shows the same background, with a visible focus ring on the actual link or button.                                                       |
| Selects a row                                     | Keeps the selection background visible, using the stronger selection color.                                                              |
| Selects neighboring rows                          | Keeps a separate rounded background for each row, without adding gaps.                                                                   |
| Presses a row on a touch screen                   | Shows the background during the press, then clears it on release, cancellation, or scrolling. A tap runs the row’s main action directly. |
| Drags an item to reorder it                       | Hides ordinary hover and focus backgrounds during the drag. Selection remains visible, and the dragged item keeps its drag styling.      |
| Uses a row with no main action, or a disabled row | Gets no hover background or extra row action. Any available buttons and links still work.                                                |

## Custom layout details

Use `Table` and `List` where possible. If you need a custom layout, these
settings help keep its rows working the same way:

- Set `data-state="selected"` on selected rows.
- Keep elements between the main link and the row at `position: static` so the
  link's clickable area can cover the row. This is why the table example uses
  `className="static"` on its first cell. Standard controls already stay above
  that clickable area; use `data-row-secondary` for a custom control.
- Use `rowSurfaceClasses.inset` when a scrolling container has no room for a
  highlight outside its edges. The highlight will stay inside the row.
- When columns disappear on smaller screens, add `max-sm:shade-row-end` or a
  matching breakpoint to the last visible cell. This keeps its rounded edge
  and removes its outside padding. Use `rowSurfaceClasses.end` when that cell
  is always last.
- `SortableList` handles the drag state for its rows. For a custom drag
  implementation, set `data-row-dragging="true"` on the list during the drag.

Try the **Table**, **List**, **Row Primary Action**, **Sortable List**,
and **Row Surface** examples to see these behaviors.

## Updating existing lists

The older `ActionList`, `ActionListItem`, `ActionListItemContent`, and
`ActionListItemActions` names still work. Use the shorter `List` names in new
code; existing apps can switch names without changing how their lists behave.

## Lists with their own appearance

`DataList` keeps its existing data bars, hover effects, and sliding values.
Navigation, menu options, and full feed or article cards use their own
components. ActivityPub keeps its existing custom rows and is outside this
Admin update.
