File tree Expand file tree Collapse file tree 4 files changed +40
-34
lines changed
Expand file tree Collapse file tree 4 files changed +40
-34
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import * as React from 'react';
44import { MenuContext } from './context/MenuContext' ;
55import { useFullPath , useMeasure } from './context/PathContext' ;
66import type { MenuItemGroupType } from './interface' ;
7- import { parseChildren } from './utils/nodeUtil ' ;
7+ import { parseChildren } from './utils/commonUtil ' ;
88
99export interface MenuItemGroupProps
1010 extends Omit < MenuItemGroupType , 'type' | 'children' | 'label' > {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import classNames from 'classnames';
33import Overflow from 'rc-overflow' ;
44import warning from 'rc-util/lib/warning' ;
55import SubMenuList from './SubMenuList' ;
6- import { parseChildren } from '../utils/nodeUtil ' ;
6+ import { parseChildren } from '../utils/commonUtil ' ;
77import type { MenuInfo , SubMenuType } from '../interface' ;
88import MenuContextProvider , { MenuContext } from '../context/MenuContext' ;
99import useMemoCallback from '../hooks/useMemoCallback' ;
Original file line number Diff line number Diff line change 1+ import toArray from "rc-util/lib/Children/toArray" ;
2+ import * as React from 'react' ;
3+
4+ export function parseChildren (
5+ children : React . ReactNode | undefined ,
6+ keyPath : string [ ] ,
7+ ) {
8+ return toArray ( children ) . map ( ( child , index ) => {
9+ if ( React . isValidElement ( child ) ) {
10+ const { key } = child ;
11+ let eventKey = ( child . props as any ) ?. eventKey ?? key ;
12+
13+ const emptyKey = eventKey === null || eventKey === undefined ;
14+
15+ if ( emptyKey ) {
16+ eventKey = `tmp_key-${ [ ...keyPath , index ] . join ( '-' ) } ` ;
17+ }
18+
19+ const cloneProps = {
20+ key : eventKey ,
21+ eventKey,
22+ } as any ;
23+
24+ if ( process . env . NODE_ENV !== 'production' && emptyKey ) {
25+ cloneProps . warnKey = true ;
26+ }
27+
28+ return React . cloneElement ( child , cloneProps ) ;
29+ }
30+
31+ return child ;
32+ } ) ;
33+ }
Original file line number Diff line number Diff line change 11import * as React from 'react' ;
2- import toArray from 'rc-util/lib/Children/toArray' ;
32import type { ItemType } from '../interface' ;
4- import { Divider , MenuItem , MenuItemGroup , SubMenu } from '..' ;
3+ import MenuItemGroup from '../MenuItemGroup' ;
4+ import SubMenu from '../SubMenu' ;
5+ import Divider from '../Divider' ;
6+ import MenuItem from '../MenuItem' ;
7+ import { parseChildren } from './commonUtil' ;
58
6- export function parseChildren (
7- children : React . ReactNode | undefined ,
8- keyPath : string [ ] ,
9- ) {
10- return toArray ( children ) . map ( ( child , index ) => {
11- if ( React . isValidElement ( child ) ) {
12- const { key } = child ;
13- let eventKey = ( child . props as any ) ?. eventKey ?? key ;
14-
15- const emptyKey = eventKey === null || eventKey === undefined ;
16-
17- if ( emptyKey ) {
18- eventKey = `tmp_key-${ [ ...keyPath , index ] . join ( '-' ) } ` ;
19- }
20-
21- const cloneProps = {
22- key : eventKey ,
23- eventKey,
24- } as any ;
25-
26- if ( process . env . NODE_ENV !== 'production' && emptyKey ) {
27- cloneProps . warnKey = true ;
28- }
29-
30- return React . cloneElement ( child , cloneProps ) ;
31- }
32-
33- return child ;
34- } ) ;
35- }
369
3710function convertItemsToNodes ( list : ItemType [ ] ) {
3811 return ( list || [ ] )
You can’t perform that action at this time.
0 commit comments