Skip to content

portal()

Render a WhisqNode inside a different DOM target than its logical parent. Useful for modals, tooltips, and dropdowns that need to escape the parent’s overflow: hidden or stacking context.

function portal(target: Element, content: WhisqNode): WhisqNode;
ParamTypeDescription
targetElementDOM element to teleport content into
contentWhisqNodeAny element / component call — the portal payload

A WhisqNode that renders a marker comment at the logical location and the real content inside target. Disposing the returned node removes the teleported content.

import { signal, portal, when, div, button } from "@whisq/core";
const open = signal(false);
div(
button({ onclick: () => open.value = true }, "Open modal"),
when(() => open.value, () =>
portal(document.body, div({ class: "modal-overlay" },
div({ class: "modal-card" }, "Hello"),
)),
),
);

The modal renders inside <body> instead of nested under the logical parent, so it can span the full viewport regardless of ancestor overflow rules.