From 4ac3ff4abd3ca52af4310da631c118f94df3c8cc Mon Sep 17 00:00:00 2001 From: Baruch Velez Date: Wed, 9 Oct 2019 01:24:56 +0200 Subject: [PATCH] [added]: pass overlay and content element references to onAfterOpen fn (#741) --- specs/Modal.events.spec.js | 10 ++++++++++ src/components/ModalPortal.js | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/specs/Modal.events.spec.js b/specs/Modal.events.spec.js index 5565f472..bc02c9f7 100644 --- a/specs/Modal.events.spec.js +++ b/specs/Modal.events.spec.js @@ -25,6 +25,16 @@ export default () => { afterOpenCallback.called.should.be.ok(); }); + it("should call onAfterOpen with overlay and content references", () => { + const afterOpenCallback = sinon.spy(); + const modal = renderModal({ isOpen: true, onAfterOpen: afterOpenCallback }); + + sinon.assert.calledWith(afterOpenCallback, { + overlayEl: modal.portal.overlay, + contentEl: modal.portal.content + }); + }); + it("should trigger the onAfterClose callback", () => { const onAfterCloseCallback = sinon.spy(); const modal = renderModal({ diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index 85fd693b..a510a019 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -208,7 +208,10 @@ export default class ModalPortal extends Component { this.setState({ afterOpen: true }); if (this.props.isOpen && this.props.onAfterOpen) { - this.props.onAfterOpen(); + this.props.onAfterOpen({ + overlayEl: this.overlay, + contentEl: this.content + }); } }); }