@@ -3,7 +3,6 @@ import classNames from 'classnames';
3
3
import CSSMotion from 'rc-motion' ;
4
4
import type { CSSMotionProps } from 'rc-motion' ;
5
5
import DrawerPanel from './DrawerPanel' ;
6
- // import type ScrollLocker from 'rc-util/lib/Dom/scrollLocker';
7
6
import DrawerContext from './context' ;
8
7
import type { DrawerContextProps } from './context' ;
9
8
import KeyCode from 'rc-util/lib/KeyCode' ;
@@ -63,7 +62,7 @@ export interface DrawerPopupProps {
63
62
) => void ;
64
63
}
65
64
66
- export default function DrawerPopup ( props : DrawerPopupProps ) {
65
+ function DrawerPopup ( props : DrawerPopupProps , ref : React . Ref < HTMLDivElement > ) {
67
66
const {
68
67
prefixCls,
69
68
open,
@@ -105,6 +104,8 @@ export default function DrawerPopup(props: DrawerPopupProps) {
105
104
const sentinelStartRef = React . useRef < HTMLDivElement > ( ) ;
106
105
const sentinelEndRef = React . useRef < HTMLDivElement > ( ) ;
107
106
107
+ React . useImperativeHandle ( ref , ( ) => panelRef . current ) ;
108
+
108
109
const onPanelKeyDown : React . KeyboardEventHandler < HTMLDivElement > = event => {
109
110
const { keyCode, shiftKey } = event ;
110
111
@@ -127,6 +128,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
127
128
// Close
128
129
case KeyCode . ESC : {
129
130
if ( onClose && keyboard ) {
131
+ event . stopPropagation ( ) ;
130
132
onClose ( event ) ;
131
133
}
132
134
break ;
@@ -140,7 +142,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
140
142
if ( open && autoFocus ) {
141
143
panelRef . current ?. focus ( { preventScroll : true } ) ;
142
144
}
143
- } , [ open , autoFocus ] ) ;
145
+ } , [ open ] ) ;
144
146
145
147
// ============================ Push ============================
146
148
const [ pushed , setPushed ] = React . useState ( false ) ;
@@ -332,3 +334,11 @@ export default function DrawerPopup(props: DrawerPopupProps) {
332
334
</ DrawerContext . Provider >
333
335
) ;
334
336
}
337
+
338
+ const RefDrawerPopup = React . forwardRef ( DrawerPopup ) ;
339
+
340
+ if ( process . env . NODE_ENV !== 'production' ) {
341
+ RefDrawerPopup . displayName = 'DrawerPopup' ;
342
+ }
343
+
344
+ export default RefDrawerPopup ;
0 commit comments