react-layout-components icon indicating copy to clipboard operation
react-layout-components copied to clipboard

Add support for React refs on `Box`

Open DannyDelott opened this issue 6 years ago • 3 comments

This is a great library, however it is missing a way to attach a ref to Box's underlying DOM node. This is useful for integrations with other third party libraries.

Specifically we want to be able to integrate with react-beautiful-dnd, which requires an exposed ref on the draggable items.

Would you be open to a PR that introduces an elementRef prop to the Box component?

Example usage:

render() {
  return (
    <Box elementRef={...}>
      {this.props.children}
    </Box>
  );
}

DannyDelott avatar Oct 08 '19 00:10 DannyDelott

Hey! Yeah sure, go for it! I‘d prefer an update to latest React using the forwardRef API though. If you need any help, just ping me!

robinweser avatar Oct 08 '19 05:10 robinweser

The forwardRef API won't work for ScrollView, because it currently exposes instance methods via ref, ie: scrollTo, getScrollPosition, et al. These would become inaccessible with a forwardRef refactor.

Let me know what your thoughts, and if you'd be willing to accept the elementRef as proposed here.

DannyDelott avatar Nov 06 '19 23:11 DannyDelott

Yeah that makes sense! innerRef oder elementRef are common names I guess. :)

robinweser avatar Nov 07 '19 12:11 robinweser