---
title: "Scroll Area"
description: "Custom-styled scrollbars that keep native scrolling."
url: https://weme-ui.github.io/slim/components/scroll-area.md
---
# Scroll Area

内容超出时换成自定义滚动条。底下是 Reka UI `ScrollArea`，原生滚动还在。

## Installation

```bash
pnpm dlx @weme-ui/weme-ui add scroll-area
```

## Usage

```vue
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'

const items = [
  'Apple',
  'Banana',
  'Blueberry',
  'Cherry',
  'Grape',
  'Lemon',
  'Mango',
  'Orange',
  'Peach',
  'Pear',
  'Pineapple',
  'Strawberry',
  'Watermelon',
]
</script>

<template>
  <div class="flex items-center">
    <ScrollArea class="h-48 w-48">
      <div class="p-3 flex flex-col gap-2">
        <p v-for="item in items" :key="item" class="text-sm">
          {{ item }}
        </p>
      </div>
    </ScrollArea>
  </div>
</template>
```

## Props

| 属性              | 说明                                                                                                        | 类型                                                     | 默认值    |
| ----------------- | ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | --------- |
| `as`              | 渲染为的元素或组件（Reka UI `Primitive`）                                                                   | `AsTag \| Component`                                     | `'div'`   |
| `orientation`     | 滚动条方向；未传时横向和纵向都渲染                                                                          | `'horizontal' \| 'vertical'`                             | —         |
| `type`            | 滚动条何时可见：`auto` 溢出时、`always` 始终、`scroll` 滚动时、`hover` 悬停或滚动、`glimpse` 进入时短暂显示 | `'auto' \| 'always' \| 'scroll' \| 'hover' \| 'glimpse'` | `'hover'` |
| `scrollHideDelay` | 停止交互后隐藏滚动条的毫秒数。`type` 不是 `'scroll'` 时未传按 `0`；`'scroll'` 且未传时走 Reka 的 `600`      | `number`                                                 | `0`       |
| `dir`             | 阅读方向；未传时继承 `ConfigProvider`，否则按 LTR                                                           | `'ltr' \| 'rtl'`                                         | —         |
| `class`           | 根节点额外 class                                                                                            | `any`                                                    | —         |
| `ui`              | 覆盖 slots 样式（`root` / `viewport` / `scrollbar` / `thumb`）                                              | `Partial<ScrollAreaStyleSlots>`                          | —         |

## Slots

| 插槽      | 说明     |
| --------- | -------- |
| `default` | 滚动内容 |

## Accessibility

基于 Reka UI `ScrollArea`（`ScrollAreaRoot` / `ScrollAreaViewport`）。保留浏览器原生滚动，键盘滚动也走原生，平台之间不完全一样。

## Examples

### Orientation

```vue
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'

const items = [
  'Apple',
  'Banana',
  'Blueberry',
  'Cherry',
  'Grape',
  'Lemon',
  'Mango',
  'Orange',
  'Peach',
  'Pear',
  'Pineapple',
  'Strawberry',
  'Watermelon',
]
</script>

<template>
  <div class="flex flex-wrap gap-3 items-center">
    <ScrollArea orientation="vertical" class="h-48 w-40">
      <div class="p-3 flex flex-col gap-2">
        <p v-for="item in items" :key="item" class="text-sm">
          {{ item }}
        </p>
      </div>
    </ScrollArea>
    <ScrollArea orientation="horizontal" class="w-64">
      <div class="p-3 flex gap-3 w-max">
        <p v-for="item in items" :key="item" class="text-sm whitespace-nowrap">
          {{ item }}
        </p>
      </div>
    </ScrollArea>
  </div>
</template>
```

### Type

```vue
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'

const types = ['hover', 'always', 'scroll', 'auto', 'glimpse'] as const

const items = [
  'Apple',
  'Banana',
  'Blueberry',
  'Cherry',
  'Grape',
  'Lemon',
  'Mango',
  'Orange',
  'Peach',
  'Pear',
  'Pineapple',
  'Strawberry',
  'Watermelon',
]
</script>

<template>
  <div class="flex flex-wrap gap-3 items-center">
    <ScrollArea v-for="type in types" :key="type" :type="type" class="h-48 w-40">
      <div class="p-3 flex flex-col gap-2">
        <p v-for="item in items" :key="item" class="text-sm">
          {{ item }}
        </p>
      </div>
    </ScrollArea>
  </div>
</template>
```