ScrollBar

ScrollBar controls a scroll position with optional arrows, keyboard input, and a draggable thumb. Use ScrollBox when the component must also own and clip scrollable children.

Availability

FieldAvailability
Package@opentui/core
Core renderableScrollBarRenderable
ReactUnavailable
SolidUnavailable
StatusBuilt-in Core renderable

Basic usage

Renderable API

OpenTUI preview

Run this example to open an interactive terminal.

Source code · typescript
import { ScrollBarRenderable, createCliRenderer } from "@opentui/core"

const renderer = await createCliRenderer()

const scrollbar = new ScrollBarRenderable(renderer, {
  id: "scrollbar",
  orientation: "vertical",
  height: 10,
  showArrows: true,
  trackOptions: {
    backgroundColor: "#222222",
    foregroundColor: "#888888",
  },
  onChange: (position) => {
    console.log("Scroll position:", position)
  },
})

// Connect the scrollbar to your content
scrollbar.scrollSize = 200
scrollbar.viewportSize = 20
scrollbar.scrollPosition = 0

renderer.root.add(scrollbar)
scrollbar.focus()
position: 0 / 180  ▲
                   ▀







viewport: 20 / 200 ▼

Keyboard controls

When focused, the scrollbar responds to:

  • Up/Down or k/j for vertical bars

  • Left/Right or h/l for horizontal bars

  • PageUp/PageDown to move by half the viewport

  • Home/End to jump to start/end

Properties

PropertyTypeDefaultDescription
orientation"vertical" or "horizontal"-Scrollbar direction
showArrowsbooleanfalseShow arrow buttons
arrowOptionsArrowOptions-Styling for arrow buttons
trackOptionsPartial<SliderOptions>-Styling for the track and thumb
scrollSizenumber0Total scrollable size
viewportSizenumber0Visible size of the viewport
scrollPositionnumber0Current scroll position
scrollStepnumber-Step size when scrollBy(..., "step")
onChange(position: number) => void-Fired when scroll position changes

Read Layout for viewport dimensions. Read Interaction, focus, and selection for keyboard and pointer behavior. Slider exposes the underlying continuous-value control without scroll semantics.

Changes0.7.0
0.7.0
core: A ScrollBar position is never negative. Before, a ScrollBox with content that fit the viewport could report a scrollTop or scrollLeft such as -7 while its content did not move. A ScrollBar’s onChange value and scrollPosition now agree, and with sticky bottom over short content, a sideways scroll no longer stops the box from following new content. (#1769)