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

Context menu allow jsx #2817

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ exports[`EuiContextMenu is rendered 1`] = `
/>
`;

exports[`EuiContextMenu panel item can contain JSX 1`] = `
<div
class="euiContextMenu"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<div
class="euiPopoverTitle"
>
<span
class="euiContextMenu__itemLayout"
>
3
</span>
</div>
<div>
<div>
<button
class="euiContextMenuItem"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
<span
style="color:tomato"
>
foo
</span>
</span>
</span>
</button>
</div>
</div>
</div>
</div>
`;

exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 1`] = `
<div
class="euiContextMenu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ exports[`EuiContextMenu is rendered 1`] = `
/>
`;

exports[`EuiContextMenu panel item can contain JSX 1`] = `
<div
class="euiContextMenu"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<div
class="euiPopoverTitle"
>
<span
class="euiContextMenu__itemLayout"
>
3
</span>
</div>
<div>
<div>
<button
class="euiContextMenuItem"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
<span
style="color:tomato"
>
foo
</span>
</span>
</span>
</button>
</div>
</div>
</div>
</div>
`;

exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 1`] = `
<div
class="euiContextMenu"
Expand Down
21 changes: 20 additions & 1 deletion src/components/context_menu/context_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { requiredProps, takeMountedSnapshot } from '../../test';
import { EuiContextMenu } from './context_menu';
import { setTimeout } from 'timers';

const panel3 = {
id: 3,
title: '3',
items: [
{
name: <span style={{ color: 'tomato' }}>foo</span>,
key: 'foo',
},
],
};

const panel2 = {
id: 2,
title: '2',
Expand Down Expand Up @@ -42,7 +53,7 @@ const panel0 = {
],
};

const panels = [panel0, panel1, panel2];
const panels = [panel0, panel1, panel2, panel3];

export const tick = (ms = 0) =>
new Promise(resolve => {
Expand All @@ -56,6 +67,14 @@ describe('EuiContextMenu', () => {
expect(component).toMatchSnapshot();
});

it('panel item can contain JSX', () => {
const component = render(
<EuiContextMenu panels={panels} initialPanelId={3} />
);

expect(component).toMatchSnapshot();
});

describe('props', () => {
describe('panels and initialPanelId', () => {
it('renders the referenced panel', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/context_menu/context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type EuiContextMenuPanelItemDescriptor = Omit<
EuiContextMenuItemProps,
'hasPanel'
> & {
name: string;
name: React.ReactNode;
key?: string;
panel?: EuiContextMenuPanelId;
};

Expand Down Expand Up @@ -260,6 +261,7 @@ export class EuiContextMenu extends Component<EuiContextMenuProps, State> {
const {
panel,
name,
key,
icon,
onClick,
toolTipTitle,
Expand All @@ -285,7 +287,7 @@ export class EuiContextMenu extends Component<EuiContextMenuProps, State> {

return (
<EuiContextMenuItem
key={name}
key={key || (typeof name === 'string' ? name : undefined) || index}
icon={icon}
onClick={onClickHandler}
hasPanel={Boolean(panel)}
Expand Down