# Scroll Area

> A box that scrolls with a thin themed scrollbar and edges that fade where there's more.

Page: https://uicontext.com/docs/components/scroll-area

Group: Primitives.

## When to use

A box that scrolls with a thin themed scrollbar and edges that fade where there's more. Use [Resizable Panels](https://uicontext.com/docs/components/resizable-panels.md) instead when people should choose how much room the content gets.

## Usage

```ts
import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"

const styles = stylex.create({ box: { maxBlockSize: 240 } })

export const Channels = <M>(h: Html.H<M>, names: ReadonlyArray<string>) =>
	ScrollArea(h, { label: "Channels", style: styles.box, children: [h.ul.children(names.map((n) => h.li.key(n).children(n)))] })
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A long list in a short box

The example the page opens with: Scroll Area in “A long list in a short box”.

This example also uses Avatar. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/avatar
```

```ts title="src/demo.ts" source="www/src/examples/scroll-area/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Avatar } from "./ui/uicontext/components/Avatar.ts"
import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"
import { workspace } from "./people.ts"

const styles = stylex.create({
	box: { inlineSize: "min(100%, 18rem)", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	head: { paddingBlock: space.md, paddingInline: space.lg, fontSize: font.sm, fontWeight: 600, color: color.fg, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line },
	scroll: { maxBlockSize: 280 },
	list: { margin: 0, padding: space.xs, listStyle: "none" },
	row: { display: "flex", alignItems: "center", gap: space.md, minBlockSize: 36, paddingInline: space.sm, fontSize: font.base, color: color.fg },
	name: { minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
})

const members = workspace.slice(0, 60)

// a channel's members: sixty people in a box the height of a few
export const ChannelMembers = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.box)).children(
		h.div.attrs(sx(styles.head)).children(`${members.length} members`),
		ScrollArea(h, {
			label: "Members",
			style: styles.scroll,
			children: [
				h.ul.attrs(sx(styles.list)).children(
					members.map((m) => h.li.key(m.id).attrs(sx(styles.row)).children(Avatar(h, { ...m, size: "xs", decorative: true }), h.span.attrs(sx(styles.name)).children(m.name))),
				),
			],
		}),
	)
```

### Sideways

`orientation: "horizontal"` scrolls a wide table inside a narrow card; the edge fades where there's more.

```ts title="src/horizontal.ts" source="www/src/examples/scroll-area/horizontal.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	box: { inlineSize: "min(100%, 30rem)" },
	table: { borderCollapse: "collapse", fontSize: font.sm, fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap" },
	cell: { paddingBlock: space.sm, paddingInline: space.lg, textAlign: "end", borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line, color: color.fg },
	head: { color: color.muted, fontWeight: 500 },
	first: { textAlign: "start", position: "sticky", insetInlineStart: 0, backgroundColor: color.panel },
	frame: { borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
})

const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
const rows: ReadonlyArray<readonly [string, ReadonlyArray<number>]> = [
	["New customers", [212, 198, 240, 266, 251, 280, 302, 295, 318, 331, 347, 362]],
	["Churned", [31, 28, 35, 30, 26, 33, 29, 27, 31, 25, 24, 22]],
	["Net revenue ($k)", [84, 86, 91, 97, 99, 104, 111, 113, 119, 124, 131, 138]],
]

// a year of numbers in a narrow card: it scrolls sideways, the first column stays put
export const MonthlyNumbers = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.box, styles.frame)).children(
		ScrollArea(h, {
			label: "Monthly numbers, 2026",
			orientation: "horizontal",
			children: [
				h.table.attrs(sx(styles.table)).children(
					h.thead.children(h.tr.children(h.th.attrs({ scope: "col", ...sx(styles.cell, styles.head, styles.first) }).children("2026"), months.map((m) => h.th.key(m).attrs({ scope: "col", ...sx(styles.cell, styles.head) }).children(m)))),
					h.tbody.children(
						rows.map(([label, values]) =>
							h.tr.key(label).children(
								h.th.attrs({ scope: "row", ...sx(styles.cell, styles.head, styles.first) }).children(label),
								values.map((v, i) => h.td.key(String(i)).attrs(sx(styles.cell)).children(v.toLocaleString("en-US"))),
							)),
					),
				),
			],
		}),
	)
```

### Sample data

The examples above import these files.

