Skip to content

Commit da7a732

Browse files
committed
chore: update
1 parent 6d0f7bb commit da7a732

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Dialog/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function Dialog(props: IDialogPropTypes) {
4848
const contentRef = useRef<ContentRef>();
4949

5050
const [animatedVisible, setAnimatedVisible] = React.useState(visible);
51+
const [originFocusEl, setOriginFocusEl] = React.useState<HTMLElement>();
5152

5253
// ========================== Init ==========================
5354
const ariaId = useId();
@@ -59,7 +60,10 @@ export default function Dialog(props: IDialogPropTypes) {
5960
}
6061

6162
function focusDialogContent() {
62-
if (!contains(wrapperRef.current, document.activeElement)) {
63+
if (originFocusEl) return originFocusEl.focus();
64+
if (contains(wrapperRef.current, document.activeElement)) {
65+
setOriginFocusEl(document.activeElement as HTMLElement);
66+
} else {
6367
contentRef.current?.focus();
6468
}
6569
}

0 commit comments

Comments
 (0)