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

Support horizontal scrollbar?

Open thovo opened this issue 9 years ago • 11 comments

Thank you a lot for the component! It worked pretty nice.

Situation: I am using overflow-x: auto to display a horizontal scrollbar for Tabs component of react-toolbox. I want to use react-custom-scrollbar for the nav part of Tabs component.

I want to know there is any support for horizontal scrolling now and if it has, how to implement it?

I tried to look at the documentation and around issues discussion but I didn't find any example using it. I am extremely grateful if you can show me how to do it.

thovo avatar Aug 17 '16 16:08 thovo

You'll need to make the Scrollbars' child components wider than the Scrollbars component itself. This can be done with a fixed width on the child components.

malte-wessel avatar Sep 03 '16 09:09 malte-wessel

The problem is usually we don't know the available width of child component as the data would be very random.

thovo avatar Sep 03 '16 09:09 thovo

Maybe you could force the tabs to overflow with the help of css. If you got inline-block elements you could set white-space: nowrap; on the tabs container element, to ensure that the container grows horizontally.

malte-wessel avatar Sep 03 '16 09:09 malte-wessel

Yes, I am doing it now, I force the nav inside Tabs have overflow-x: auto so it will add a horizontal scrollbar now if it is too long. The problem is wrap the whole Tabs component inside Scrollbars didn't render the nice scroll but always the default scrollbar of browser which is a little ugly.

An example is below: tabs

thovo avatar Sep 06 '16 08:09 thovo

I don't understand how this is used to show the horizontal scrollbar. Can you please show how? I also want to have this.

janejanejane avatar Sep 07 '16 03:09 janejanejane

@janejanejane : it didn't show yet and currently I don't know how, to enable the horizontal scrollbar you just need to add style overflow-x: auto to the element you want.

thovo avatar Sep 07 '16 07:09 thovo

@thovo

React file : <CustomScrollBars autoHide={false} style={{ width: "100%", height: "48px" }} renderTrackHorizontal={props => <div {...props} className="track-horizontal"/>} renderThumbHorizontal={props => <div {...props} className="thumb-horizontal"/>}> </CustomScrollBars>

CSS file : .track-horizontal { min-width: 100%; z-index: 150; bottom: 0; } .thumb-horizontal { cursor: pointer; background: red; min-width: 100px; }

If test is ok remove in .thumb-horizonta -> min-width: 100px;

ghost avatar Sep 21 '16 09:09 ghost

I tried that in a codesandbox and it looks like it's being covered up by native scrollbars?

https://codesandbox.io/s/nZm4PKxPp

cc: @WonderStudio

ignu avatar Apr 18 '17 19:04 ignu

You can use something like react-measure to get the width of the container, and use that width to set the width of the scroll bar.

  handleResize = (rect) => {
    this.setState({
      dimensions: rect.bounds
    })
  }

  ...

  <Measure bounds onResize={this.handleResize}>
    {({measureRef}) => <div ref={measureRef} className="chooser-objects"
      onWheel={this.handleWheel}>
      <Scrollbars universal style={{ width: this.state.dimensions.width, height: this.state.dimensions.height }}>

The real challenge is getting it to convert vertical scroll motion to horizontal, for mouse wheels. @

CaptainN avatar Sep 27 '17 21:09 CaptainN

Can it support to show the vertical and the horizontal scrollbar at the same time?

MuYunyun avatar Mar 26 '20 09:03 MuYunyun

i have done it. using css become horizontal scrollbar. and use onWheel eventlistener to scroll by mousewheel. looks good.

HUGY1 avatar May 26 '21 02:05 HUGY1