Skip to content

Commit 282cb31

Browse files
committed
fix(Popover): updates Popover for radix v1
Update Popover for addition of Portal component see #286
1 parent 00b700a commit 282cb31

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/components/Popover/Popover.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import {
33
Arrow,
44
Close,
55
Content,
6+
Portal,
67
Root,
78
Trigger,
89
} from '@radix-ui/react-popover'
910
import React, { ComponentProps, ElementRef, FC, forwardRef } from 'react'
1011
import type { AsProps, CSSProps } from '../../stitches.config'
1112
import { styled } from '../../stitches.config'
13+
import { ConditionalWrapper } from '../../utils'
1214
import { paperStyles } from '../Paper'
1315

1416
const StyledContent = styled(Content, paperStyles, {
@@ -30,16 +32,28 @@ const StyledArrow = styled(Arrow, {
3032
fill: '$paper',
3133
})
3234

33-
type PopoverContentProps = CSSProps & AsProps & ComponentProps<typeof Content>
35+
type PopoverContentProps = CSSProps &
36+
AsProps &
37+
ComponentProps<typeof Content> & {
38+
/** By default, portals your content parts into the body, set false to add at dom location. */
39+
portalled?: boolean
40+
/** Specify a container element to portal the content into. */
41+
container?: ComponentProps<typeof Portal>['container']
42+
}
3443

3544
export const PopoverContent = forwardRef<
3645
ElementRef<typeof StyledContent>,
3746
PopoverContentProps
38-
>(({ children, ...props }, forwardedRef) => (
39-
<StyledContent {...props} ref={forwardedRef}>
40-
<StyledArrow offset={-1} />
41-
{children}
42-
</StyledContent>
47+
>(({ portalled = true, container, children, ...props }, forwardedRef) => (
48+
<ConditionalWrapper
49+
condition={portalled}
50+
wrapper={(child) => <Portal container={container}>{child}</Portal>}
51+
>
52+
<StyledContent {...props} ref={forwardedRef}>
53+
<StyledArrow offset={-1} />
54+
{children}
55+
</StyledContent>
56+
</ConditionalWrapper>
4357
))
4458
PopoverContent.toString = () => `.${StyledContent.className}`
4559

0 commit comments

Comments
 (0)