# Scroll Area

> A native scroll container with Dify overlay scrollbars.

```tsx title="hero.tsx"
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
import * as React from 'react'

const activity = [
  { time: '10:42', note: 'Maya published version 14 of Customer support bot.' },
  { time: '10:15', note: 'Leo added 3 documents to the Product FAQ knowledge base.' },
  { time: '09:58', note: 'The nightly sync workflow finished without errors.' },
  { time: '09:31', note: 'Ana changed the default model for all new apps.' },
  { time: '09:07', note: 'Maya invited sam@example.com as an editor.' },
  { time: '08:44', note: 'The HTTP request node in Order lookup retried twice.' },
  { time: '08:20', note: 'Leo enabled annotation replies for Customer support bot.' },
]

export function ScrollAreaHeroDemo() {
  const titleId = React.useId()

  return (
    <div className="flex w-full max-w-80 flex-col gap-2">
      <p id={titleId} className="system-sm-semibold text-text-primary">
        Recent activity
      </p>
      <ScrollArea className="h-56 rounded-xl">
        <ScrollAreaViewport
          role="region"
          aria-labelledby={titleId}
          className="border-[0.5px] border-components-panel-border bg-components-panel-bg"
        >
          <ScrollAreaContent style={{ minWidth: 0 }}>
            <ul className="flex flex-col py-1.5 ps-3 pe-4">
              {activity.map((entry) => (
                <li key={entry.time} className="flex gap-3 py-1.5">
                  <span className="shrink-0 pt-px system-xs-regular text-text-tertiary tabular-nums">
                    {entry.time}
                  </span>
                  <span className="system-sm-regular text-pretty text-text-secondary">
                    {entry.note}
                  </span>
                </li>
              ))}
            </ul>
          </ScrollAreaContent>
        </ScrollAreaViewport>
        <ScrollAreaScrollbar>
          <ScrollAreaThumb />
        </ScrollAreaScrollbar>
      </ScrollArea>
    </div>
  )
}
```

## Usage guidelines

- Use `ScrollArea` for a fixed-size panel, list or code block whose content can overflow. Let the page itself scroll natively.
- `ScrollAreaViewport` is the element that scrolls and takes focus. Put scroll refs, `onScroll`, `role`, the accessible name and overscroll behavior on the viewport, not on the root.
- The viewport becomes a `Tab` stop whenever its content overflows, so name what it scrolls: add `role="region"` with `aria-labelledby` pointing at a visible title, otherwise with `aria-label`.
- Wrap the content in `ScrollAreaContent`. It keeps the scrollbars in sync when the content changes size.
- Base UI sets the viewport's `overflow` and the content's `min-width` inline. Override them with `style`, such as `style={{ minWidth: 0 }}` on `ScrollAreaContent` so a vertical list truncates long text; `min-w-0` and `overflow-*` utilities do not apply.
- Render one `ScrollAreaScrollbar` per scrolling axis. Add `ScrollAreaCorner` when both axes scroll.
- `ScrollAreaScrollbar` stays hidden at rest and reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. Override `className` with `pointer-events-auto opacity-100` if a surface requires a persistent scrollbar.

## Anatomy

```tsx
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaCorner,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
```

```tsx
<ScrollArea>
  <ScrollAreaViewport>
    <ScrollAreaContent />
  </ScrollAreaViewport>
  <ScrollAreaScrollbar>
    <ScrollAreaThumb />
  </ScrollAreaScrollbar>
  <ScrollAreaCorner />
</ScrollArea>
```

The root draws the focus ring above the content when the viewport has keyboard focus, so the ring is not clipped or masked by the scrolling content.

## Examples

### Truncating a vertical list

`style={{ minWidth: 0 }}` on `ScrollAreaContent` lets long file names truncate instead of adding a horizontal scroll.

