Skip to content

Commit

Permalink
[NO JIRA][BpkPopover]: Reinstate renderTarget prop for rendering in D…
Browse files Browse the repository at this point in the history
…OM at specific location (#3527)
  • Loading branch information
olliecurtis authored Jul 11, 2024
1 parent 78bcf0b commit b708ebc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion examples/bpk-component-popover/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ const DefaultExample = () => (
</Spacer>
);

const WithCustomRenderTargetExample = () => (
<Spacer>
<div id="my-target" />
<PopoverContainer id="my-popover-1" renderTarget={() => document.getElementById('my-target')} />
</Spacer>
);

const WithoutArrowExample = () => (
<Spacer>
<PopoverContainer id="my-popover-2" displayArrow={false} />
Expand Down Expand Up @@ -176,7 +183,7 @@ const InputTriggerExample = () => (

const WithActionButtonExample = () => (
<Spacer>
<PopoverContainer id="my-popover" actionText="Action" onAction={() => {}} />
<PopoverContainer id="my-popover" actionText="Action" onAction={() => { }} />
</Spacer>
);

Expand All @@ -188,6 +195,7 @@ const VisualExample = () => (

export {
DefaultExample,
WithCustomRenderTargetExample,
WithoutArrowExample,
WithLabelAsTitleExample,
WithNoCloseButtonIconExample,
Expand Down
2 changes: 2 additions & 0 deletions examples/bpk-component-popover/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import BpkPopover from '../../packages/bpk-component-popover';

import {
DefaultExample,
WithCustomRenderTargetExample,
WithoutArrowExample,
WithLabelAsTitleExample,
OnTheSideExample,
Expand All @@ -36,6 +37,7 @@ export default {
};

export const Default = DefaultExample;
export const WithCustomRenderTarget = WithCustomRenderTargetExample;
export const WithoutArrow = WithoutArrowExample;
export const WithLabelAsTitle = WithLabelAsTitleExample;
export const WithNoCloseButtonIcon =
Expand Down
5 changes: 4 additions & 1 deletion packages/bpk-component-popover/src/BpkPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type Props = CloseButtonProps & {
closeButtonLabel?: string;
actionText?: string;
onAction?: () => void;
renderTarget?: () => HTMLElement | HTMLElement | null;
};

const BpkPopover = ({
Expand All @@ -125,6 +126,7 @@ const BpkPopover = ({
onClose,
padded = true,
placement = 'bottom',
renderTarget = () => null,
showArrow = true,
target,
...rest
Expand Down Expand Up @@ -186,12 +188,13 @@ const BpkPopover = ({
const bodyClassNames = getClassName(padded && 'bpk-popover__body--padded');

const labelId = `bpk-popover-label-${id}`;
const renderElement = typeof renderTarget === 'function' ? renderTarget() : renderTarget;

return (
<>
{targetElement}
{isOpenState && (
<FloatingPortal>
<FloatingPortal root={renderElement}>
<FloatingFocusManager context={context}>
<div
className={getClassName('bpk-popover--container')}
Expand Down

0 comments on commit b708ebc

Please sign in to comment.