Skip to content

Commit

Permalink
Merge pull request #37 from thompsongl/k8/search
Browse files Browse the repository at this point in the history
combined refs; popoverProps clean up
  • Loading branch information
cchaos authored Aug 14, 2020
2 parents f6c9498 + 066972a commit e91e60a
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import React, {
CSSProperties,
} from 'react';
import classNames from 'classnames';
import { useCombinedRefs } from '../../../services';
import { EuiSelectable, EuiSelectableProps } from '../selectable';
import { EuiPopoverTitle, EuiPopoverFooter } from '../../popover';
import { EuiPopover, Props as PopoverProps } from '../../popover/popover';
Expand Down Expand Up @@ -85,19 +86,17 @@ export const EuiSelectableTemplateSitewide: FunctionComponent<EuiSelectableTempl
/**
* Popover helpers
*/
const { closePopover: _closePopover, panelRef, width, ...popoverRest } = {
...popoverProps,
};
const [popoverRef, setPopoverRef] = useState<HTMLElement | null>(null);
const closePopover = () => {
setInputHasFocus(false);
popoverProps && popoverProps.closePopover && popoverProps.closePopover();
_closePopover && _closePopover();
};
// Width applied to the internal div
let popoverWidth: CSSProperties['width'] = 600;
if (popoverProps && popoverProps.width) {
// So it also needs to be removed from the spread
const { width, ...popoverRest } = popoverProps;
popoverWidth = popoverProps.width;
popoverProps = popoverRest;
}
const popoverWidth: CSSProperties['width'] = width || 600;
const setPanelRef = useCombinedRefs([setPopoverRef, panelRef]);

/**
* Search helpers
Expand Down Expand Up @@ -196,9 +195,8 @@ export const EuiSelectableTemplateSitewide: FunctionComponent<EuiSelectableTempl
panelPaddingSize="none"
display="block"
isOpen={inputHasFocus}
{...popoverProps}
// HELP: How to forward this ref if consumers want it
panelRef={setPopoverRef}
{...popoverRest}
panelRef={setPanelRef}
button={search}
closePopover={closePopover}>
<div style={{ width: popoverWidth, maxWidth: '100%' }}>
Expand Down

0 comments on commit e91e60a

Please sign in to comment.