ScrollBarRenderable provides visual scroll indicators with support for both vertical and horizontal orientations. It includes an interactive slider track and optional arrow buttons for navigation.
Import
Basic Usage
Scroll Properties
The scrollbar manages three key dimensions:Total size of the scrollable content. For vertical scrollbars, this is the total height of content. For horizontal scrollbars, this is the total width.
Size of the visible viewport. Determines the thumb size on the slider.
Current scroll position (0 to scrollSize - viewportSize). Automatically clamped to valid range.
Props
Direction of the scrollbar. Controls layout and keyboard navigation.
Whether to show arrow buttons at the start and end of the scrollbar for navigation.
Styling options for arrow buttons:
foregroundColor- Color of the arrow characterbackgroundColor- Background color of the arrow buttonattributes- Text attributes (bold, underline, etc.)arrowChars- Custom characters for arrows (up, down, left, right)
Options passed to the internal slider component. See Slider documentation for available options.
Callback fired when scroll position changes through user interaction.
Custom step size for “step” unit scrolling. Defaults to 1 if not set.
Methods
scrollBy()
Scroll by a delta amount with different units:delta(number) - Amount to scroll (can be negative)unit(ScrollUnit) - One of:"absolute"- Scroll by exact pixels (default)"viewport"- Multiply delta by viewport size"content"- Multiply delta by total content size"step"- Multiply delta by scrollStep value
resetVisibilityControl()
Reset automatic visibility behavior. By default, the scrollbar hides when content fits in viewport.Keyboard Navigation
The scrollbar responds to keyboard events when focused:| Key | Action |
|---|---|
↑ / k | Scroll up (vertical) by 20% of viewport |
↓ / j | Scroll down (vertical) by 20% of viewport |
← / h | Scroll left (horizontal) by 20% of viewport |
→ / l | Scroll right (horizontal) by 20% of viewport |
PageUp | Scroll backward by 50% of viewport |
PageDown | Scroll forward by 50% of viewport |
Home | Scroll to start |
End | Scroll to end |
Examples
Vertical Scrollbar with Arrows
Horizontal Scrollbar
Auto-hiding Scrollbar
Custom Scroll Steps
Child Components
The ScrollBarRenderable contains three child components:slider
ASliderRenderable instance that provides the draggable thumb and track.
startArrow / endArrow
Arrow buttons for navigation (up/left and down/right).Events
Fired when scroll position changes through user interaction (dragging slider, clicking arrows, or keyboard navigation).
Notes
- The scrollbar automatically hides when
scrollSize <= viewportSizeunless visibility is manually controlled - Scroll position is automatically clamped to valid range
[0, scrollSize - viewportSize] - Mouse interactions on arrows include hold-to-repeat behavior
- The component is focusable by default for keyboard navigation
Source
View the full source code atpackages/core/src/renderables/ScrollBar.ts:19