```ts title="src/people.ts" source="www/src/examples/_shared/people.ts"
import type { AvatarPerson } from "./ui/uicontext/components/Avatar.ts"

// People for avatars, pickers and mentions. Pictures are drawn inline, a head and shoulders on a
// soft backdrop, so the examples need no image files.

const portrait = (backdrop: string, skin: string, shirt: string, hair: string) =>
	`data:image/svg+xml,${encodeURIComponent(
		`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="${backdrop}"/><path d="M10 64c2-13 11-19 22-19s20 6 22 19z" fill="${shirt}"/><circle cx="32" cy="27" r="12" fill="${skin}"/><path d="M19 26c0-9 6-14 13-14s13 5 13 14c-3-5-8-7-13-7s-10 2-13 7z" fill="${hair}"/></svg>`,
	)}`

export const ada: AvatarPerson = { id: "ada", name: "Ada Lovelace", image: portrait("#dbe7f7", "#f1c7a5", "#3b5b8c", "#4a2f22"), presence: "active" }
export const ben: AvatarPerson = { id: "ben", name: "Ben Okafor", image: portrait("#f3e3d3", "#8d5a3b", "#2f6b4f", "#1d1410"), presence: "away" }
export const mira: AvatarPerson = { id: "mira", name: "Mira Patel", presence: "dnd" }
export const sam: AvatarPerson = { id: "sam", name: "Sam Rivera", image: portrait("#e6e1f5", "#d9a57e", "#7a3e8c", "#2b1c14"), presence: "offline" }
export const kenji: AvatarPerson = { id: "kenji", name: "Kenji Watanabe" }
export const lena: AvatarPerson = { id: "lena", name: "Lena Fischer", image: portrait("#e3f1e8", "#f4d2b8", "#b0413e", "#c8a165") }
export const omar: AvatarPerson = { id: "omar", name: "Omar Haddad" }
export const priya: AvatarPerson = { id: "priya", name: "Priya Raman", presence: "active" }
export const scout: AvatarPerson = { id: "scout", name: "Scout", agent: true }

export const reviewers: ReadonlyArray<AvatarPerson> = [ada, ben, mira, sam, kenji, lena, omar]

/** Names that break layouts, and a picture that never loads. */
export const worstPeople: ReadonlyArray<AvatarPerson> = [
	{ id: "aleksandra", name: "Aleksandra Wiśniewska-Kowalczyk", presence: "active" },
	{ id: "christopher", name: "Christopher Alexander Montgomery III" },
	{ id: "j", name: "J" },
	{ id: "fox", name: "🦊 Fox" },
	{ id: "xiuying", name: "王秀英", presence: "away" },
	{ id: "ngoc-han", name: "Đặng Thị Ngọc Hân" },
	{ id: "broken", name: "Dana Whitfield", image: "/missing/dana.jpg" },
	{ id: "relay", name: "Relay Customer Escalations Assistant", agent: true },
]

/** A big workspace: 1,284 members. */
export const workspace: ReadonlyArray<AvatarPerson> = Array.from({ length: 1284 }, (_, i) => {
	const first = ["Ada", "Ben", "Mira", "Sam", "Kenji", "Lena", "Omar", "Priya", "Jo", "Rafael", "Ines", "Tomas"][i % 12]!
	const last = ["Lovelace", "Okafor", "Patel", "Rivera", "Watanabe", "Fischer", "Haddad", "Raman", "Kim", "Silva", "Novak", "Berg"][Math.floor(i / 12) % 12]!
	return { id: `m${i}`, name: `${first} ${last}` }
})
```

## API reference

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `key` | `string` | — | Names the area among others in the same view; needed for more than one. |
| `label` | `string` | — | What the area holds, for screen readers when it takes focus: "Members". |
| `orientation` | `"vertical" \| "horizontal" \| "both"` | `vertical` | Which way it scrolls; `vertical` by default. |
| `fade` | `boolean` | `on` | Fade the edges where there's more to scroll to; on by default. |
| `children` (required) | `View.Children` | — | — |
| `style` | `Style` | — | StyleX styles for the box: its height or max height, a border, a radius. |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/scroll-area
```

With npm: `npx shadcn@latest add checkfu/uicontext/scroll-area`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/scroll-area`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/scroll-area`.

It writes these files:

- `src/ui/uicontext/components/ScrollArea.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/ScrollArea.ts](https://github.com/checkfu/uicontext/blob/main/src/ScrollArea.ts)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
