Skip to content

Commit

Permalink
fix(Popover): Update component to forward ref
Browse files Browse the repository at this point in the history
  • Loading branch information
hussam-i-am committed Nov 20, 2024
1 parent 56ff1c0 commit 75e709e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-jobs-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Add forward ref to Popover
15 changes: 7 additions & 8 deletions packages/react/src/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ export type PopoverProps = {
} & StyledPopoverProps &
HTMLProps<HTMLDivElement>

const Popover: React.FC<React.PropsWithChildren<PopoverProps>> = ({
className,
caret = 'top',
open,
relative,
...props
}) => {
const Popover = React.forwardRef<HTMLElement, PopoverProps>(function Popover(
{className, caret = 'top', open, relative, ...props},
forwardRef,
) {
const enabled = useFeatureFlag(CSS_MODULES_FLAG)
if (enabled) {
return (
<BaseComponent
{...props}
ref={forwardRef}
data-open={open ? '' : undefined}
data-relative={relative ? '' : undefined}
data-caret={caret}
Expand All @@ -74,7 +72,8 @@ const Popover: React.FC<React.PropsWithChildren<PopoverProps>> = ({
}

return <BaseComponent {...props} className={className} caret={caret} open={open} relative={relative} />
}
})
Popover.displayName = 'Popover'

const StyledPopoverContent = toggleStyledComponent(
CSS_MODULES_FLAG,
Expand Down

0 comments on commit 75e709e

Please sign in to comment.