组件

Scroll Area

A scroll container whose bar is a pencil "scroll mark": a graphite pull sliding down a faint gutter, gone over once more when a hand is on it. It fades in on hover or scroll, works in both directions, and is Radix underneath.

安装

terminal
npx shadcn@latest add @wobko/scroll-area

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Tags

Shadcn's list, with a pencil scroll mark instead of a bar. The mark fades in when the pointer is over the area or it scrolls, and the thumb is a graphite pull that slides down a faint gutter.

Horizontal strip

`orientation="horizontal"` shows only the horizontal mark. `bleed` pads the viewport by 12 px so the notes' shadows and any focus ring are not cut at the edge of the strip.

Both directions

`orientation="both"` shows both marks (here `type="always"`, so they stay in view); the corner where they meet stays empty. A scroll container with nothing focusable inside is reachable by keyboard in current browsers; the viewport draws a blue ring inside its edge when it has focus.

Message log

A real screen: a fixed-height log inside a card, with the newest line kept in view, `bleed` so the edge buttons keep their rings, and an input below. The scroll mark shows while the log is being scrolled.

Demo

Official `scroll-area-demo`: fifty version tags with a Separator between each. The box is a dashed pencil edge rather than `rounded-md border`, and the scroll mark is a graphite pull in a faint gutter. Scroll with the wheel, drag the mark, or focus the list and use the arrow keys.

Horizontal demo

Official `scroll-area-horizontal-demo`: a strip of figures that scrolls sideways under an explicit `ScrollBar orientation="horizontal"`. shadcn shows three stock photographs; here they are polaroids of drawn scenes, so nothing is fetched. `bleed` gives the viewport 12 px so the photos' shadows are not cut at the edge.

API 参考

ScrollArea

The Radix Scroll Area root with its viewport, a vertical mark and the corner. The root clips (that is how scrolling works): use `bleed` when children draw beyond their own box.

属性类型默认值说明
orientation"vertical" | "horizontal" | "both""vertical"Which marks to mount. Upstream always mounts the vertical one and lets you add `<ScrollBar orientation="horizontal" />` as a child; that still works. With `vertical` the content wrapper Radix adds is an ordinary block (Radix makes it `display: table`, as wide as the widest unbreakable line, so a `truncate` title in a list of cards pushed the cards out of the box); `horizontal` and `both` keep the table so a row of max-content width overflows and scrolls. A sideways row inside a `vertical` area needs a width of its own (`w-max`).
bleedbooleanfalsePad the viewport by 12 px so a child's focus ring, shadow or ink bleed is not cut at the edge of the scroll area.
type"auto" | "always" | "scroll" | "hover""hover"When the mark shows (Radix): on hover or scroll, whenever there is overflow, only while scrolling, or always.
scrollHideDelaynumber600How long the mark lingers after the pointer leaves (ms).

ScrollBar

The gutter and its thumb, each its own small drawing. The thumb's length follows the content; a thumb over 44 px gets two short cross-strokes at its middle.

属性类型默认值说明
orientation"vertical" | "horizontal""vertical"Which edge it lives on.
seedstring | number-Pins the hand. Default: derived from useId().

无障碍

  • Native scrolling: wheel, touch, keyboard (arrows, Space, PageUp/PageDown, Home/End) and scrollbar-less devices all work; the mark is an overlay for pointers and never the only way to scroll.
  • A scroll region with nothing focusable in it is reachable by keyboard in current browsers; the viewport draws a blue ring inside its edge when focused. If yours is not, give the content `tabIndex={0}` and a name.
  • The gutter and thumb are aria-hidden drawings; the thumb can be dragged and the gutter clicked, as in Radix.
  • Windows high contrast draws the thumb in the system text color. Reduced motion removes the fade.
  • Right-to-left content puts the vertical mark on the left: pass `dir="rtl"` to the root, as Radix asks.

源码

CLI 会复制进你项目的文件。

正在加载源码