From 0f8ea52103b0baf939754a41c3f2c8e8bc976d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Wed, 3 Jun 2026 10:51:00 +0800 Subject: [PATCH 1/3] feat: add title property to ItemData and update itemData usage in convertItemsToNodes --- src/MenuItem.tsx | 1 + src/interface.ts | 1 + src/utils/nodeUtil.tsx | 7 +------ 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index c325ebe4..74882518 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -140,6 +140,7 @@ const InternalMenuItem = React.forwardRef((props: MenuItemProps, ref: React.Ref< label: children, itemIcon, extra: props.extra, + title: props.title, }; return { diff --git a/src/interface.ts b/src/interface.ts index 01eebbfe..1e013c41 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -69,6 +69,7 @@ export type ItemData = { itemIcon?: RenderIconType; extra?: React.ReactNode; key: React.Key; + title?: string; }; export interface MenuItemGroupType extends ItemSharedProps { diff --git a/src/utils/nodeUtil.tsx b/src/utils/nodeUtil.tsx index 492dea29..5864aacc 100644 --- a/src/utils/nodeUtil.tsx +++ b/src/utils/nodeUtil.tsx @@ -51,12 +51,7 @@ function convertItemsToNodes( const hasExtra = !!extra || extra === 0; return ( - + {hasExtra ? ( <> {label} From 65ab39b012d404783f06bd01dd80bfac3f7eef25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Wed, 3 Jun 2026 11:23:28 +0800 Subject: [PATCH 2/3] feat: update test to pass all itemData properties in onSelect and onClick when using items prop --- tests/MenuItem.spec.tsx | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/tests/MenuItem.spec.tsx b/tests/MenuItem.spec.tsx index ab922944..87966ef1 100644 --- a/tests/MenuItem.spec.tsx +++ b/tests/MenuItem.spec.tsx @@ -181,51 +181,25 @@ describe('MenuItem', () => { ); }); - it('should only pass defined itemData properties in onSelect and onClick', () => { + it('should pass all itemData properties in onSelect and onClick when using items prop', () => { const onSelect = jest.fn(); const onClick = jest.fn(); + const items = [{ key: '1', label: 'Menu Item', foo: '123', title: 'test title' }]; const { container } = render( - , + , ); fireEvent.click(container.querySelector('.rc-menu-item')!); expect(onSelect).toHaveBeenCalledWith( expect.objectContaining({ key: '1', - itemData: expect.objectContaining({ - key: '1', - label: 'Menu Item', - }), - }), - ); - expect(onSelect).toHaveBeenCalledWith( - expect.objectContaining({ - key: '1', - itemData: expect.not.objectContaining({ - foo: '123', - }), + itemData: expect.objectContaining(items[0]), }), ); expect(onClick).toHaveBeenCalledWith( expect.objectContaining({ key: '1', - itemData: expect.objectContaining({ - key: '1', - label: 'Menu Item', - }), - }), - ); - expect(onClick).toHaveBeenCalledWith( - expect.objectContaining({ - key: '1', - itemData: expect.not.objectContaining({ - foo: '123', - }), + itemData: expect.objectContaining(items[0]), }), ); }); From d31d1eda4920c7e8121e3160b21ec6bcaf2ee98a Mon Sep 17 00:00:00 2001 From: EmilyyyLiu <100924403+EmilyyyLiu@users.noreply.github.com> Date: Wed, 3 Jun 2026 11:27:22 +0800 Subject: [PATCH 3/3] Update src/utils/nodeUtil.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/utils/nodeUtil.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/nodeUtil.tsx b/src/utils/nodeUtil.tsx index 5864aacc..b50d8cce 100644 --- a/src/utils/nodeUtil.tsx +++ b/src/utils/nodeUtil.tsx @@ -51,7 +51,7 @@ function convertItemsToNodes( const hasExtra = !!extra || extra === 0; return ( - + {hasExtra ? ( <> {label}