Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-spiders-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update the `AnchoredOverlay` component so that the `ref` value is not overridden when spreading props
18 changes: 17 additions & 1 deletion packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
onClickOutside={onClickOutside}
ignoreClickRefs={[anchorRef]}
onEscape={onEscape}
ref={updateOverlayRef}
role="none"
visibility={position ? 'visible' : 'hidden'}
height={height}
Expand All @@ -262,6 +261,12 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
className={className}
preventOverflow={preventOverflow}
{...overlayProps}
ref={node => {
if (overlayProps?.ref) {
assignRef(overlayProps.ref, node)
}
updateOverlayRef(node)
}}
>
{showXIcon ? (
<div className={classes.ResponsiveCloseButtonContainer}>
Expand All @@ -288,4 +293,15 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
)
}

function assignRef<T>(
ref: React.MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined,
value: T | null,
) {
if (typeof ref === 'function') {
ref(value)
} else if (ref) {
ref.current = value
}
}
Comment on lines +296 to +305

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignRef utility function is duplicating functionality that already exists in the codebase. Consider using the existing useRefObjectAsForwardedRef hook or extracting assignRef to a shared utility location since it's a common ref-handling pattern that could be reused across components.

Copilot uses AI. Check for mistakes.

AnchoredOverlay.displayName = 'AnchoredOverlay'
Loading