Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: page scroll position will jump after dialog is closed #202

Merged
merged 2 commits into from Sep 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
hengkx marked this conversation as resolved.
Show resolved Hide resolved
}
this.lastOutSideFocusNode = null;
}
if (afterClose) {
Copy link
Member

Choose a reason for hiding this comment

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

      try {
        this.lastOutSideFocusNode.focus();
      } catch (e) {
--        this.lastOutSideFocusNode = null; // 没看懂这一行的作用
      }
      this.lastOutSideFocusNode = null;// 在这里已经设置了null
    

afterClose();
}
Expand Down