npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simplebar-react

v3.2.6

Published

React component for SimpleBar

Downloads

2,302,283

Readme

SimplebarReact

Installation

- Via npm npm install simplebar-react --save

- Via Yarn yarn add simplebar-react

Usage

Check out the Demo project or our live Codesandbox example.

If you are using a module loader (like Webpack) you first need to load SimpleBar:

import SimpleBar from 'simplebar-react';
import 'simplebar-react/dist/simplebar.min.css';

const App = () => (
  <SimpleBar style={{ maxHeight: 300 }}>// your content</SimpleBar>
);

Don't forget to import both css and js in your project!

:warning: Warning!

SimpleBar is not intended to be used on the body element! I don't recommend wrapping your entire web page inside a custom scroll as it will often badly affect the user experience (slower scroll performance compared to the native body scroll, no native scroll behaviours like click on track, etc.). Do it at your own risk! SimpleBar is meant to improve the experience of internal web page scrolling; such as a chat box or a small scrolling area. Please read the caveats section first to be aware of the limitations!

Troubleshooting

If you are experiencing issues when setting up SimpleBar, it is most likely because your styles are clashing with SimpleBar ones. Make sure the element you are setting SimpleBar on does not override any SimpleBar css properties! We recommend to not style that element at all and use an inner element instead.

Sponsors

Thanks to BrowserStack for sponsoring open source projects and letting us test SimpleBar for free.

  1. Documentation

1. Documentation

Passing options

Find the list of available options on the core documentation.

<SimpleBar forceVisible="y" autoHide={false}>
  // your content
</SimpleBar>

Extra options

scrollableNodeProps

You can pass props to the underlying scrollable div element. This is useful for example to get a ref of it, if you want to access the scroll event or apply imperative directive (like scrolling SimpleBar to the bottom, etc.).

const scrollableNodeRef = React.createRef();

<SimpleBar scrollableNodeProps={{ ref: scrollableNodeRef }}>
  // your content
</SimpleBar>;

Accessing SimpleBar instance

You can pass a ref to the SimpleBar element:

const ref = useRef();

useEffect(() => {
  ref.current.recalculate();
  console.log(ref.current.el); // <- the root element you applied SimpleBar on
})

<SimpleBar ref={ref}>
  // your content
</SimpleBar>

Usage with 3rd party libraries

For advanced usage, in some cases (like using react-window) you can forward the scrollable and content elements using a render prop pattern:

<SimpleBar>
  {({ scrollableNodeRef, contentNodeRef }) => {
    // Now you have access to scrollable and content nodes
    return <div></div>;
  }}
</SimpleBar>

If you define your own elements you should do:

<SimpleBar>
  {({ scrollableNodeProps, contentNodeProps }) => {
    return (
      <div {...scrollableNodeProps}>
        outer/scrollable element
        <div {...contentNodeProps} />inner element</div>
      </div>
    );
  }}
</SimpleBar>