# Scroll Area

A region that scrolls with the platform's own scrolling and an overlay scrollbar: a 4 px #c8c8c8 thumb that floats over the content's edge, never takes its space, and fades out when you stop scrolling and the pointer leaves.

- Beta: ready to use; its API can still change in a minor release.
- Category: Layout & surfaces

```tsx
import { ScrollArea } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for every region that scrolls, like a contact's activity or a long list in a panel. The scrollbar floats over the content and takes none of its width.
- Do: Give it a height, a `max-h-*` or a flex-1 parent in a dialog or drawer body. Without one it grows with its content and never scrolls.
- Do: Set `inList` inside a menu or listbox, so the area is never a tab stop between the list and its rows.
- Do: Set `aria-label`, like "Activity", when the region holds focusable content of its own, so a keyboard user knows where they are.
- Don't: Use `overflow-auto` or `overflow-scroll`. The operating system draws its own track, which takes width from the content, and lint rejects it.
- Don't: Set `horizontal` to fit a wide table into a narrow panel when the columns could wrap or drop. Sideways scrolling hides columns the reader can't tell are there.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Goes to the content: a scroll area with focusable content is no tab stop itself. |

## Related

- [Truncate](./truncate.md)
- [Table](./table.md)
- [Drawer](./drawer.md)

## Examples

What the examples import:

```tsx
import { ScrollArea } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const activity = [
  "Jane Citizen opened the costs agreement",
  "Ada Hartley called Jane Citizen (6 min)",
  "Settlement booked for 14 December",
  "Contract exchanged",
  "Deposit received in trust",
  "Searches ordered",
  "Ada Hartley added a note",
  "Opportunity created from the website form",
  "Jane Citizen replied by email",
  "Costs agreement sent",
  "Matter type set to Conveyancing · Purchase",
  "Referral source: Paddington Realty",
] as const;

const columns = [
  "Name",
  "Matter type",
  "Responsible",
  "Stage",
  "Value",
  "Created",
  "Last activity",
  "Source",
] as const;
```

### Vertical

Hover or scroll to see the thumb; it fades 600 ms after both stop. The text runs right to the edge because the scrollbar takes no space.

```tsx
<ScrollArea
  aria-label="Activity"
  className="border-neutral-border h-48 w-80 rounded-md border"
>
  <ul className="text-body flex flex-col gap-3 p-4">
    {activity.map(item => (
      <li key={item}>{item}</li>
    ))}
  </ul>
</ScrollArea>
```

### Both ways

horizontal adds a second thumb along the bottom for wide content, like a table.

```tsx
<ScrollArea
  horizontal
  aria-label="Opportunities"
  className="border-neutral-border h-40 w-96 rounded-md border"
>
  <table className="text-body text-left">
    <thead>
      <tr>
        {columns.map(column => (
          <th
            key={column}
            className="text-neutral-text-muted px-4 py-2 font-semibold whitespace-nowrap"
          >
            {column}
          </th>
        ))}
      </tr>
    </thead>
    <tbody>
      {activity.slice(0, 6).map(item => (
        <tr key={item}>
          {columns.map(column => (
            <td key={column} className="px-4 py-2 whitespace-nowrap">
              {column === "Name"
                ? item.split(" ").slice(0, 2).join(" ")
                : "—"}
            </td>
          ))}
        </tr>
      ))}
    </tbody>
  </table>
</ScrollArea>
```

## Props

ScrollArea takes ui-sdk's Scroll Area options: type (hover by default, or scroll, auto, always), scrollHideDelay, stickToEnd and controller.

### ScrollArea

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `scrollbarClassName` | `string` |  | Classes for the vertical scrollbar, like a top inset under a sticky header. |
| `horizontal` | `boolean` | `false` | Adds a horizontal scrollbar, for content wider than the area. |
| `aria-label` | `string` |  | Names the scrollable region when it holds focusable content of its own, like "Activity". |
| `inList` | `boolean` | `false` | Set inside a menu or listbox that moves its own highlight. Its arrow keys already scroll the highlight into view, so the area never becomes a tab stop, and it joins the list as an unnamed group so the list's structure stays valid (a focusable box isn't allowed between a list and its rows). |

### ScrollBar

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `orientation` | `unknown` | `"vertical"` |  |
