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.

Scrollbar is not showing when component mounts.

See original GitHub issue

I have the following scrollbar component:

const CustomScrollbars = ({ children }) => (
    <Scrollbars
        renderThumbVertical={({ style, ...props }) =>
            <div {...props} style={{
                ...style,
                backgroundColor: '#bbb',
                borderRadius: '5px',
                cursor: 'pointer',
                width: '10px',
                right: 2,
            }}/>
        }
        >
        {children}
    </Scrollbars>
);

When the page loads the scrollbar does not appear. When I position the mouse pointer over the content and use the mousewheel to start scrolling, the scrollbar appears.

Having inspected the element using dev tools, the scrollbar is on the page, but the height of the thumb area is initially 0px.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

2reactions
uadarshcommented, Nov 9, 2020

It seems like the Scrollbar component should call update whenever the scrollbar thumb is likely to change. This is not happening. I did this by creating a ref and calling update on that - a bit hackish, but works until it is fixed internally.

     // In render method
      <Scrollbars
        ref={this.scrollbarRef}
      >
        <div ref={this.childRef}>{this.props.children}</div>
      </Scrollbars>

Then call this.scrollbarRef.current.update() whenever the scrollbar is expected to change. For me it was on child component resizes. So, I did the following -

  componentDidMount() {
    this.observer = new ResizeObserver(this.update).observe(
      this.childRef.current
    );
  }
  componentWillUnmount() {
    this.observer && this.observer.disconnect();
  }

0reactions
atomoccommented, Feb 24, 2021

@uadarsh

  componentDidMount() {
    this.observer = new ResizeObserver(this.update);

    this.observer.observe(
      this.childRef.current
    );
  }

Small amendment

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to check to see if a scrollbar is present in React?
It seems to always return true whether a scrollbar is visible or not. The following approach may work for you:.
Read more >
Developers - Scrollbar is not showing when component mounts. -
Scrollbar is not showing when component mounts. ... I have the following scrollbar component: const CustomScrollbars = ({ children }) => ( <Scrollbars ......
Read more >
::-webkit-scrollbar - CSS: Cascading Style Sheets | MDN
The ::-webkit-scrollbar CSS pseudo-element affects the style of an element's scrollbar when it has overflow:scroll; set.
Read more >
Scroll a React component into view - Robin van der Vleuten
We learn how React exposes HTML elements by scrolling an element into ... we grab a user's attention for something that isn't visible...
Read more >
Issue with Shelf - scrolling and apps not working
Title: Issue with Shelf - scrolling and apps not working; Device: OnePlus7; Software Version: O2 Stable 191107; Probablility of occurance: 4_50%-100% ...
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