diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e59a99879..a79e08076cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Changed SASS comments to non-compiled comments in invisibles files ([#2807](https://github.com/elastic/eui/pull/2807)) - Added `rowHeader` prop to `EuiBasicTable` to allow consumers to set the identifying cell in a row ([#2802](https://github.com/elastic/eui/pull/2802)) - Improved `EuiDescribedFormGroup` accessibility by avoiding duplicated output in screen readers ([#2783](https://github.com/elastic/eui/pull/2783)) +- Added optional `key` attribute to `EuiContextMenu` items and relaxed `name` attribute to allow any React node ([#2817](https://github.com/elastic/eui/pull/2817)) **Bug fixes** diff --git a/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap b/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap index 7ccbae34290..07dd69b196e 100644 --- a/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap +++ b/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap @@ -8,6 +8,49 @@ exports[`EuiContextMenu is rendered 1`] = ` /> `; +exports[`EuiContextMenu panel item can contain JSX 1`] = ` +
+
+
+ + 3 + +
+
+
+ +
+
+
+
+`; + exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 1`] = `
`; +exports[`EuiContextMenu panel item can contain JSX 1`] = ` +
+
+
+ + 3 + +
+
+
+ +
+
+
+
+`; + exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 1`] = `
foo, + key: 'foo', + }, + ], +}; + const panel2 = { id: 2, title: '2', @@ -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 => { @@ -56,6 +67,14 @@ describe('EuiContextMenu', () => { expect(component).toMatchSnapshot(); }); + it('panel item can contain JSX', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + describe('props', () => { describe('panels and initialPanelId', () => { it('renders the referenced panel', () => { diff --git a/src/components/context_menu/context_menu.tsx b/src/components/context_menu/context_menu.tsx index f333533321d..c3c5ef34aa2 100644 --- a/src/components/context_menu/context_menu.tsx +++ b/src/components/context_menu/context_menu.tsx @@ -23,7 +23,8 @@ export type EuiContextMenuPanelItemDescriptor = Omit< EuiContextMenuItemProps, 'hasPanel' > & { - name: string; + name: React.ReactNode; + key?: string; panel?: EuiContextMenuPanelId; }; @@ -260,6 +261,7 @@ export class EuiContextMenu extends Component { const { panel, name, + key, icon, onClick, toolTipTitle, @@ -285,7 +287,7 @@ export class EuiContextMenu extends Component { return (