Skip to content

Commit 0cee119

Browse files
authored
refactor: rename item.title to item.label to avoid conflict with antd (#439)
* chore: move title to label * docs: update doc * chore: reorder
1 parent 907f621 commit 0cee119

File tree

10 files changed

+35
-31
lines changed

10 files changed

+35
-31
lines changed

assets/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
color: #777 !important;
9999
}
100100
}
101-
& > &-item-divider {
101+
&-item-divider {
102102
height: 1px;
103103
margin: 1px 0;
104104
overflow: hidden;

docs/demo/items.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## items
2+
3+
<code src="../examples/items.tsx">

docs/demo/options.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/examples/options.tsx renamed to docs/examples/items.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import '../../assets/index.less';
66

77
export default () => (
88
<Menu
9-
options={[
9+
items={[
1010
{
1111
// MenuItem
12-
title: 'Top Menu Item',
12+
label: 'Top Menu Item',
1313
key: 'top',
1414
},
1515
{
1616
// MenuGroup
1717
type: 'group',
18-
title: 'Top Menu Group without children',
18+
label: 'Top Menu Group without children',
1919
},
2020
{
2121
// MenuGroup
2222
type: 'group',
23-
title: 'Top Menu Group with children',
23+
label: 'Top Menu Group with children',
2424
children: [
2525
{
2626
// MenuItem
27-
title: 'Menu Item 1',
27+
label: 'Menu Item 1',
2828
key: 'inner1',
2929
},
3030
{
@@ -33,30 +33,30 @@ export default () => (
3333
},
3434
{
3535
// MenuItem
36-
title: 'Menu Item 2',
36+
label: 'Menu Item 2',
3737
key: 'inner2',
3838
},
3939
],
4040
},
4141
{
4242
// SubMenu
43-
title: 'SubMenu',
43+
label: 'SubMenu',
4444
key: 'sub1',
4545
children: [
4646
{
4747
// MenuItem
48-
title: 'Menu Item 1-1',
48+
label: 'Menu Item 1-1',
4949
key: 'inner11',
5050
},
5151

5252
{
5353
// SubMenu
54-
title: 'SubMenu inner',
54+
label: 'SubMenu inner',
5555
key: 'sub1-1',
5656
children: [
5757
{
5858
// MenuItem
59-
title: 'Menu Item 111',
59+
label: 'Menu Item 111',
6060
key: 'inner1-1-1',
6161
},
6262
],

src/MenuItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useMenuId } from './context/IdContext';
1515
import PrivateContext from './context/PrivateContext';
1616

1717
export interface MenuItemProps
18-
extends Omit<MenuItemType, 'title' | 'key'>,
18+
extends Omit<MenuItemType, 'label' | 'key'>,
1919
Omit<
2020
React.HTMLAttributes<HTMLLIElement>,
2121
'onClick' | 'onMouseEnter' | 'onMouseLeave' | 'onSelect'

src/MenuItemGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { useFullPath, useMeasure } from './context/PathContext';
77
import type { MenuItemGroupType } from './interface';
88

99
export interface MenuItemGroupProps
10-
extends Omit<MenuItemGroupType, 'type' | 'children'> {
10+
extends Omit<MenuItemGroupType, 'type' | 'children' | 'label'> {
11+
title?: React.ReactNode;
12+
1113
children?: React.ReactNode;
1214

1315
/** @private Internal filled key. Do not set it directly */

src/SubMenu/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {
2222
import { useMenuId } from '../context/IdContext';
2323
import PrivateContext from '../context/PrivateContext';
2424

25-
export interface SubMenuProps extends Omit<SubMenuType, 'key' | 'children'> {
25+
export interface SubMenuProps
26+
extends Omit<SubMenuType, 'key' | 'children' | 'label'> {
27+
title?: React.ReactNode;
28+
2629
children?: React.ReactNode;
2730

2831
/** @private Used for rest popup. Do not use in your prod */

src/interface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface ItemSharedProps {
77
}
88

99
export interface SubMenuType extends ItemSharedProps {
10-
title?: React.ReactNode;
10+
label?: React.ReactNode;
1111

1212
children: ItemType[];
1313

@@ -35,7 +35,7 @@ export interface SubMenuType extends ItemSharedProps {
3535
}
3636

3737
export interface MenuItemType extends ItemSharedProps {
38-
title?: React.ReactNode;
38+
label?: React.ReactNode;
3939

4040
disabled?: boolean;
4141

@@ -54,7 +54,7 @@ export interface MenuItemType extends ItemSharedProps {
5454
export interface MenuItemGroupType extends ItemSharedProps {
5555
type: 'group';
5656

57-
title?: React.ReactNode;
57+
label?: React.ReactNode;
5858

5959
children?: ItemType[];
6060
}

src/utils/nodeUtil.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import toArray from 'rc-util/lib/Children/toArray';
3-
import type { MenuItemType, ItemType } from '../interface';
3+
import type { ItemType } from '../interface';
44
import { Divider, MenuItem, MenuItemGroup, SubMenu } from '..';
55

66
export function parseChildren(
@@ -38,23 +38,23 @@ function convertItemsToNodes(list: ItemType[]) {
3838
return (list || [])
3939
.map((opt, index) => {
4040
if (opt && typeof opt === 'object') {
41-
const { children, key, type, ...restProps } = opt as any;
41+
const { label, children, key, type, ...restProps } = opt as any;
4242
const mergedKey = key ?? `tmp-${index}`;
4343

4444
// MenuItemGroup & SubMenuItem
4545
if (children || type === 'group') {
4646
if (type === 'group') {
4747
// Group
4848
return (
49-
<MenuItemGroup key={mergedKey} {...restProps}>
49+
<MenuItemGroup key={mergedKey} {...restProps} title={label}>
5050
{convertItemsToNodes(children)}
5151
</MenuItemGroup>
5252
);
5353
}
5454

5555
// Sub Menu
5656
return (
57-
<SubMenu key={mergedKey} {...restProps}>
57+
<SubMenu key={mergedKey} {...restProps} title={label}>
5858
{convertItemsToNodes(children)}
5959
</SubMenu>
6060
);
@@ -65,10 +65,9 @@ function convertItemsToNodes(list: ItemType[]) {
6565
return <Divider key={mergedKey} {...restProps} />;
6666
}
6767

68-
const { title, ...restMenuItemProps } = restProps as MenuItemType;
6968
return (
70-
<MenuItem key={mergedKey} {...restMenuItemProps}>
71-
{title}
69+
<MenuItem key={mergedKey} {...restProps}>
70+
{label}
7271
</MenuItem>
7372
);
7473
}

tests/Options.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ describe('Options', () => {
1313
// Invalid
1414
null,
1515
{
16-
title: 'SubMenu',
16+
label: 'SubMenu',
1717
key: 'sub1',
1818
children: [
1919
{
2020
type: 'group',
21-
title: 'Menu Group',
21+
label: 'Menu Group',
2222
children: [
2323
{
24-
title: 'Menu Item 1',
24+
label: 'Menu Item 1',
2525
key: '1',
2626
},
2727
{
28-
title: 'Menu Item 2',
28+
label: 'Menu Item 2',
2929
key: '2',
3030
},
3131
],

0 commit comments

Comments
 (0)