@@ -27,6 +27,7 @@ import { PathRegisterContext, PathUserContext } from './context/PathContext';
2727import useKeyRecords , { OVERFLOW_KEY } from './hooks/useKeyRecords' ;
2828import { IdContext } from './context/IdContext' ;
2929import PrivateContext from './context/PrivateContext' ;
30+ import { composeRef } from 'rc-util/lib/ref' ;
3031
3132/**
3233 * Menu modify after refactor:
@@ -145,7 +146,7 @@ interface LegacyMenuProps extends MenuProps {
145146 openAnimation ?: string ;
146147}
147148
148- const Menu : React . FC < MenuProps > = props => {
149+ const Menu = React . forwardRef < HTMLUListElement , MenuProps > ( ( props , ref ) => {
149150 const {
150151 prefixCls = 'rc-menu' ,
151152 style,
@@ -223,6 +224,7 @@ const Menu: React.FC<MenuProps> = props => {
223224 const [ mounted , setMounted ] = React . useState ( false ) ;
224225
225226 const containerRef = React . useRef < HTMLUListElement > ( ) ;
227+ const mergedRef = composeRef ( containerRef , ref ) ;
226228
227229 const uuid = useUUID ( id ) ;
228230
@@ -488,7 +490,7 @@ const Menu: React.FC<MenuProps> = props => {
488490 const container = (
489491 < Overflow
490492 id = { id }
491- ref = { containerRef as any }
493+ ref = { mergedRef as any }
492494 prefixCls = { `${ prefixCls } -overflow` }
493495 component = "ul"
494496 itemComponent = { MenuItem }
@@ -591,6 +593,6 @@ const Menu: React.FC<MenuProps> = props => {
591593 </ IdContext . Provider >
592594 </ PrivateContext . Provider >
593595 ) ;
594- } ;
596+ } ) ;
595597
596598export default Menu ;
0 commit comments