@@ -3,7 +3,6 @@ import classNames from 'classnames';
33import CSSMotion from 'rc-motion' ;
44import type { CSSMotionProps } from 'rc-motion' ;
55import DrawerPanel from './DrawerPanel' ;
6- // import type ScrollLocker from 'rc-util/lib/Dom/scrollLocker';
76import DrawerContext from './context' ;
87import type { DrawerContextProps } from './context' ;
98import KeyCode from 'rc-util/lib/KeyCode' ;
@@ -63,7 +62,7 @@ export interface DrawerPopupProps {
6362 ) => void ;
6463}
6564
66- export default function DrawerPopup ( props : DrawerPopupProps ) {
65+ function DrawerPopup ( props : DrawerPopupProps , ref : React . Ref < HTMLDivElement > ) {
6766 const {
6867 prefixCls,
6968 open,
@@ -105,6 +104,8 @@ export default function DrawerPopup(props: DrawerPopupProps) {
105104 const sentinelStartRef = React . useRef < HTMLDivElement > ( ) ;
106105 const sentinelEndRef = React . useRef < HTMLDivElement > ( ) ;
107106
107+ React . useImperativeHandle ( ref , ( ) => panelRef . current ) ;
108+
108109 const onPanelKeyDown : React . KeyboardEventHandler < HTMLDivElement > = event => {
109110 const { keyCode, shiftKey } = event ;
110111
@@ -127,6 +128,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
127128 // Close
128129 case KeyCode . ESC : {
129130 if ( onClose && keyboard ) {
131+ event . stopPropagation ( ) ;
130132 onClose ( event ) ;
131133 }
132134 break ;
@@ -140,7 +142,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
140142 if ( open && autoFocus ) {
141143 panelRef . current ?. focus ( { preventScroll : true } ) ;
142144 }
143- } , [ open , autoFocus ] ) ;
145+ } , [ open ] ) ;
144146
145147 // ============================ Push ============================
146148 const [ pushed , setPushed ] = React . useState ( false ) ;
@@ -332,3 +334,11 @@ export default function DrawerPopup(props: DrawerPopupProps) {
332334 </ DrawerContext . Provider >
333335 ) ;
334336}
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