Skip to content

Commit

Permalink
Position AnchoredOverlay directly on style property (#1381)
Browse files Browse the repository at this point in the history
* Position AnchoredOverlay directly on style property

* changeset
  • Loading branch information
jfuchs committed Aug 18, 2021
1 parent 557f839 commit b31f085
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-rice-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': minor
---

AnchoredOverlay positions are set directly on style property
2 changes: 1 addition & 1 deletion src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({
[overlayRef.current]
)
const overlayPosition = useMemo(() => {
return position && {top: `${position.top}px`, left: `${position.left}px`, anchorSide: position.anchorSide}
return position && {style: {top: `${position.top}px`, left: `${position.left}px`}, anchorSide: position.anchorSide}
}, [position])

useEffect(() => {
Expand Down
8 changes: 3 additions & 5 deletions src/__tests__/__snapshots__/AnchoredOverlay.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ Object {
-webkit-animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
visibility: var(--styled-overlay-visibility);
top: 4px;
left: 0px;
}
.c2:focus {
Expand Down Expand Up @@ -217,7 +215,7 @@ Object {
data-focus-trap="active"
height="auto"
role="none"
style="--styled-overlay-visibility: visible;"
style="--styled-overlay-visibility: visible; top: 4px; left: 0px;"
width="auto"
>
<button
Expand Down Expand Up @@ -257,11 +255,11 @@ Object {
style="position: relative; z-index: 1;"
>
<div
class="Overlay__StyledOverlay-jhwkzw-0 leFwDU"
class="Overlay__StyledOverlay-jhwkzw-0 kVoHwu"
data-focus-trap="active"
height="auto"
role="none"
style="--styled-overlay-visibility: visible;"
style="--styled-overlay-visibility: visible; top: 4px; left: 0px;"
width="auto"
>
<button
Expand Down
3 changes: 1 addition & 2 deletions src/stories/useAnchoredPosition.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ export const WithPortal = () => {
<Portal>
<Float
ref={floatingElementRef as React.RefObject<HTMLDivElement>}
top={position?.top ?? 0}
left={position?.left ?? 0}
style={{top: `${position?.top ?? 0}px`, left: `${position?.left ?? 0}px`}}
width={250}
height={400}
sx={{visibility: position ? 'visible' : 'hidden'}}
Expand Down

0 comments on commit b31f085

Please sign in to comment.