Skip to content

Commit

Permalink
♻️ Fikset kommentarer fra git-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Feb 6, 2024
1 parent 1583001 commit c47dc4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions @navikt/core/react/src/overlays/portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement> {
/**
Expand All @@ -11,20 +11,19 @@ interface PortalBaseProps extends HTMLAttributes<HTMLDivElement> {
rootElement?: HTMLElement | null;
}

export type PortalProps = PortalBaseProps & WithAsChild;
export type PortalProps = PortalBaseProps & AsChildProps;

export const Portal = forwardRef<HTMLDivElement, PortalProps>(
({ 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(
<Component ref={ref} data-aksel-portal="" {...rest} />,
_rootContainer,
root,
)
: null;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type WithAsChild =
export type AsChildProps =
| {
children: React.ReactElement | false | null;
/**
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/react/src/util/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { OverridableComponent } from "./OverridableComponent";
export type { WithAsChild } from "./WithAsChild";
export type { AsChildProps } from "./AsChildProps";

0 comments on commit c47dc4d

Please sign in to comment.