File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ export default function Dialog(props: IDialogPropTypes) {
48
48
const contentRef = useRef < ContentRef > ( ) ;
49
49
50
50
const [ animatedVisible , setAnimatedVisible ] = React . useState ( visible ) ;
51
+ const [ originFocusEl , setOriginFocusEl ] = React . useState < HTMLElement > ( ) ;
51
52
52
53
// ========================== Init ==========================
53
54
const ariaId = useId ( ) ;
@@ -59,7 +60,10 @@ export default function Dialog(props: IDialogPropTypes) {
59
60
}
60
61
61
62
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 {
63
67
contentRef . current ?. focus ( ) ;
64
68
}
65
69
}
You can’t perform that action at this time.
0 commit comments