question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I add custom scrollbar??

See original GitHub issue

I would like to use react-scrollbar as follow:

<ScrollArea>
   menu.....
</ScrollArea>

but I can’t find any function that can do this, have any idea?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19

github_iconTop GitHub Comments

13reactions
Tomassitocommented, Sep 24, 2019
import Select from "react-select";
import Scrollbars from "react-custom-scrollbars";

const MyComponent = () => {
  const renderScrollbar = props => {
    return (
      <div style={{ height: 300 }}>
        <Scrollbars>{props.children}</Scrollbars>
      </div>
    );
  };
  
  return (
    <Select
       ....
       components={{ MenuList: renderScrollbar }}
    />
  );
}

something like this works for me.

@zzossig Can you share a codesanbox with this working? I copied this and didn’t work for me. Also, no need to wrap it in additional div just to get the height, as you can set autoHeight and autoHeightMax on Scrollbars. It only worked after adding prop captureMenuScroll={false}

11reactions
taiwanhuacommented, Jul 14, 2020

you can just use styled-component to rewrite css, like below :

import Select from 'react-select'
import styled from 'styled-components'

const SelectExtend = styled(Select).attrs((props) => ({}))`
    && {
        [class*="MenuList"] {
            //滾動條美化
            ::-webkit-scrollbar {
                width: 0.5em;
                height: ${props => props?.theme?.scrollHeight ?? 'initial'}; //scroll-x 的高度
            }
            ::-webkit-scrollbar-track {
                -webkit-border-radius: 10px;
                border-radius: 10px;
                margin:0px 0.1rem 5px 0;
            }
            ::-webkit-scrollbar-thumb {
                -webkit-border-radius: 4px;
                border-radius: 4px;
                background: ${props => props?.theme?.scrollUnhoverBackgroundColor ?? '#9093994d'};
            }
            &:hover::-webkit-scrollbar-thumb {
                -webkit-border-radius: 4px;
                border-radius: 4px;
                background: ${props => props?.theme?.scrollHoverBackgroundColor ?? '#9093994d'};
            }
        }
    }
`
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create a Custom Scrollbar - W3Schools
Learn how to create a custom scrollbar with CSS. Custom Scrollbars. Custom Scrollbar Example. Note: The -webkit-scrollbar is not supported in Firefox or...
Read more >
Custom Scrollbars In CSS - Ahmad Shadeed
Creating a scrollable element is possible by adding a value other than visible to the overflow property. It's recommended to use the auto ......
Read more >
scrollbar - CSS-Tricks
This article should be updated to include the styling options for firefox: Styling scrollbars in Firefox is also possible (since v64) with ...
Read more >
How to Add a Custom Scrollbar in WordPress - WPBeginner
To customize your scrollbar using CSS, go to Appearance » Customize. The WordPress customizer. In the WordPress customizer, click on Additional ...
Read more >
How to create a responsive custom scrollbar using CSS
Scrollbars are very common. You will see it in a web page, in elements like <div> or <p> etc. If you want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found