diff --git a/src/Frame.jsx b/src/Frame.jsx index 767362a..d6f1655 100644 --- a/src/Frame.jsx +++ b/src/Frame.jsx @@ -11,6 +11,7 @@ export class Frame extends Component { // element that we render react into. static propTypes = { style: PropTypes.object, // eslint-disable-line + onLoad: PropTypes.func, head: PropTypes.node, initialContent: PropTypes.string, mountTarget: PropTypes.string, @@ -24,6 +25,7 @@ export class Frame extends Component { static defaultProps = { style: {}, + onLoad: undefined, head: null, children: undefined, mountTarget: undefined, @@ -57,6 +59,13 @@ export class Frame extends Component { this.nodeRef.current.removeEventListener('load', this.handleLoad); } + onIframeLoad = () => { + this.handleLoad(); + if (this.props.onLoad) { + this.props.onLoad(); + } + }; + getDoc() { return this.nodeRef.current ? this.nodeRef.current.contentDocument : null; // eslint-disable-line } @@ -131,7 +140,7 @@ export class Frame extends Component { delete props.contentDidUpdate; delete props.forwardedRef; return ( - ); diff --git a/test/Frame.spec.jsx b/test/Frame.spec.jsx index c90242b..47915ae 100644 --- a/test/Frame.spec.jsx +++ b/test/Frame.spec.jsx @@ -62,6 +62,16 @@ describe('The Frame Component', () => { expect(node.getAttribute('width')).to.equal('80%'); }); + it('should call onLoad given as props', done => { + div = document.body.appendChild(document.createElement('div')); + + const onLoad = () => { + done(); + }; + + ReactDOM.render(, div); + }); + it('should create an iFrame with a tag inside', done => { div = document.body.appendChild(document.createElement('div')); const frame = ReactDOM.render(