11import { clsx } from 'clsx' ;
22import { useComposeRef } from '@rc-component/util/lib/ref' ;
3+ import { useLockFocus } from '@rc-component/util/lib/Dom/focus' ;
34import React , { useMemo , useRef } from 'react' ;
45import { RefContext } from '../../context' ;
56import type { IDialogPropTypes } from '../../IDialogPropTypes' ;
67import MemoChildren from './MemoChildren' ;
78import pickAttrs from '@rc-component/util/lib/pickAttrs' ;
89
9- const sentinelStyle : React . CSSProperties = {
10- width : 0 ,
11- height : 0 ,
12- overflow : 'hidden' ,
13- outline : 'none' ,
14- } ;
15-
16- const entityStyle : React . CSSProperties = {
17- outline : 'none' ,
18- } ;
19-
2010export interface PanelProps extends Omit < IDialogPropTypes , 'getOpenCount' > {
2111 prefixCls : string ;
2212 ariaId ?: string ;
@@ -27,7 +17,6 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
2717
2818export type PanelRef = {
2919 focus : ( ) => void ;
30- changeActive : ( next : boolean ) => void ;
3120} ;
3221
3322const Panel = React . forwardRef < PanelRef , PanelProps > ( ( props , ref ) => {
@@ -58,23 +47,14 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
5847
5948 // ================================= Refs =================================
6049 const { panel : panelRef } = React . useContext ( RefContext ) ;
50+ const internalRef = useRef < HTMLDivElement > ( null ) ;
51+ const mergedRef = useComposeRef ( holderRef , panelRef , internalRef ) ;
6152
62- const mergedRef = useComposeRef ( holderRef , panelRef ) ;
63-
64- const sentinelStartRef = useRef < HTMLDivElement > ( null ) ;
65- const sentinelEndRef = useRef < HTMLDivElement > ( null ) ;
53+ useLockFocus ( visible , ( ) => internalRef . current ) ;
6654
6755 React . useImperativeHandle ( ref , ( ) => ( {
6856 focus : ( ) => {
69- sentinelStartRef . current ?. focus ( { preventScroll : true } ) ;
70- } ,
71- changeActive : ( next ) => {
72- const { activeElement } = document ;
73- if ( next && activeElement === sentinelEndRef . current ) {
74- sentinelStartRef . current . focus ( { preventScroll : true } ) ;
75- } else if ( ! next && activeElement === sentinelStartRef . current ) {
76- sentinelEndRef . current . focus ( { preventScroll : true } ) ;
77- }
57+ internalRef . current ?. focus ( { preventScroll : true } ) ;
7858 } ,
7959 } ) ) ;
8060
@@ -167,13 +147,11 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
167147 className = { clsx ( prefixCls , className ) }
168148 onMouseDown = { onMouseDown }
169149 onMouseUp = { onMouseUp }
150+ tabIndex = { - 1 }
170151 >
171- < div ref = { sentinelStartRef } tabIndex = { 0 } style = { entityStyle } >
172- < MemoChildren shouldUpdate = { visible || forceRender } >
173- { modalRender ? modalRender ( content ) : content }
174- </ MemoChildren >
175- </ div >
176- < div tabIndex = { 0 } ref = { sentinelEndRef } style = { sentinelStyle } />
152+ < MemoChildren shouldUpdate = { visible || forceRender } >
153+ { modalRender ? modalRender ( content ) : content }
154+ </ MemoChildren >
177155 </ div >
178156 ) ;
179157} ) ;
0 commit comments