```tsx title="truncation.tsx"
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'

const files = [
  'customer-support-playbook-2026-q3-final-reviewed.pdf',
  'pricing.md',
  'product-faq-with-troubleshooting-steps-for-self-hosted-deployments.docx',
  'refund-policy.txt',
  'api-reference-export-generated-from-openapi-schema.html',
  'onboarding-checklist.xlsx',
  'release-notes-archive-including-all-patch-versions.md',
  'security-whitepaper.pdf',
]

export function ScrollAreaTruncationDemo() {
  return (
    <ScrollArea className="h-48 w-full max-w-72 rounded-xl">
      <ScrollAreaViewport
        role="region"
        aria-label="Uploaded documents"
        className="border-[0.5px] border-components-panel-border bg-components-panel-bg"
      >
        <ScrollAreaContent style={{ minWidth: 0 }}>
          <ul className="flex flex-col gap-0.5 p-2">
            {files.map((file) => (
              <li
                key={file}
                className="flex h-8 min-w-0 items-center gap-2 rounded-lg px-2 text-text-secondary"
              >
                <span aria-hidden="true" className="i-ri-file-text-line size-4 shrink-0" />
                <span className="min-w-0 truncate system-sm-regular">{file}</span>
              </li>
            ))}
          </ul>
        </ScrollAreaContent>
      </ScrollAreaViewport>
      <ScrollAreaScrollbar>
        <ScrollAreaThumb />
      </ScrollAreaScrollbar>
    </ScrollArea>
  )
}
```

### Horizontal

Set `orientation="horizontal"` on the scrollbar for a row that overflows sideways.

```tsx title="horizontal.tsx"
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'

const nodes = [
  'Start',
  'Question classifier',
  'Knowledge retrieval',
  'LLM',
  'Code',
  'HTTP request',
  'Template',
  'Answer',
]

export function ScrollAreaHorizontalDemo() {
  return (
    <ScrollArea className="w-full max-w-md rounded-xl">
      <ScrollAreaViewport
        role="region"
        aria-label="Workflow nodes"
        className="border-[0.5px] border-components-panel-border bg-components-panel-bg"
      >
        <ScrollAreaContent>
          <ol className="flex gap-2 p-3 pb-5">
            {nodes.map((node, index) => (
              <li
                key={node}
                className="flex shrink-0 items-center gap-2 rounded-lg border-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg px-3 py-2 system-sm-medium whitespace-nowrap text-text-secondary"
              >
                <span className="system-xs-regular text-text-tertiary">{index + 1}</span>
                {node}
              </li>
            ))}
          </ol>
        </ScrollAreaContent>
      </ScrollAreaViewport>
      <ScrollAreaScrollbar orientation="horizontal">
        <ScrollAreaThumb />
      </ScrollAreaScrollbar>
    </ScrollArea>
  )
}
```

### Scroll fade

The viewport exposes `--scroll-area-overflow-y-start` and `--scroll-area-overflow-y-end`. Use them in a mask so the edges fade only when there is more content in that direction, and give each `var()` a fallback so the mask is valid before hydration.

```tsx title="scroll-fade.tsx"
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'

const paragraphs = [
  'You are a support assistant for a cloud storage product. Answer in the language the user writes in.',
  'Use the retrieved knowledge as the only source of facts. When the context does not cover the question, say so and suggest contacting support.',
  'Keep answers under 120 words. Use a numbered list for steps and inline code for settings, paths and commands.',
  'Never ask for passwords, recovery codes or payment details. If the user shares one, tell them to rotate it.',
  'When the user reports data loss, collect the account email, the affected folder and the time it was last seen before suggesting a restore.',
]

export function ScrollAreaScrollFadeDemo() {
  return (
    <ScrollArea className="h-48 w-full max-w-80 rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg">
      <ScrollAreaViewport
        role="region"
        aria-label="System prompt"
        className="mask-linear-[to_bottom,transparent_0,black_min(40px,var(--scroll-area-overflow-y-start,0px)),black_calc(100%-min(40px,var(--scroll-area-overflow-y-end,40px))),transparent_100%] mask-no-repeat"
      >
        <ScrollAreaContent style={{ minWidth: 0 }}>
          <div className="flex flex-col gap-3 py-3 ps-4 pe-6 system-sm-regular text-text-secondary">
            {paragraphs.map((paragraph) => (
              <p key={paragraph}>{paragraph}</p>
            ))}
          </div>
        </ScrollAreaContent>
      </ScrollAreaViewport>
      <ScrollAreaScrollbar>
        <ScrollAreaThumb />
      </ScrollAreaScrollbar>
    </ScrollArea>
  )
}
```

