Skip to content

Commit 0bc58e6

Browse files
committed
docs(README): more detail on resize handles
These are a bit tricky due to ref forwarding.
1 parent b1ed428 commit 0bc58e6

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,59 @@ The following props can also be used on `<ResizableBox>`:
127127
}
128128
```
129129
130-
If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
130+
If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
131+
132+
#### Resize Handle
133+
134+
If you override the resize handle, we expect that any `ref` passed to your new handle with represent the underlying DOM element.
135+
136+
This is required, as `react-resizable` must be able to access the underlying DOM node to attach handlers and measure position deltas.
137+
138+
There are a few ways to do this:
139+
140+
##### Native DOM Element
141+
142+
This requires no special treatment.
143+
144+
```js
145+
<Resizable handle={<div className="foo" />} />
146+
```
147+
148+
##### Custom React Component
149+
150+
You must [forward the ref](https://reactjs.org/docs/forwarding-refs.html) to the underlying DOM element.
151+
152+
###### Class Components
153+
154+
```js
155+
class MyHandleComponent extends React.Component {
156+
render() {
157+
return <div ref={this.props.innerRef} className="foo" />
158+
}
159+
}
160+
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);
161+
162+
<Resizable handle={<MyHandle />} />
163+
```
164+
165+
###### Functional Components
166+
167+
```js
168+
const MyHandle = React.forwardRef((props, ref) => {
169+
return <div ref={ref} className="foo" />;
170+
});
171+
172+
<Resizable handle={<MyHandle />} />
173+
```
174+
175+
##### Custom Function
176+
177+
You can define a function as a handle, which will simply receive props and ref. This may be more clear to read, depending on your coding style.
178+
179+
```js
180+
const MyHandle = (props) => {
181+
return <div ref={props.innerRef} className="foo" />;
182+
};
183+
184+
<Resizable handle={(props, ref) => <MyHandle innerRef={ref} {...props} />} />
185+
```

0 commit comments

Comments
 (0)