Skip to content

Commit

Permalink
fix: page scroll position will jump after dialog is closed (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Sep 2, 2020
1 parent 1d535d7 commit 6a45ccb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Dialog.tsx
Expand Up @@ -106,7 +106,8 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}

componentDidUpdate(prevProps: IDialogPropTypes) {
const { visible, mask, focusTriggerAfterClose, mousePosition } = this.props;
const { visible, mousePosition } = this.props;

if (visible) {
// first show
if (!prevProps.visible) {
Expand All @@ -127,14 +128,6 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}
} else if (prevProps.visible) {
this.inTransition = true;
if (mask && this.lastOutSideFocusNode && focusTriggerAfterClose) {
try {
this.lastOutSideFocusNode.focus();
} catch (e) {
this.lastOutSideFocusNode = null;
}
this.lastOutSideFocusNode = null;
}
}
}

Expand All @@ -154,7 +147,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}

onAnimateLeave = () => {
const { afterClose, getOpenCount } = this.props;
const { afterClose, getOpenCount, focusTriggerAfterClose, mask } = this.props;
// need demo?
// https://github.com/react-component/dialog/pull/28
if (this.wrap) {
Expand All @@ -166,6 +159,14 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
if (!getOpenCount()) {
this.switchScrollingEffect();
}
if (mask && this.lastOutSideFocusNode && focusTriggerAfterClose) {
try {
this.lastOutSideFocusNode.focus();
} catch (e) {
this.lastOutSideFocusNode = null;
}
this.lastOutSideFocusNode = null;
}
if (afterClose) {
afterClose();
}
Expand Down

1 comment on commit 6a45ccb

@vercel
Copy link

@vercel vercel bot commented on 6a45ccb Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.