Skip to content

Commit

Permalink
Merge pull request #14 from thompsongl/contextMenuM
Browse files Browse the repository at this point in the history
Prevents passing undefined size through to menu items
  • Loading branch information
andreadelrio authored Jan 14, 2021
2 parents e2e59ea + c076074 commit d73573a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
<div>
<EuiResizeObserver onResize={[Function: onResize]}>
<div>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -573,7 +573,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -595,7 +595,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
<div>
<EuiResizeObserver onResize={[Function: onResize]}>
<div>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -604,7 +604,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand Down Expand Up @@ -654,7 +654,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
<div>
<EuiResizeObserver onResize={[Function: onResize]}>
<div>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={0} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -663,7 +663,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={1} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -685,7 +685,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
<div>
<EuiResizeObserver onResize={[Function: onResize]}>
<div>
<EuiContextMenuItem data-counter={2} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={2} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={2}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -694,7 +694,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={3} buttonRef={[Function: bound ]} size={[undefined]}>
<EuiContextMenuItem data-counter={3} buttonRef={[Function: buttonRef]}>
<button disabled={false} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={3}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand Down
26 changes: 16 additions & 10 deletions src/components/context_menu/context_menu_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { CommonProps, NoArgCallback, keysOf } from '../common';
import { EuiIcon } from '../icon';
import { EuiResizeObserver } from '../observer/resize_observer';
import { cascadingMenuKeys } from '../../services';
import { EuiContextMenuItem } from './context_menu_item';
import {
EuiContextMenuItem,
EuiContextMenuItemProps,
} from './context_menu_item';

export type EuiContextMenuPanelHeightChangeHandler = (height: number) => void;
export type EuiContextMenuPanelTransitionType = 'in' | 'out';
Expand Down Expand Up @@ -404,7 +407,7 @@ export class EuiContextMenuPanel extends Component<Props, State> {
this.updateFocus();
}

menuItemRef = (index: number, node: HTMLElement) => {
menuItemRef = (index: number, node: HTMLElement | null) => {
// There's a weird bug where if you navigate to a panel without items, then this callback
// is still invoked, so we have to do a truthiness check.
if (node) {
Expand Down Expand Up @@ -495,14 +498,17 @@ export class EuiContextMenuPanel extends Component<Props, State> {

const content =
items && items.length
? items.map((MenuItem, index) =>
MenuItem.type === EuiContextMenuItem
? cloneElement(MenuItem, {
buttonRef: this.menuItemRef.bind(this, index),
size,
})
: MenuItem
)
? items.map((MenuItem, index) => {
const cloneProps: Partial<EuiContextMenuItemProps> = {
buttonRef: (node) => this.menuItemRef(index, node),
};
if (size) {
cloneProps.size = size;
}
return MenuItem.type === EuiContextMenuItem
? cloneElement(MenuItem, cloneProps)
: MenuItem;
})
: children;

return (
Expand Down

0 comments on commit d73573a

Please sign in to comment.