0

Can someone please help? This is my code: https://codesandbox.io/s/5xoj9zw56l

I followed this code: https://codesandbox.io/s/6jr75xj8y3

1
  • Please add essential parts here Commented Nov 22, 2018 at 12:38

1 Answer 1

1

Drawer creates an elements, it will have structure like this

parent div > nested div > your data

And while getting the ref into drawer you do not get that div reference which you need to scroll.

What you need to do is you can add ref to your data div and go through ref.parent this way you will have parent div ref and there you can scroll the element.

To scroll you must have ref of div where you applied the overflow.

Here is the changes you need to do

Instead of container you will get aprent element

handleScrollTo = () => {

    console.log(this.container.parentElement.scrollTop);
    this.container.parentElement.scrollTop = 200;
  };

instead of using ref on drawer using the data on scroll

<Drawer open={this.state.left} onClose={this.toggleDrawer( "left", false)} onScroll={e=> console.log("scroll " + e.target.scrollTop)} >
  <div ref={el=> (this.container = el)} tabIndex={1} role="button" onKeyDown={this.toggleDrawer("left", false)} > {sideList} </div>
</Drawer>

Here is demo link

Sign up to request clarification or add additional context in comments.

1 Comment

Your technique works great! Thanks so much. How do I make it auto scroll when the Drawer is open? This code doesn't work: <Drawer onOpen={() => { this.handleScrollTo(); }}>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.