File tree 4 files changed +14
-5
lines changed
4 files changed +14
-5
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,11 @@ export default function Dialog(props: IDialogPropTypes) {
59
60
}
60
61
61
62
function focusDialogContent ( ) {
62
- if ( ! contains ( wrapperRef . current , document . activeElement ) ) {
63
+ if ( originFocusEl ) {
64
+ originFocusEl . focus ( ) ;
65
+ } else if ( contains ( wrapperRef . current , document . activeElement ) ) {
66
+ setOriginFocusEl ( document . activeElement as HTMLElement ) ;
67
+ } else {
63
68
contentRef . current ?. focus ( ) ;
64
69
}
65
70
}
Original file line number Diff line number Diff line change 1
- import * as React from 'react' ;
2
1
import Portal from '@rc-component/portal' ;
2
+ import * as React from 'react' ;
3
3
import Dialog from './Dialog' ;
4
4
import type { IDialogPropTypes } from './IDialogPropTypes' ;
5
+ import { isNil } from './util' ;
5
6
6
7
// fix issue #10656
7
8
/*
@@ -41,7 +42,7 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props: IDialogPropTypes) => {
41
42
< Portal
42
43
open = { visible || forceRender || animatedVisible }
43
44
autoDestroy = { false }
44
- getContainer = { getContainer }
45
+ getContainer = { isNil ( getContainer ) ? 'body' : getContainer }
45
46
autoLock = { visible || animatedVisible }
46
47
>
47
48
< Dialog
Original file line number Diff line number Diff line change @@ -37,3 +37,7 @@ export function offset(el: Element) {
37
37
pos . top += getScroll ( w , true ) ;
38
38
return pos ;
39
39
}
40
+
41
+ export function isNil ( val : any ) {
42
+ return val === undefined || val === null ;
43
+ }
Original file line number Diff line number Diff line change @@ -222,8 +222,7 @@ describe('dialog', () => {
222
222
expect ( wrapper . find ( '.rc-dialog-footer' ) . text ( ) ) . toBe ( 'test' ) ;
223
223
} ) ;
224
224
225
- // 失效了,需要修复
226
- it . skip ( 'support input autoFocus' , ( ) => {
225
+ it ( 'support input autoFocus' , ( ) => {
227
226
render (
228
227
< Dialog visible >
229
228
< input autoFocus />
You can’t perform that action at this time.
0 commit comments