Skip to content

Commit

Permalink
Updated appendTo based on new Popper logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Feb 10, 2023
1 parent 5f7d441 commit e6222bc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 71 deletions.
51 changes: 17 additions & 34 deletions packages/react-core/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
const transitionTimerRef = React.useRef(null);
const showTimerRef = React.useRef(null);
const hideTimerRef = React.useRef(null);
const containerRef = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
onMount();
Expand Down Expand Up @@ -455,41 +454,25 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
</FocusTrap>
);

const getInlineReference = () => {
if (reference) {
if ((reference as React.RefObject<any>)?.current) {
return (reference as React.RefObject<any>)?.current.parentElement;
} else if (typeof reference === 'function') {
return reference()?.parentElement;
}
}

return containerRef?.current;
};

const popoverPopper = (
<Popper
trigger={children}
reference={reference}
popper={content}
popperMatchesTriggerWidth={false}
appendTo={appendTo === 'inline' ? getInlineReference || undefined : appendTo}
isVisible={visible}
positionModifiers={positionModifiers}
distance={distance}
placement={position}
onTriggerClick={onTriggerClick}
onDocumentClick={onDocumentClick}
onDocumentKeyDown={onDocumentKeyDown}
enableFlip={enableFlip}
zIndex={zIndex}
flipBehavior={flipBehavior}
/>
);

return (
<PopoverContext.Provider value={{ headerComponent }}>
{appendTo === 'inline' && children ? <div ref={containerRef}>{popoverPopper}</div> : popoverPopper}
<Popper
trigger={children}
reference={reference}
popper={content}
popperMatchesTriggerWidth={false}
appendTo={appendTo}
isVisible={visible}
positionModifiers={positionModifiers}
distance={distance}
placement={position}
onTriggerClick={onTriggerClick}
onDocumentClick={onDocumentClick}
onDocumentKeyDown={onDocumentKeyDown}
enableFlip={enableFlip}
zIndex={zIndex}
flipBehavior={flipBehavior}
/>
</PopoverContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,61 @@

exports[`popover can close from content (uncontrolled) 1`] = `
<DocumentFragment>
<div>
<div
style="display: contents;"
<div
style="display: contents;"
>
<button
id="uncontrolled-toggle"
>
<button
id="uncontrolled-toggle"
>
Toggle Popover
</button>
</div>
Toggle Popover
</button>
</div>
</DocumentFragment>
`;

exports[`popover can have a custom minimum width 1`] = `
<DocumentFragment>
<div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
</div>
</DocumentFragment>
`;

exports[`popover can specify position as object value 1`] = `
<DocumentFragment>
<div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
</div>
</DocumentFragment>
`;

exports[`popover renders close-button, header and body 1`] = `
<DocumentFragment>
<div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
</div>
</DocumentFragment>
`;

exports[`popover renders in strict mode 1`] = `
<DocumentFragment>
<div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
<div
style="display: contents;"
>
<div>
Toggle Popover
</div>
</div>
</DocumentFragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class PopoverDemo extends Component {
bodyContent="I have a custom heading level."
footerContent="Popover footer"
headerComponent="h1"
position="auto"
>
<button id="popover-heading-level-toggle">Toggle Popover</button>
</Popover>
Expand Down

0 comments on commit e6222bc

Please sign in to comment.