File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Expand file tree Collapse file tree 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) {
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,11 @@ export default function Dialog(props: IDialogPropTypes) {
5960 }
6061
6162 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 {
6368 contentRef . current ?. focus ( ) ;
6469 }
6570 }
Original file line number Diff line number Diff line change 1- import * as React from 'react' ;
21import Portal from '@rc-component/portal' ;
2+ import * as React from 'react' ;
33import Dialog from './Dialog' ;
44import type { IDialogPropTypes } from './IDialogPropTypes' ;
5+ import { isNil } from './util' ;
56
67// fix issue #10656
78/*
@@ -41,7 +42,7 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props: IDialogPropTypes) => {
4142 < Portal
4243 open = { visible || forceRender || animatedVisible }
4344 autoDestroy = { false }
44- getContainer = { getContainer }
45+ getContainer = { isNil ( getContainer ) ? 'body' : getContainer }
4546 autoLock = { visible || animatedVisible }
4647 >
4748 < Dialog
Original file line number Diff line number Diff line change @@ -37,3 +37,7 @@ export function offset(el: Element) {
3737 pos . top += getScroll ( w , true ) ;
3838 return pos ;
3939}
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', () => {
222222 expect ( wrapper . find ( '.rc-dialog-footer' ) . text ( ) ) . toBe ( 'test' ) ;
223223 } ) ;
224224
225- // 失效了,需要修复
226- it . skip ( 'support input autoFocus' , ( ) => {
225+ it ( 'support input autoFocus' , ( ) => {
227226 render (
228227 < Dialog visible >
229228 < input autoFocus />
You can’t perform that action at this time.
0 commit comments