Skip to content

Commit

Permalink
Fix overlay position (#1201)
Browse files Browse the repository at this point in the history
Co-authored-by: dgreif <dustin.greif@gmail.com>
  • Loading branch information
T-Hugs and dgreif committed Apr 30, 2021
1 parent 344e35d commit 3c13d03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/olive-planets-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Fix overlay position when using an AnchoredOverlay
5 changes: 4 additions & 1 deletion src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({renderAnchor, c
},
[overlayRef.current]
)
const overlayPosition = useMemo(() => {
return position && {top: `${position.top}px`, left: `${position.left}px`}
}, [position])

useFocusZone({containerRef: overlayRef, disabled: !open || focusType !== 'list' || !position})
useFocusTrap({containerRef: overlayRef, disabled: !open || focusType !== 'list' || !position})
Expand All @@ -114,7 +117,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({renderAnchor, c
ref={updateOverlayRef}
role="listbox"
visibility={position ? 'visible' : 'hidden'}
{...position}
{...overlayPosition}
>
{children}
</Overlay>
Expand Down

1 comment on commit 3c13d03

@vercel
Copy link

@vercel vercel bot commented on 3c13d03 Apr 30, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.