Skip to content

Instantly share code, notes, and snippets.

@krazyjakee
Created April 23, 2019 14:16
Show Gist options
  • Save krazyjakee/8c87cae9bb33cb89fecb8e2f233657a9 to your computer and use it in GitHub Desktop.
Save krazyjakee/8c87cae9bb33cb89fecb8e2f233657a9 to your computer and use it in GitHub Desktop.
A small wrapper around react-scrollbars-custom to give it autohiding scrollbars
import React, { useState } from 'react';
import RSC from 'react-scrollbars-custom';
export default ({ autoHide, children, ...props }) => {
const [inUse, setInUse] = useState();
const style = { style: autoHide && { display: inUse ? null : 'none' }};
return <RSC
trackXProps={style}
trackYProps={style}
onMouseEnter={autoHide && (() => setInUse(true))}
onMouseLeave={autoHide && (() => setInUse(false))}
{...props}
>{children}</RSC>;
};
// <Scrollbar autoHide noScrollX>Content!</Scrollbar>
@gabrielfgularte
Copy link

You're a life saver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment