Custom Scrollbars for React

4.1.1 · maintenance · verified Sun Apr 19

react-scrollbars-custom is a React component that provides highly customizable scrollbars while preserving native browser scrolling behavior. Unlike many alternatives, it does not emulate scrolling but rather styles the native scrollbars, ensuring optimal performance (60 FPS using requestAnimationFrame) and a consistent experience across different browsers and platforms. Key features include cross-browser compatibility, full customizability for look and feel, scrollbar nesting, momentum scrolling for iOS, RTL support, and proper handling of page zoom. The current stable version is 4.1.1, released in August 2022, indicating a maintenance phase following active development. It differentiates itself by its performance-focused approach and extensive customization options, including allowing users to define their own renderer components.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `Scrollbar` into a React component, setting its dimensions and populating it with content to enable scrolling. It also shows how to opt out of default styling.

import React from 'react';
import { Scrollbar } from 'react-scrollbars-custom';

function App() {
  return (
    <div style={{ width: '100%', height: 'calc(100vh - 20px)', padding: '10px' }}>
      <h1>My Scrollable Content</h1>
      <p>This component demonstrates a custom scrollbar that maintains native scrolling behavior but allows for extensive styling. It's often used when default browser scrollbars don't match the application's aesthetic.</p>
      <Scrollbar style={{ width: '100%', height: 300, border: '1px solid #ccc', padding: '10px' }} noDefaultStyles>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        {Array.from({ length: 50 }).map((_, i) => (
          <p key={i}>This is some scrollable content, line {i + 1}. Adding more lines to ensure the scrollbar appears and is functional.</p>
        ))}
        <p>End of scrollable content. You can scroll this section independently.</p>
      </Scrollbar>
      <h2>Another section below the scrollable area.</h2>
      <p>This content is outside the custom scrollbar component.</p>
    </div>
  );
}

export default App;

view raw JSON →