Skip to content

Commit 6a45ccb

Browse files
authored
fix: page scroll position will jump after dialog is closed (#202)
close ant-design/ant-design#26528
1 parent 1d535d7 commit 6a45ccb

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Dialog.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
106106
}
107107

108108
componentDidUpdate(prevProps: IDialogPropTypes) {
109-
const { visible, mask, focusTriggerAfterClose, mousePosition } = this.props;
109+
const { visible, mousePosition } = this.props;
110+
110111
if (visible) {
111112
// first show
112113
if (!prevProps.visible) {
@@ -127,14 +128,6 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
127128
}
128129
} else if (prevProps.visible) {
129130
this.inTransition = true;
130-
if (mask && this.lastOutSideFocusNode && focusTriggerAfterClose) {
131-
try {
132-
this.lastOutSideFocusNode.focus();
133-
} catch (e) {
134-
this.lastOutSideFocusNode = null;
135-
}
136-
this.lastOutSideFocusNode = null;
137-
}
138131
}
139132
}
140133

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

156149
onAnimateLeave = () => {
157-
const { afterClose, getOpenCount } = this.props;
150+
const { afterClose, getOpenCount, focusTriggerAfterClose, mask } = this.props;
158151
// need demo?
159152
// https://github.com/react-component/dialog/pull/28
160153
if (this.wrap) {
@@ -166,6 +159,14 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
166159
if (!getOpenCount()) {
167160
this.switchScrollingEffect();
168161
}
162+
if (mask && this.lastOutSideFocusNode && focusTriggerAfterClose) {
163+
try {
164+
this.lastOutSideFocusNode.focus();
165+
} catch (e) {
166+
this.lastOutSideFocusNode = null;
167+
}
168+
this.lastOutSideFocusNode = null;
169+
}
169170
if (afterClose) {
170171
afterClose();
171172
}

0 commit comments

Comments
 (0)