Skip to content

Commit 04fc14f

Browse files
committed
fix: focusTriggerAfterClose not working
close #280 ant-design/ant-design#32923
1 parent d8e2732 commit 04fc14f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Dialog/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ export default function Dialog(props: IDialogPropTypes) {
5353

5454
// ========================= Events =========================
5555
function onDialogVisibleChanged(newVisible: boolean) {
56+
// Try to focus
5657
if (newVisible) {
57-
// Try to focus
58-
if (!contains(wrapperRef.current, document.activeElement)) {
59-
lastOutSideActiveElementRef.current = document.activeElement as HTMLElement;
60-
contentRef.current?.focus();
61-
}
58+
contentRef.current?.focus();
6259
} else {
6360
// Clean up scroll bar & focus back
6461
setAnimatedVisible(false);
@@ -127,10 +124,17 @@ export default function Dialog(props: IDialogPropTypes) {
127124
}
128125
}
129126

127+
function saveLastOutSideActiveElementRef() {
128+
if (!contains(wrapperRef.current, document.activeElement)) {
129+
lastOutSideActiveElementRef.current = document.activeElement as HTMLElement;
130+
}
131+
}
132+
130133
// ========================= Effect =========================
131134
useEffect(() => {
132135
if (visible) {
133136
setAnimatedVisible(true);
137+
saveLastOutSideActiveElementRef();
134138
}
135139
}, [visible]);
136140

0 commit comments

Comments
 (0)