### Both axes

Render a vertical and a horizontal `ScrollAreaScrollbar` together with `ScrollAreaCorner` when content overflows in both directions, such as a wide log table.

```tsx title="both-axes.tsx"
import {
  ScrollArea,
  ScrollAreaContent,
  ScrollAreaCorner,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'

const runs = [
  {
    id: 'run_8421',
    workflow: 'Customer support bot',
    trigger: 'Webhook',
    model: 'gpt-4.1-mini',
    tokens: '1,420',
    latency: '1.14s',
    status: 'Succeeded',
  },
  {
    id: 'run_8420',
    workflow: 'Order lookup',
    trigger: 'API',
    model: 'claude-3-7-sonnet',
    tokens: '2,890',
    latency: '1.86s',
    status: 'Succeeded',
  },
  {
    id: 'run_8419',
    workflow: 'Nightly knowledge sync',
    trigger: 'Schedule',
    model: 'text-embedding-3-large',
    tokens: '18,240',
    latency: '4.32s',
    status: 'Succeeded',
  },
  {
    id: 'run_8418',
    workflow: 'Ticket triage',
    trigger: 'Webhook',
    model: 'gpt-4.1-mini',
    tokens: '960',
    latency: '0.82s',
    status: 'Failed',
  },
  {
    id: 'run_8417',
    workflow: 'Release notes draft',
    trigger: 'Manual',
    model: 'claude-3-7-sonnet',
    tokens: '4,115',
    latency: '2.49s',
    status: 'Succeeded',
  },
  {
    id: 'run_8416',
    workflow: 'Refund eligibility check',
    trigger: 'API',
    model: 'gpt-4.1',
    tokens: '1,735',
    latency: '1.37s',
    status: 'Succeeded',
  },
  {
    id: 'run_8415',
    workflow: 'Product FAQ retrieval',
    trigger: 'API',
    model: 'gpt-4.1-mini',
    tokens: '1,180',
    latency: '0.94s',
    status: 'Succeeded',
  },
  {
    id: 'run_8414',
    workflow: 'Invoice parser',
    trigger: 'Webhook',
    model: 'gemini-2.5-flash',
    tokens: '3,050',
    latency: '1.63s',
    status: 'Succeeded',
  },
] as const

export function ScrollAreaBothAxesDemo() {
  return (
    <ScrollArea className="h-56 w-full max-w-md rounded-xl">
      <ScrollAreaViewport
        role="region"
        aria-label="Workflow run logs"
        className="border-[0.5px] border-components-panel-border bg-components-panel-bg"
      >
        <ScrollAreaContent className="pe-3 pb-3">
          <table className="w-max border-collapse text-start">
            <thead>
              <tr className="border-b border-divider-subtle text-text-tertiary">
                <th scope="col" className="px-3 py-2 text-start system-xs-medium whitespace-nowrap">
                  Run
                </th>
                <th scope="col" className="px-3 py-2 text-start system-xs-medium whitespace-nowrap">
                  Workflow
                </th>
                <th scope="col" className="px-3 py-2 text-start system-xs-medium whitespace-nowrap">
                  Trigger
                </th>
                <th scope="col" className="px-3 py-2 text-start system-xs-medium whitespace-nowrap">
                  Model
                </th>
                <th scope="col" className="px-3 py-2 text-end system-xs-medium whitespace-nowrap">
                  Tokens
                </th>
                <th scope="col" className="px-3 py-2 text-end system-xs-medium whitespace-nowrap">
                  Latency
                </th>
                <th scope="col" className="px-3 py-2 text-start system-xs-medium whitespace-nowrap">
                  Status
                </th>
              </tr>
            </thead>
            <tbody className="divide-y divide-divider-subtle">
              {runs.map((run) => (
                <tr key={run.id} className="text-text-secondary">
                  <td className="px-3 py-2 font-mono system-xs-regular whitespace-nowrap text-text-tertiary">
                    {run.id}
                  </td>
                  <td className="px-3 py-2 system-sm-medium whitespace-nowrap text-text-primary">
                    {run.workflow}
                  </td>
                  <td className="px-3 py-2 system-sm-regular whitespace-nowrap">{run.trigger}</td>
                  <td className="px-3 py-2 font-mono system-xs-regular whitespace-nowrap">
                    {run.model}
                  </td>
                  <td className="px-3 py-2 text-end system-sm-regular whitespace-nowrap tabular-nums">
                    {run.tokens}
                  </td>
                  <td className="px-3 py-2 text-end system-sm-regular whitespace-nowrap tabular-nums">
                    {run.latency}
                  </td>
                  <td className="px-3 py-2 system-sm-regular whitespace-nowrap">{run.status}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </ScrollAreaContent>
      </ScrollAreaViewport>
      <ScrollAreaScrollbar>
        <ScrollAreaThumb />
      </ScrollAreaScrollbar>
      <ScrollAreaScrollbar orientation="horizontal">
        <ScrollAreaThumb />
      </ScrollAreaScrollbar>
      <ScrollAreaCorner />
    </ScrollArea>
  )
}
```

