Skip to content

Commit

Permalink
fix(NavigationPopoverOverlay): Add portal to overlay to send it to th…
Browse files Browse the repository at this point in the history
…e end of the document body / changed position of popover
  • Loading branch information
pallendes committed Dec 15, 2023
1 parent 47bba88 commit 52dfb7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/components/navigation/navigation-popover-overlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Popover } from "@headlessui/react";
import * as React from "react";
import { createPortal } from "react-dom";

export const NavigationPopoverOverlay = () => {
return createPortal(
<Popover.Overlay className="fixed inset-0 z-30 translate-x-[180px] bg-modal-background" />,
document.body
);
};
7 changes: 3 additions & 4 deletions src/components/navigation/navigation-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from "react";
import { usePopper } from "react-popper";
import { NavigationPopoverButton } from "./navigation-popover-button";
import { NavigationPopoverContextProvider } from "./navigation-popover-context";
import { NavigationPopoverOverlay } from "./navigation-popover-overlay";
import { NavigationPopoverPanel } from "./navigation-popover-panel";

export interface NavigationPopoverProps {
Expand All @@ -14,7 +15,7 @@ const NavigationPopover = ({ children, showOverlay }: NavigationPopoverProps) =>
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement>();
const [popperElement, setPopperElement] = useState<HTMLDivElement>();
const { styles, attributes } = usePopper(referenceElement, popperElement, {
placement: "right-end",
placement: "bottom-start",
});

const context = {
Expand All @@ -31,9 +32,7 @@ const NavigationPopover = ({ children, showOverlay }: NavigationPopoverProps) =>
return (
<NavigationPopoverContextProvider value={context}>
<Popover>
{showOverlay && (
<Popover.Overlay className="fixed inset-0 z-30 translate-x-[180px] bg-modal-background" />
)}
{showOverlay && <NavigationPopoverOverlay />}
{children}
</Popover>
</NavigationPopoverContextProvider>
Expand Down

0 comments on commit 52dfb7e

Please sign in to comment.