PortalProvider
PortalProvider is the Rust portal layer: it owns the process of stacking floating entries (dropdowns, toasts, tooltips) above the page and renders them through PortalRender, the member that draws one layer per entry. It is the provider half of an API surface that predates the mirrored popover components, and it is the piece use_portal() reads — a handful of the older widgets (the search suggestion dropdown among them) reach the overlay root through it.
PortalRender has no page of its own: it is the renderer PortalProvider mounts at the end of its own output, and the only way a host can build it directly is with an explicit Signal<Vec<PortalEntry>> (see "Rendering the entries" below).
- Reach for it only from a legacy Rust surface whose own popup code already calls use_portal(). New popover code should use the mirrored components (Popover, Menu, Tooltip), which carry their own layering.
- The provider is the layer host: it publishes the context, opens the fixed root and renders what has been pushed into it. It does not position dropdowns, place tooltips or style cards on its own — PortalRender's entry renderers do.
- Modal-shaped surfaces are not portal entries any more: the legacy PortalEntry::Modal / Popover variants were retired with the mirrored Modal / Popover families. Three entry kinds remain: Dropdown, Toast, Tooltip.
Import
use *; // PortalProvider, PortalEntry, PortalMaskMode, PortalRender,
// PortalPositionStrategy, TriggerPlacement, ToastPosition,
// use_portal, generate_portal_id, PORTAL_ID_COUNTER
use *; // rsx!, VNode, Callback, Signal
There is no Vue component on this side: packages/vue/src ships no HkPortalProvider. On Vue a portal is the runtime's own job (each popover, toast or tooltip teleports itself into the overlay root — ensureOverlayRoot() — and registers its band with usePopupManager()); there is no provider component to mount, so this is a Rust-only page.
PortalRender is reachable as hikari_components::portal::render::PortalRender and through the root barrel's use hikari_components::* (it lives in a pub mod render), while the prelude does not carry it; PortalContext is re-exported from hikari_components::portal explicitly.
What the provider does
It creates one entry list (Signal<Vec<PortalEntry>>), publishes it as a PortalContext — entries, add_entry, remove_entry, clear_all — and renders its children followed by a PortalRender bound to the same list. use_portal() reads that context and clones the handle, so a widget can push an entry (portal.add_entry.call(entry) — call the Callback field, not the struct), drop one (portal.remove_entry.call(id)), or wipe the layer (portal.clear_all.call(())).
Entry order is the render order, and it is also the stacking order: PortalRender numbers entries 10000 + index inside a z-index: 9999 fixed root. remove_entry retains everything whose id differs from the given one; clear_all empties the list.
Source defect — neither provider symbol is reachable from rsx!. PortalProvider is declared as pub fn PortalProvider(children: Element) -> Element — a component without a #[define_props] props struct — and PortalRender takes inline #[props(default)] parameters rather than a named props type. Inside an rsx! block both fail, each with the same macro error:
rsx! { PortalProvider { div { "…" } } }
error[E0422]: cannot find struct, variant or union type `PortalProviderProps` in this scope
rsx! { PortalRender {} }
error[E0422]: cannot find struct, variant or union type `PortalRenderProps` in this scope
Both were tried in a live example of this documentation workspace and both failed at compile time (no binary was produced): rsx! looks for a <Name>Props struct that the macro would have generated, and neither function declares one. PortalProvider cannot be called directly either — its parameter is a bare Element, while the macro rewrote the callable shape to a props struct that does not exist, so PortalProvider(children_element) fails with a type mismatch and PortalProvider(PortalProviderProps { … }) with a missing-struct error. PortalRender is the one that does have a direct shape: PortalRender(Some(signal)) compiles outside an rsx! block. Neither can stand as a fence's body, so this page carries no live Rust example; treat the snippets below as call-site shapes.
Rendering the entries
PortalRender takes entries: Option<Signal<Vec<PortalEntry>>> (default None, which renders nothing at all — no root, no div) and maps each entry to one of three renderers:
- Dropdown — a position: fixed overlay covering the viewport, pointer-events: auto, with the sheet's dimmed or transparent overlay face (mask_mode), then the dropdown surface placed by the entry's strategy: Fixed(x, y) drops it at those coordinates, TriggerBased { placement } computes from trigger_rect, MouseBased also lands on the TriggerBased path. A click on the overlay closes the entry; with close_on_select, a click on a .hk-menu-item inside closes it too.
- Toast entry — a position: fixed box (hk-toast) pinned to one of six positions by position (TopLeft … BottomRight, default BottomRight), 16 px in from the viewport edge.
- Tooltip entry — a bubble placed from trigger_rect and placement (all 12 directions), clamped 8 px inside the viewport, with an optional arrow element.
Entries animate in two phases — Appearing → Visible via a request-animation-frame, and Disappearing → removal 200 ms later — so a surface that opens and closes with motion is not abruptly removed. On the non-wasm host the animation branch is compiled out and an entry renders in its target state; use_animated_portal_entry also logs each phase, which is why the mirrors elsewhere do not use this layer.
// Inside a component that sits under a mounted provider:
let portal = use_portal;
let id = generate_portal_id;
portal.add_entry.call;
// A card the caller hands to a dropdown entry, built as an element:
let card = rsx! ;
let id = generate_portal_id;
portal.add_entry.call;
The entry types
PortalEntry is the input contract; the three variants carry what each renderer needs.
- Dropdown { id, strategy, mask_mode, children, trigger_rect, close_on_select } — trigger_rect is (x, y, width, height) in viewport coordinates, children: Element.
- Toast { id, position, children } — position: ToastPosition, children: Element.
- Tooltip { id, trigger_rect, placement, content, arrow } — content is a String, so a tooltip through this layer is plain text by construction.
PortalContext holds only entries, add_entry, remove_entry and clear_all — there is no add_toast / add_dropdown / add_tooltip helper. Every push is built by the caller as one of the three PortalEntry variants.
generate_portal_id() hands out process-unique ids (portal-0, portal-1, …) from PORTAL_ID_COUNTER, so a host that pushes entries need not invent keys.
API
Rust
Props — PortalProvider
| Prop | Type | Default | Description |
|---|---|---|---|
| children | Element | — | — |
Props — PortalRender
| Prop | Type | Default | Description |
|---|---|---|---|
| entries | Option<Signal<Vec<PortalEntry>>> | None | — |
Accessibility
- The portal root is a fixed div with pointer-events: none and z-index: 9999; it adds no role, no landmark and no name, so nothing inside it is announced differently because it is a portal.
- Focus is not managed. Pushing a dropdown or a toast entry does not move focus, trap it, or return it on removal — a host that needs a focus cycle (an "opened from here, close returns there" contract) must implement it around the entry itself.
- Dropdown's overlay closes on click but is not a dialog: no role="dialog", no aria-modal, no Escape handling. A portal dropdown therefore does not announce itself as a modal to assistive technology.
- A tooltip entry places a bubble but attaches no aria-describedby to the trigger and gives the content no role="tooltip"; a screen reader user hears nothing from it. Pass the same sentence through a real Tooltip when the text is load-bearing.
- The toast entry's renderer is the private ToastPortalEntry (its box is div.hk-toast); it is not a public component, so no host composes it directly, and the live region must come from the toast content inside it.
- Escape, scroll locking and focus return all belong to the host: the layer never reads keyboard input.