## Keyboard

| Key                        | Action                                                                                                           |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `Tab`                      | Moves focus to the viewport when its content overflows. The root draws the focus ring and reveals the scrollbar. |
| `ArrowDown`, `ArrowUp`     | Scrolls the focused viewport down or up.                                                                         |
| `ArrowRight`, `ArrowLeft`  | Scrolls the focused viewport right or left.                                                                      |
| `PageDown`, `PageUp`       | Scrolls down or up by about one viewport height.                                                                 |
| `Space`, `Shift` + `Space` | Scrolls down or up by about one viewport height.                                                                 |
| `Home`, `End`              | Scrolls to the top or bottom.                                                                                    |

## API reference

### ScrollArea

Groups a scrollable viewport with custom overlay scrollbars. Renders a `<div>` element.

`ScrollAreaViewport` owns scroll refs, events, and focus; use inline `style` to override Base UI's inline `overflow` on Viewport or `minWidth` on Content.

Inherits `style`, `overflowEdgeThreshold`, `className`, `render` from [Base UI ScrollArea.Root](https://base-ui.com/react/components/scroll-area#root).

**Data attributes**

| Attribute               | Description                                                       |
| ----------------------- | ----------------------------------------------------------------- |
| `data-scrolling`        | Present when the user scrolls inside the scroll area.             |
| `data-has-overflow-x`   | Present when the scroll area content is wider than the viewport.  |
| `data-has-overflow-y`   | Present when the scroll area content is taller than the viewport. |
| `data-overflow-x-start` | Present when there is overflow on the horizontal start side.      |
| `data-overflow-x-end`   | Present when there is overflow on the horizontal end side.        |
| `data-overflow-y-start` | Present when there is overflow on the vertical start side.        |
| `data-overflow-y-end`   | Present when there is overflow on the vertical end side.          |

**CSS variables**

| Variable                      | Type     | Description                      |
| ----------------------------- | -------- | -------------------------------- |
| `--scroll-area-corner-height` | `number` | The scroll area's corner height. |
| `--scroll-area-corner-width`  | `number` | The scroll area's corner width.  |

### ScrollAreaContent

A container for the content of the scroll area. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI ScrollArea.Content](https://base-ui.com/react/components/scroll-area#content).

**Data attributes**

| Attribute               | Description                                                       |
| ----------------------- | ----------------------------------------------------------------- |
| `data-scrolling`        | Present when the user scrolls inside the scroll area.             |
| `data-has-overflow-x`   | Present when the scroll area content is wider than the viewport.  |
| `data-has-overflow-y`   | Present when the scroll area content is taller than the viewport. |
| `data-overflow-x-start` | Present when there is overflow on the horizontal start side.      |
| `data-overflow-x-end`   | Present when there is overflow on the horizontal end side.        |
| `data-overflow-y-start` | Present when there is overflow on the vertical start side.        |
| `data-overflow-y-end`   | Present when there is overflow on the vertical end side.          |

### ScrollAreaCorner

A small rectangular area that appears at the intersection of horizontal and vertical scrollbars. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI ScrollArea.Corner](https://base-ui.com/react/components/scroll-area#corner).

### ScrollAreaScrollbar

Overlay scrollbar track that reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. Renders a `<div>` element.

Inherits `orientation`, `keepMounted`, `className`, `render`, `style` from [Base UI ScrollArea.Scrollbar](https://base-ui.com/react/components/scroll-area#scrollbar).

**Data attributes**

| Attribute               | Description                                                       |
| ----------------------- | ----------------------------------------------------------------- |
| `data-orientation`      | Indicates the orientation of the scrollbar.                       |
| `data-hovering`         | Present when the pointer is over the scroll area.                 |
| `data-scrolling`        | Present when the user scrolls inside the scroll area.             |
| `data-has-overflow-x`   | Present when the scroll area content is wider than the viewport.  |
| `data-has-overflow-y`   | Present when the scroll area content is taller than the viewport. |
| `data-overflow-x-start` | Present when there is overflow on the horizontal start side.      |
| `data-overflow-x-end`   | Present when there is overflow on the horizontal end side.        |
| `data-overflow-y-start` | Present when there is overflow on the vertical start side.        |
| `data-overflow-y-end`   | Present when there is overflow on the vertical end side.          |

**CSS variables**

| Variable                     | Type     | Description                     |
| ---------------------------- | -------- | ------------------------------- |
| `--scroll-area-thumb-height` | `number` | The scroll area thumb's height. |
| `--scroll-area-thumb-width`  | `number` | The scroll area thumb's width.  |

### ScrollAreaThumb

The draggable part of the scrollbar that indicates the current scroll position. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI ScrollArea.Thumb](https://base-ui.com/react/components/scroll-area#thumb).

**Data attributes**

| Attribute          | Description                                           |
| ------------------ | ----------------------------------------------------- |
| `data-orientation` | Indicates the orientation of the scrollbar.           |
| `data-scrolling`   | Present when the user scrolls inside the scroll area. |

### ScrollAreaViewport

The actual scrollable container of the scroll area. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI ScrollArea.Viewport](https://base-ui.com/react/components/scroll-area#viewport).

**Data attributes**

| Attribute               | Description                                                       |
| ----------------------- | ----------------------------------------------------------------- |
| `data-scrolling`        | Present when the user scrolls inside the scroll area.             |
| `data-has-overflow-x`   | Present when the scroll area content is wider than the viewport.  |
| `data-has-overflow-y`   | Present when the scroll area content is taller than the viewport. |
| `data-overflow-x-start` | Present when there is overflow on the horizontal start side.      |
| `data-overflow-x-end`   | Present when there is overflow on the horizontal end side.        |
| `data-overflow-y-start` | Present when there is overflow on the vertical start side.        |
| `data-overflow-y-end`   | Present when there is overflow on the vertical end side.          |

**CSS variables**

| Variable                         | Type     | Description                                            |
| -------------------------------- | -------- | ------------------------------------------------------ |
| `--scroll-area-overflow-x-start` | `number` | The distance from the horizontal start edge in pixels. |
| `--scroll-area-overflow-x-end`   | `number` | The distance from the horizontal end edge in pixels.   |
| `--scroll-area-overflow-y-start` | `number` | The distance from the vertical start edge in pixels.   |
| `--scroll-area-overflow-y-end`   | `number` | The distance from the vertical end edge in pixels.     |
