Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Scrollbar

The Scrollbar component provides a consistent look and feel for scrollbars across multiple platforms and browsers.

Import

Usage

The scrollbar is hidden by default. You can mouse over the scrollable content to show the scrollbar.

EDITABLE EXAMPLE

Scroll direction

The examples below illustrate the different scroll directions. You can try to resize the scrollable content to see how the scrollbar changes.

Vertical scrolling

To enable vertical scrolling, set the scrollbar height to a value less than the scrollable content height.

EDITABLE EXAMPLE

Horizontal scrolling

To enable horizontal scrolling, set the scrollbar width to a value less than the scrollable content width.

EDITABLE EXAMPLE

Bidirectional scrolling

EDITABLE EXAMPLE

Overflow control

Use the overflow prop to set the overflow of the content. You can set the value to auto, scroll, or hidden.

  • auto: The scrollbar will be shown if the content overflows and mouse is hovering over the content.
  • scroll: The scrollbar is always visible if the content overflows.
  • hidden: The scrollbar is never shown.

Note: overflowX and overflowY are also available if you need to set the overflow on both X and Y axis.

EDITABLE EXAMPLE

Scrollbar thumb

Use the minThumbWidth and minThumbHeight props to set the minimum size of the thumb (in pixels).

EDITABLE EXAMPLE

Scroll indicator

The scroll indicator can visually indicate the current scroll position of the scrollable element, so that the user knows whether it can be scrolled further.

EDITABLE EXAMPLE

Scrollable menu

EDITABLE EXAMPLE

Scrollable table

EDITABLE EXAMPLE

Props

NameTypeDefaultDescription
childrenReactNode | functionThe content of the scrollbar.
widthnumber | string'100%'The width of the scrollbar. If set to 'auto', you can constrain the width using the minWidth and maxWidth props.
heightnumber | string'100%'The height of the scrollbar. If set to 'auto', you can constrain the height using the minHeight and maxHeight props.
minWidthnumber | stringThe minimum width of the scrollbar.
maxWidthnumber | stringThe maximum width of the scrollbar.
minHeightnumber | stringThe minimum height of the scrollbar.
maxHeightnumber | stringThe maximum height of the scrollbar.
minThumbWidthnumber32The minimum width of the thumb in pixels.
minThumbHeightnumber32The minimum height of the thumb in pixels.
onScrollfunctionA callback function that is called when the scrollbar is scrolled.
onUpdatefunctionA callback function that is called when the scrollbar is updated.
overflowstring'auto'The overflow of the scrollable content. One of: 'auto', 'scroll', 'hidden'.
overflowXstringThe horizontal overflow of the scrollable content. One of: 'auto', 'scroll', 'hidden'.
overflowYstringThe vertical overflow of the scrollable content. One of: 'auto', 'scroll', 'hidden'.

Further Reading

  • Bidirectional scrolling: what’s not to like?