Skip to content

Commit

Permalink
Trigger afterPopupVisibleChange after portal updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Nov 7, 2017
1 parent 4c84908 commit 3b21cf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
"prop-types": "15.x",
"rc-align": "2.x",
"rc-animate": "2.x",
"rc-util": "^4.1.0"
"rc-util": "^4.2.0"
}
}
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ const Trigger = createReactClass({
} else {
popupVisible = !!props.defaultPopupVisible;
}

this.prevPopupVisible = popupVisible;

return {
popupVisible,
};
Expand Down Expand Up @@ -163,10 +166,10 @@ const Trigger = createReactClass({
};
if (!IS_REACT_16) {
this.renderComponent(null, triggerAfterPopupVisibleChange);
} else {
triggerAfterPopupVisibleChange();
}

this.prevPopupVisible = prevState.popupVisible;

// We must listen to `mousedown`, edge case:
// https://github.com/ant-design/ant-design/issues/5804
// https://github.com/react-component/calendar/issues/250
Expand Down Expand Up @@ -313,6 +316,12 @@ const Trigger = createReactClass({
}
},

handlePortalUpdate() {
if (this.prevPopupVisible !== this.state.popupVisible) {
this.props.afterPopupVisibleChange(this.state.popupVisible);
}
},

getPopupDomNode() {
// for test
if (this._component && this._component.getPopupDomNode) {
Expand Down Expand Up @@ -574,6 +583,7 @@ const Trigger = createReactClass({
<Portal
key="portal"
getContainer={this.getContainer}
didUpdate={this.handlePortalUpdate}
>
{this.getComponent()}
</Portal>
Expand Down

0 comments on commit 3b21cf2

Please sign in to comment.