react-remove-scroll icon indicating copy to clipboard operation
react-remove-scroll copied to clipboard

How to allow scroll on multiple elements?

Open dotmlj opened this issue 6 years ago β€’ 3 comments

Hi.

How is it possible to allow scroll on multiple elements?

The doc mentions "support nested scrollable elements" and "More than one lock" but I don't see/understand how it's done.

Thank you! :)

dotmlj avatar Jan 09 '20 12:01 dotmlj

Oh, that's really is not explained in the documentation. But there is a shards prop, where you can provide an array of Refs to "other elements"

const ref = useRef();

<div ref={ref}>Some location</div>
<RemoveScroll shards={[ref]}>Work for "Some Location", as well as for own children</RemoveScroll>

πŸ‘‰ keep in mind, shards are not "portal-friendly"

theKashey avatar Jan 09 '20 20:01 theKashey

Thank you for the fast reply, it works! :)

For future reference here's how I made it:

class Details extends React.Component {
  constructor(props) {
    this.firstScrollElement = React.createRef();
  }

...

<div className={classes.scroll} ref={this.firstScrollElement}>
    children
</div>

<RemoveScroll shards={[this.firstScrollElement]} className={classes.scroll}>
    children
</RemoveScroll>

Notice that "ref" on <RemoveScroll> in @theKashey example should of course be "shards".

dotmlj avatar Jan 10 '20 07:01 dotmlj

Yep, of course "shards" πŸ˜…

theKashey avatar Jan 10 '20 10:01 theKashey

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.

stale[bot] avatar Apr 30 '23 07:04 stale[bot]