Skip to content

Commit

Permalink
Merge pull request #1606 from adevinta/fix-forwardedref-popover
Browse files Browse the repository at this point in the history
fix(popover): fix ref warning when forward ref without using it
  • Loading branch information
soykje authored Oct 26, 2023
2 parents 56d8f40 + a93320b commit 2101cbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/components/popover/src/PopoverAnchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { forwardRef } from 'react'
export type AnchorProps = RadixPopover.PopoverAnchorProps

export const Anchor = forwardRef<HTMLDivElement, AnchorProps>(
({ asChild = false, children, ...rest }) => (
<RadixPopover.Anchor data-spark-component="popover-anchor" asChild={asChild} {...rest}>
({ asChild = false, children, ...rest }, ref) => (
<RadixPopover.Anchor
data-spark-component="popover-anchor"
ref={ref}
asChild={asChild}
{...rest}
>
{children}
</RadixPopover.Anchor>
)
Expand Down
5 changes: 3 additions & 2 deletions packages/components/popover/src/PopoverArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { forwardRef } from 'react'

export type ArrowProps = RadixPopover.PopoverArrowProps

export const Arrow = forwardRef<HTMLDivElement, ArrowProps>(
({ asChild = false, width = 16, height = 8, className, ...rest }) => {
export const Arrow = forwardRef<SVGSVGElement, ArrowProps>(
({ asChild = false, width = 16, height = 8, className, ...rest }, ref) => {
/**
* This is necessary to override a Radix UI behaviour.
* Radix hides the arrow when the Popover is too misaligned from its trigger element.
Expand All @@ -15,6 +15,7 @@ export const Arrow = forwardRef<HTMLDivElement, ArrowProps>(
return (
<RadixPopover.Arrow
data-spark-component="popover-arrow"
ref={ref}
className={styles}
asChild={asChild}
width={width}
Expand Down
4 changes: 2 additions & 2 deletions packages/components/popover/src/PopoverHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface HeaderProps {
}

export const Header = forwardRef<HTMLDivElement, HeaderProps>(
({ children, className, ...rest }) => {
({ children, className, ...rest }, ref) => {
const id = useId()
const { setHeaderId } = usePopover()

Expand All @@ -21,7 +21,7 @@ export const Header = forwardRef<HTMLDivElement, HeaderProps>(
}, [id, setHeaderId])

return (
<header id={id} className={cx('mb-md text-headline-2', className)} {...rest}>
<header id={id} ref={ref} className={cx('mb-md text-headline-2', className)} {...rest}>
{children}
</header>
)
Expand Down

0 comments on commit 2101cbc

Please sign in to comment.