open/close event callbacks added to Popup's proptypes

This commit is contained in:
NikolaBorislavovHristov 2018-06-20 17:38:52 +03:00
parent 60ba1c9172
commit a8a2bb3327

View file

@ -26,6 +26,16 @@ class Popup extends PureComponent {
window.removeEventListener('keyup', this.onKeyUp);
}
componentDidUpdate(prevProps, prevState) {
if (prevState.isOpen !== this.state.isOpen) {
if (this.state.isOpen && typeof this.props.onAfterOpen === 'function') {
this.props.onAfterOpen();
} else if (!this.state.isOpen && typeof this.props.onAfterClose === 'function') {
this.props.onAfterClose();
}
}
}
onKeyUp = (event) => {
if (event.keyCode === 27) {
this.close(event);
@ -129,4 +139,9 @@ Popup.Menu.propTypes = {
width: PropTypes.number
};
Popup.propTypes = {
onAfterOpen: PropTypes.func,
onAfterClose: PropTypes.func
};
export default Popup;