React-custom-scrollbars: access to ref

Created on 15 Jul 2017  路  4Comments  路  Source: malte-wessel/react-custom-scrollbars

Hi, can I set ref as a prop for <Scrollbars /> and control scrollbars manually?

Most helpful comment

@mhemrg elements are exposed on the API after #155 change.

handleScrollbarsMount(scrollbars) {
  const containerElm = scrollbars.container;
  const viewElm = scrollbars.view;
  const hTrackElm = scrollbars.trackHorizontal;
  const hThumbElm = scrollbars.thumbHorizontal;
  const vTrackElm = scrollbars.trackVertical;
  const vThumbElm = scrollbars.thumbVertical;
}

render() {
    <Scrollbars ref={s => { this.handleScrollbarsMount(s); }}>
        <div/>
        <div/>
    </Scrollbars>
}

All 4 comments

usefulMethod() {
    this.scrollbars.scrollToBottom();
}

render() {
    <Scrollbars ref={s => { this.scrollbars = s; }}>
        <div/>
        <div/>
    </Scrollbars>
}

I correctly understood your question?

I need to have access to the element, not the react-custom-scrollbars's API.

@mhemrg elements are exposed on the API after #155 change.

handleScrollbarsMount(scrollbars) {
  const containerElm = scrollbars.container;
  const viewElm = scrollbars.view;
  const hTrackElm = scrollbars.trackHorizontal;
  const hThumbElm = scrollbars.thumbHorizontal;
  const vTrackElm = scrollbars.trackVertical;
  const vThumbElm = scrollbars.thumbVertical;
}

render() {
    <Scrollbars ref={s => { this.handleScrollbarsMount(s); }}>
        <div/>
        <div/>
    </Scrollbars>
}

This would be nice to mention in the docs. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dusanstojanovic picture dusanstojanovic  路  3Comments

luxotus picture luxotus  路  4Comments

Amdingo picture Amdingo  路  4Comments

ilfa picture ilfa  路  5Comments

webchaz picture webchaz  路  3Comments