From c47dc4d13bf5f788d133deace6e61a06066ad7bd Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 6 Feb 2024 14:12:08 +0100 Subject: [PATCH] :recycle: Fikset kommentarer fra git-pr --- @navikt/core/react/src/overlays/portal/Portal.tsx | 11 +++++------ .../util/types/{WithAsChild.ts => AsChildProps.ts} | 2 +- @navikt/core/react/src/util/types/index.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) rename @navikt/core/react/src/util/types/{WithAsChild.ts => AsChildProps.ts} (97%) diff --git a/@navikt/core/react/src/overlays/portal/Portal.tsx b/@navikt/core/react/src/overlays/portal/Portal.tsx index d3decfdb19..7023d0f08f 100644 --- a/@navikt/core/react/src/overlays/portal/Portal.tsx +++ b/@navikt/core/react/src/overlays/portal/Portal.tsx @@ -2,7 +2,7 @@ import React, { HTMLAttributes, forwardRef } from "react"; import ReactDOM from "react-dom"; import { useProvider } from "../../provider"; import { Slot } from "../../util/Slot"; -import { WithAsChild } from "../../util/types"; +import { AsChildProps } from "../../util/types"; interface PortalBaseProps extends HTMLAttributes { /** @@ -11,20 +11,19 @@ interface PortalBaseProps extends HTMLAttributes { rootElement?: HTMLElement | null; } -export type PortalProps = PortalBaseProps & WithAsChild; +export type PortalProps = PortalBaseProps & AsChildProps; export const Portal = forwardRef( ({ rootElement, asChild, ...rest }, ref) => { const contextRoot = useProvider()?.rootElement; - const _rootContainer = - rootElement ?? contextRoot ?? globalThis?.document?.body; + const root = rootElement ?? contextRoot ?? globalThis?.document?.body; const Component = asChild ? Slot : "div"; - return _rootContainer + return root ? ReactDOM.createPortal( , - _rootContainer, + root, ) : null; }, diff --git a/@navikt/core/react/src/util/types/WithAsChild.ts b/@navikt/core/react/src/util/types/AsChildProps.ts similarity index 97% rename from @navikt/core/react/src/util/types/WithAsChild.ts rename to @navikt/core/react/src/util/types/AsChildProps.ts index 27ac857a95..b291dbb12a 100644 --- a/@navikt/core/react/src/util/types/WithAsChild.ts +++ b/@navikt/core/react/src/util/types/AsChildProps.ts @@ -1,4 +1,4 @@ -export type WithAsChild = +export type AsChildProps = | { children: React.ReactElement | false | null; /** diff --git a/@navikt/core/react/src/util/types/index.ts b/@navikt/core/react/src/util/types/index.ts index 44c67272a1..60c317deb5 100644 --- a/@navikt/core/react/src/util/types/index.ts +++ b/@navikt/core/react/src/util/types/index.ts @@ -1,2 +1,2 @@ export type { OverridableComponent } from "./OverridableComponent"; -export type { WithAsChild } from "./WithAsChild"; +export type { AsChildProps } from "./AsChildProps";