diff --git a/docs/example.js b/docs/example.js
index ef08060..038ab85 100644
--- a/docs/example.js
+++ b/docs/example.js
@@ -51,7 +51,6 @@ function MyComponent(_ref) {
function App() {
return React.createElement(ReactResizeAware.default, {
component: MyComponent,
- useBoundingClientRect: true,
style: {position: 'relative'},
onResize: function onResize(sizes) {
return console.log(sizes);
diff --git a/docs/react-resize-aware.js b/docs/react-resize-aware.js
index 935674a..b43b817 100644
--- a/docs/react-resize-aware.js
+++ b/docs/react-resize-aware.js
@@ -107,18 +107,19 @@ var ResizeAware = function (_Component) {
var hasCustomComponent = typeof component !== 'string';
- var passSizeProps = !onlyEvent && hasCustomComponent;
return react.createElement(component, _extends((_extends2 = {}, _defineProperty(_extends2, hasCustomComponent ? 'getRef' : 'ref', function (el) {
return _this2.container = el;
- }), _defineProperty(_extends2, 'width', width), _defineProperty(_extends2, 'height', height), _extends2), props), react.createElement('object', {
+ }), _defineProperty(_extends2, 'width', hasCustomComponent ? width : undefined), _defineProperty(_extends2, 'height', hasCustomComponent ? height : undefined), _extends2), props), react.createElement('object', {
type: 'text/html',
style: style,
ref: function ref(el) {
return _this2.resizeElement = el;
},
onLoad: this.handleObjectLoad
- }), !!children && react.cloneElement(children, passSizeProps ? this.state : null));
+ }), react.Children.map(children, function (child) {
+ return react.cloneElement(child, !onlyEvent ? _this2.state : null);
+ }));
}
}]);
diff --git a/package.json b/package.json
index 31fe279..29f4a32 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "react-resize-aware",
- "version": "2.4.0",
+ "version": "2.4.1",
"description": "A resize aware component used to detect sizes changes on your components",
"main": "dist/index.js",
"scripts": {
diff --git a/src/__snapshots__/index.spec.jsx.snap b/src/__snapshots__/index.spec.jsx.snap
index 9066950..d4409ad 100644
--- a/src/__snapshots__/index.spec.jsx.snap
+++ b/src/__snapshots__/index.spec.jsx.snap
@@ -67,6 +67,48 @@ exports[`allows to define an \`onResize\` property 1`] = `
`;
+exports[`allows to use its child as target 1`] = `
+
+
+
+`;
+
exports[`allows to use its children as target 1`] = `
(this.container = el),
- width,
- height,
+ width: hasCustomComponent ? width : undefined,
+ height: hasCustomComponent ? height : undefined,
...props,
},
createElement('object', {
@@ -78,7 +77,9 @@ export default class ResizeAware extends Component {
ref: el => (this.resizeElement = el),
onLoad: this.handleObjectLoad,
}),
- !!children && cloneElement(children, passSizeProps ? this.state : null)
+ Children.map(children, child =>
+ cloneElement(child, !onlyEvent ? this.state : null)
+ )
);
}
}
diff --git a/src/index.spec.jsx b/src/index.spec.jsx
index e9f4678..c5d73df 100644
--- a/src/index.spec.jsx
+++ b/src/index.spec.jsx
@@ -11,7 +11,7 @@ function DummyComponent2({getRef, ...props}) {
return ;
}
-it('allows to use its children as target', () => {
+it('allows to use its child as target', () => {
const wrapper = mount(
@@ -21,6 +21,19 @@ it('allows to use its children as target', () => {
expect(toJson(wrapper)).toMatchSnapshot();
});
+it('allows to use itself between a component markup', () => {
+ const wrapper = mount(
+
+ );
+
+ expect(toJson(wrapper)).toMatchSnapshot();
+});
+
it('allows to define an `onResize` property', () => {
const handleResize = jest.fn();
const wrapper = mount(