Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support extra option #734

Merged
merged 8 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@
color: #777 !important;
}
}

&-item {
> span {
float: right;
font-size: 14px;
coding-ice marked this conversation as resolved.
Show resolved Hide resolved
}
}

&-item-divider {
height: 1px;
margin: 1px 0;
Expand Down
1 change: 1 addition & 0 deletions docs/examples/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default () => (
// MenuItem
label: 'Top Menu Item',
key: 'top',
extra: '⌘B',
},
{
// MenuGroup
Expand Down
2 changes: 2 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface MenuItemType extends ItemSharedProps {

itemIcon?: RenderIconType;

extra?: string;
coding-ice marked this conversation as resolved.
Show resolved Hide resolved

key: React.Key;

// >>>>> Active
Expand Down
3 changes: 2 additions & 1 deletion src/utils/nodeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function convertItemsToNodes(
return (list || [])
.map((opt, index) => {
if (opt && typeof opt === 'object') {
const { label, children, key, type, ...restProps } = opt as any;
const { label, children, key, type, extra, ...restProps } = opt as any;
const mergedKey = key ?? `tmp-${index}`;

// MenuItemGroup & SubMenuItem
Expand Down Expand Up @@ -50,6 +50,7 @@ function convertItemsToNodes(
return (
<MergedMenuItem key={mergedKey} {...restProps}>
{label}
{!!extra && <span>{extra}</span>}
coding-ice marked this conversation as resolved.
Show resolved Hide resolved
</MergedMenuItem>
);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/MenuItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,15 @@ describe('MenuItem', () => {

expect(container.querySelector('li')).toMatchSnapshot();
});

it('should set extra to option', () => {
const { container } = render(
<Menu>
<MenuItem extra="⌘B">test</MenuItem>
</Menu>,
);

expect(container.querySelector('li')).toMatchSnapshot();
});
});
});
12 changes: 12 additions & 0 deletions tests/__snapshots__/MenuItem.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MenuItem overwrite default role should set extra to option 1`] = `
<li
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-tmp_key-0"
extra="⌘B"
coding-ice marked this conversation as resolved.
Show resolved Hide resolved
role="menuitem"
tabindex="-1"
>
test
</li>
`;

exports[`MenuItem overwrite default role should set role to listitem 1`] = `
<li
class="rc-menu-item"
Expand Down
Loading