@@ -15,6 +15,7 @@ import type {
1515 SelectInfo ,
1616 RenderIconType ,
1717 ItemType ,
18+ MenuRef ,
1819} from './interface' ;
1920import MenuItem from './MenuItem' ;
2021import { parseItems } from './utils/nodeUtil' ;
@@ -28,7 +29,7 @@ import { PathRegisterContext, PathUserContext } from './context/PathContext';
2829import useKeyRecords , { OVERFLOW_KEY } from './hooks/useKeyRecords' ;
2930import { IdContext } from './context/IdContext' ;
3031import PrivateContext from './context/PrivateContext' ;
31- import { composeRef } from 'rc-util/lib/ref ' ;
32+ import { useImperativeHandle } from 'react ' ;
3233
3334/**
3435 * Menu modify after refactor:
@@ -149,7 +150,7 @@ interface LegacyMenuProps extends MenuProps {
149150 openAnimation ?: string ;
150151}
151152
152- const Menu = React . forwardRef < HTMLUListElement , MenuProps > ( ( props , ref ) => {
153+ const Menu = React . forwardRef < MenuRef , MenuProps > ( ( props , ref ) => {
153154 const {
154155 prefixCls = 'rc-menu' ,
155156 style,
@@ -232,7 +233,13 @@ const Menu = React.forwardRef<HTMLUListElement, MenuProps>((props, ref) => {
232233 const [ mounted , setMounted ] = React . useState ( false ) ;
233234
234235 const containerRef = React . useRef < HTMLUListElement > ( ) ;
235- const mergedRef = composeRef ( containerRef , ref ) ;
236+
237+ useImperativeHandle ( ref , ( ) => ( {
238+ list : containerRef . current ,
239+ focus : ( options ?: FocusOptions ) => {
240+ containerRef . current ?. focus ( options ) ;
241+ } ,
242+ } ) ) ;
236243
237244 const uuid = useUUID ( id ) ;
238245
@@ -498,7 +505,7 @@ const Menu = React.forwardRef<HTMLUListElement, MenuProps>((props, ref) => {
498505 const container = (
499506 < Overflow
500507 id = { id }
501- ref = { mergedRef as any }
508+ ref = { containerRef as any }
502509 prefixCls = { `${ prefixCls } -overflow` }
503510 component = "ul"
504511 itemComponent = { MenuItem }
0 commit comments