react-custom-scroller icon indicating copy to clipboard operation
react-custom-scroller copied to clipboard

Customize Color of Scrollbar

Open gbroques opened this issue 5 years ago • 5 comments

How would we customize the color of the scrollbar from the default of rgba(0, 0, 0, .1)?

I'd like to use this in an application with a dark background color, and rgba(0, 0, 0, .1) doesn't show up well on dark backgrounds.

gbroques avatar Sep 11 '20 21:09 gbroques

@gbroques I was able to customize the color by looking at the structure of the html and realizing that I can target the last child div of the CustomScroller. It's somewhat hacky but it works given we can't directly add classes to the track element.

If you're using makeStyles from material-ui, you can do something like this

import * as React from "react";
import { makeStyles } from "@material-ui/core";
import CustomScroller from "react-custom-scroller";

const useStyles = makeStyles({
  scroller: {
    "&> div:last-child": {
      background: "rgba(34, 157, 158, 0.4)",
    },
  },
});

const CustomColorScoller = ({ children }) => {
  const classes = useStyles();
  return (
    <CustomScroller className={classes.scroller}>{children}</CustomScroller>
  );
};

export default CustomColorScoller;

ivnflpz avatar Feb 06 '21 23:02 ivnflpz

@ivnflpz Thank you for the workaround! I will close this issue. 😄

gbroques avatar Feb 09 '21 19:02 gbroques

I'll keep it open because we plan to add an official way of doing this via props.

buzinas avatar Feb 09 '21 22:02 buzinas

I'll keep it open because we plan to add an official way of doing this via props.

This would be great. :)

gbroques avatar Feb 09 '21 22:02 gbroques

Yes, this would be awesome!

ApplePieGiraffe avatar Mar 17 '21 17:03 ApplePieGiraffe