Skip to content

Commit

Permalink
feat(Popper): made inline logic internal to Popper
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Feb 8, 2023
1 parent dd91c73 commit 11e211f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/react-core/src/helpers/Popper/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export interface PopperProps {
/** Instead of direction and position can set the placement of the popper */
placement?: Placement;
/** The container to append the popper to. Defaults to 'document.body' */
appendTo?: HTMLElement | (() => HTMLElement);
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
/** z-index of the popper element */
zIndex?: number;
/** True to make the popper visible */
Expand Down Expand Up @@ -347,13 +347,24 @@ export const Popper: React.FunctionComponent<PopperProps> = ({
...attributes.popper
};

const menuWithPopper = React.cloneElement(popper, options);
const menuWithPopper = () => {
const localPopper = React.cloneElement(popper, options);
return popperRef ? (
localPopper
) : (
<div style={{ display: 'contents' }} ref={node => setPopperElement(node?.firstElementChild as HTMLElement)}>
{localPopper}
</div>
);
};

const getTarget: () => HTMLElement = () => {
if (typeof appendTo === 'function') {
return appendTo();
if (appendTo !== 'inline') {
if (typeof appendTo === 'function') {
return appendTo();
}
return appendTo;
}
return appendTo;
};

return (
Expand All @@ -365,16 +376,7 @@ export const Popper: React.FunctionComponent<PopperProps> = ({
)}
{ready &&
isVisible &&
ReactDOM.createPortal(
popperRef ? (
menuWithPopper
) : (
<div style={{ display: 'contents' }} ref={node => setPopperElement(node?.firstElementChild as HTMLElement)}>
{menuWithPopper}
</div>
),
getTarget()
)}
(appendTo !== 'inline' ? ReactDOM.createPortal(menuWithPopper(), getTarget()) : menuWithPopper())}
</>
);
};
Expand Down

0 comments on commit 11e211f

Please sign in to comment.