Skip to content
// EFFECT DAYS 2026

Positioning unstable

Places a popup against an anchor element, keeps it inside a boundary, and reports where it ended up.

The kit's own popups, such as Tooltip and Select, are placed with this module. Use it for a popup the kit doesn't have. The options have the same names and defaults as the positioner props of those popups.

It has two layers:

  • place is a pure function from rectangles and options to a position. It reads no DOM, so it runs in any environment and placement can be tested without a browser's layout.
  • TrackPosition is a stream mount for the positioner, the element that holds the popup. It measures the anchor, the positioner and the arrow, calls place, writes the result on the positioner as inline style, and reports a Placement whenever the side, the alignment, the anchor's visibility or the arrow's centring changes.

Building a popup

  1. Spread PositionerFields into the component's props.
  2. Keep a Placement in the Model, with a message that stores each one the mount reports.
  3. Build the mount's args from the props with trackArgs.
  4. Draw the positioner as a manual popover with positionerStyle in its inline style, and issue TrackPosition on it while the popup shows.
  5. Write data-side, data-align and the like from the Placement, and give an arrow arrowStyle.

The example on TrackPosition does all five.

What the mount writes

On the positioner, as inline style:

  • left and top: the position
  • --anchor-width, --anchor-height: the anchor's size
  • --available-width, --available-height: the space between the anchor and the edge of the boundary, for a max-height
  • --transform-origin: the point on the anchor the popup grows from
  • the arrow's offset, in a variable that arrowStyle reads
  • with offsetAsPadding, the side offset as padding on the side that faces the anchor

With leaveCoordinates, it writes everything but left and top, for a component that places the positioner itself and still wants the variables and the Placement.

They survive view-rendered changes to the positioner's style attribute, and stay after the mount ends, so a closing popup keeps its place through an exit transition.

While it runs, the mount places the popup again when the window resizes, when the visual viewport resizes or scrolls, when the positioner changes size, and, unless disableAnchorTracking is set, when anything outside the positioner scrolls or the anchor changes size or moves. Scrolling inside the positioner, such as a long list, doesn't move it.

Gotchas

  • left and top are measured from the viewport, plus the page's scroll for "absolute". So the positioner has to be positioned against the viewport, as a popover or a modal dialog in the top layer is. Inside a transformed or positioned ancestor it lands in the wrong place, unless topLayer is false.
  • With topLayer: false, the positioner is an ordinary element where the view draws it, and left and top are measured from its containing block: the nearest positioned or transformed ancestor for "absolute", the nearest transformed one or else the viewport for "fixed". Draw it without popover, so an ancestor's overflow, position and stacking context apply to it, as to any other element. "clipping-ancestors" is then the area its ancestors' overflow leaves visible, inside the viewport, so the popup flips and shifts to stay in a small scrolling box.
  • Collisions use the visual viewport (the visible area under pinch-zoom or a software keyboard), not the layout viewport.
  • The positioner has to be laid out while the mount runs, so issue the mount only while the popup shows.
  • The anchor is the first element in the positioner's tree (the document, or its shadow root) that matches anchorSelector, so build the selector from h.id to keep two instances apart. While nothing matches, the mount reports anchorHidden.
  • anchorRect places the popup against a rectangle in the viewport, such as the point a context menu opened at, instead of an element. Nothing moves it, so use "fixed" as the positionMethod.
  • An arrow needs an id, passed as arrowId, and a size of its own.
  • inline places the popup against one line of a link that wraps, instead of the box around all its lines.
  • There are no function-valued offsets.

Example A popup below its anchor, and above it when it doesn't fit

import { Positioning } from "effect/ui/kit"
const viewport = { x: 0, y: 0, width: 1000, height: 800 }
const options = Positioning.resolveOptions({ sideOffset: 8 }, { side: "bottom" })
const below = Positioning.place({
anchor: { x: 400, y: 400, width: 100, height: 40 },
popup: { width: 200, height: 100 },
arrow: null,
boundary: viewport,
anchorClip: viewport,
rtl: false,
options
})
if (below.side !== "bottom" || below.x !== 350 || below.y !== 448) throw new Error("not below the anchor")
const above = Positioning.place({
anchor: { x: 400, y: 700, width: 100, height: 40 },
popup: { width: 200, height: 100 },
arrow: null,
boundary: viewport,
anchorClip: viewport,
rtl: false,
options
})
if (above.side !== "top" || above.y !== 592) throw new Error("not flipped above the anchor")
36 exports Since v4.2.0 Source

Constants

The default collisionAvoidance of other popups, such as a tooltip or a popover: when neither side fits, it tries the other axis.

Signature

declare const popupCollisionAvoidance: CollisionAvoidance

Constructors

Since v4.2.0

Fills in the defaults of a popup's positioning props.

Details

defaults holds what differs between components: the side a popup shows on when its props name none, its collisionAvoidance, which is popupCollisionAvoidance when left out, and shiftCrossAxis, false when left out. With shiftCrossAxis, unless collisionAvoidance.side is "flip", the popup keeps its side and slides toward the anchor to stay inside the boundary, as with sticky, so it can cover the anchor.

Signature

declare function resolveOptions(options: {
readonly align?: "start" | "end" | "center";
readonly alignOffset?: number;
readonly anchor?: string | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly arrowPadding?: number;
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly collisionBoundary?: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly collisionPadding?: number | {
readonly bottom?: number;
readonly left?: number;
readonly right?: number;
readonly top?: number;
};
readonly disableAnchorTracking?: boolean;
readonly positionMethod?: "fixed" | "absolute";
readonly side?: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset?: number;
readonly sticky?: boolean;
readonly topLayer?: boolean;
}, defaults: {
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly shiftCrossAxis?: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
}): {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
}

trackArgs

unstable
Since v4.2.0

Makes the args of TrackPosition from a popup's positioning props.

Details

popup holds what the component decides:

  • side: the side the popup shows on when its props name none.
  • collisionAvoidance: its default, popupCollisionAvoidance when left out.
  • anchorSelector: a CSS selector for its anchor, which the anchor prop overrides.
  • anchorRect: a rectangle in the viewport to place against instead of that anchor, which the anchor prop also overrides.
  • shiftCrossAxis: see resolveOptions. False when left out.
  • arrowId: the id of its arrow, when it draws one.
  • offsetAsPadding: see TrackPositionArgs. False when left out.
  • leaveCoordinates: see TrackPositionArgs. False when left out.
  • inline and inlineHit: see TrackPositionArgs. False and null when left out. inlineHit is dropped while props.anchor gives another anchor, an element or a rectangle, since the pointer rested on the popup's own.

topLayer comes from the props, true when left out.

The result is plain data, so a view can also read the defaults from it: args.options.side is the side to render before the mount first reports.

Signature

declare function trackArgs(props: {
readonly align?: "start" | "end" | "center";
readonly alignOffset?: number;
readonly anchor?: string | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly arrowPadding?: number;
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly collisionBoundary?: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly collisionPadding?: number | {
readonly bottom?: number;
readonly left?: number;
readonly right?: number;
readonly top?: number;
};
readonly disableAnchorTracking?: boolean;
readonly positionMethod?: "fixed" | "absolute";
readonly side?: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset?: number;
readonly sticky?: boolean;
readonly topLayer?: boolean;
}, popup: {
readonly anchorRect?: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | null;
readonly anchorSelector: string;
readonly arrowId?: string | null;
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly inline?: boolean;
readonly inlineHit?: {
readonly line: number | null;
readonly x: number;
readonly y: number;
} | null;
readonly leaveCoordinates?: boolean;
readonly offsetAsPadding?: boolean;
readonly shiftCrossAxis?: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
}): {
readonly anchorRect?: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | null;
readonly anchorSelector: string;
readonly arrowId: string | null;
readonly collisionBoundary: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly disableAnchorTracking: boolean;
readonly inline?: boolean;
readonly inlineHit?: {
readonly line: number | null;
readonly x: number;
readonly y: number;
} | null;
readonly leaveCoordinates?: boolean;
readonly offsetAsPadding: boolean;
readonly options: {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
};
readonly positionMethod: "fixed" | "absolute";
readonly topLayer?: boolean;
}

Models

Align

type unstable
Since v4.2.0

How a popup lines up with its anchor along the side it shows on.

Signature

type Align = typeof Align.Type

CollisionAvoidance

type unstable
Since v4.2.0

What a popup does when it doesn't fit inside the boundary.

Signature

type CollisionAvoidance = typeof CollisionAvoidance.Type

CollisionBoundary

type unstable
Since v4.2.0

The area a popup keeps inside.

Signature

type CollisionBoundary = typeof CollisionBoundary.Type

CollisionPadding

type unstable
Since v4.2.0

The pixels a popup keeps from the boundary's edges.

Signature

type CollisionPadding = typeof CollisionPadding.Type

InlineHit

type unstable
Since v4.2.0

Where the pointer rested on an inline anchor.

Signature

type InlineHit = typeof InlineHit.Type

PlaceInput

interface unstable
Since v4.2.0

What place measures a popup from. Every rectangle is in the same coordinates, which the result's x and y are in too.

Details

  • anchor: the element the popup is placed against.
  • popup: the popup's size.
  • arrow: the arrow's size, or null without one.
  • boundary: the area the popup keeps inside.
  • anchorClip: the part of the page the anchor can be seen through, which decides anchorHidden. The viewport, cut by each ancestor that clips the anchor.
  • rtl: whether the writing direction is right to left.

Signature

interface PlaceInput {
readonly anchor: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly anchorClip: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly arrow: Size | null;
readonly boundary: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly options: {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
};
readonly popup: Size;
readonly rtl: boolean;
}

Placement

type unstable
Since v4.2.0

What TrackPosition reports about a popup's position.

Signature

type Placement = typeof Placement.Type

PlaceOptions

type unstable
Since v4.2.0

The options place takes, with every default filled in.

Signature

type PlaceOptions = typeof PlaceOptions.Type

PlaceResult

interface unstable
Since v4.2.0

Where place puts a popup.

Details

  • x, y: the popup's top left corner.
  • side, align: where the popup ended up, which differs from the options after a flip. A logical side stays logical.
  • availableWidth, availableHeight: the space between the anchor and the boundary's edge on that side.
  • anchorHidden: the anchor is outside anchorClip. An anchor with no width or height is outside only past the clip's edge, not on it.
  • arrow: null without an arrow. Otherwise its offset from the popup's left edge as x or from its top edge as y, the other being null, and uncentered when it can't point at the anchor's middle.
  • transformOrigin: a CSS transform-origin at the point on the anchor the popup grows from.

Signature

interface PlaceResult {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrow: {
readonly uncentered: boolean;
readonly x: number | null;
readonly y: number | null;
} | null;
readonly availableHeight: number;
readonly availableWidth: number;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly transformOrigin: string;
readonly x: number;
readonly y: number;
}

PositionerOptions

type unstable
Since v4.2.0

The positioning options a popup takes as props: the type of PositionerFields.

Signature

type PositionerOptions = Schema.Struct.Type<typeof PositionerFields>

PositionMethod

type unstable
Since v4.2.0

The CSS position of the positioner.

Signature

type PositionMethod = typeof PositionMethod.Type

Rect

type unstable
Since v4.2.0

A rectangle in viewport coordinates, in pixels.

Signature

type Rect = typeof Rect.Type

Side

type unstable
Since v4.2.0

The side of the anchor a popup shows on.

Signature

type Side = typeof Side.Type

Size

interface unstable
Since v4.2.0

A width and a height, in pixels.

Signature

interface Size {
readonly height: number;
readonly width: number;
}

TrackPositionArgs

type unstable
Since v4.2.0

The args of TrackPosition.

Signature

type TrackPositionArgs = typeof TrackPositionArgs.Type

Mounts

Since v4.2.0

The body of TrackPosition: the Stream of a positioner's Placements, which places the positioner as it runs.

Details

An element takes one mount. To do more on the positioner than place it, pass Mount.makeStream a body that merges this Stream with its own. The arguments are the ones a body gets: the node, the args and the Stream of later args.

Signature

declare function trackPosition(node: HTMLElement, args: {
readonly anchorRect?: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | null;
readonly anchorSelector: string;
readonly arrowId: string | null;
readonly collisionBoundary: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly disableAnchorTracking: boolean;
readonly inline?: boolean;
readonly inlineHit?: {
readonly line: number | null;
readonly x: number;
readonly y: number;
} | null;
readonly leaveCoordinates?: boolean;
readonly offsetAsPadding: boolean;
readonly options: {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
};
readonly positionMethod: "fixed" | "absolute";
readonly topLayer?: boolean;
}, changes: Stream<{
readonly anchorRect?: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | null;
readonly anchorSelector: string;
readonly arrowId: string | null;
readonly collisionBoundary: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly disableAnchorTracking: boolean;
readonly inline?: boolean;
readonly inlineHit?: {
readonly line: number | null;
readonly x: number;
readonly y: number;
} | null;
readonly leaveCoordinates?: boolean;
readonly offsetAsPadding: boolean;
readonly options: {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
};
readonly positionMethod: "fixed" | "absolute";
readonly topLayer?: boolean;
}>): Stream<{
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
}>
Since v4.2.0

A stream mount that places a positioner against its anchor and keeps it there while it runs. Issue it on the positioner while the popup shows, and map each Placement it reports to a message.

Details

It reports once when it starts, then only when a field of the Placement changes, so following a scroll renders nothing. The position itself goes straight to the positioner's inline style. The module's JSDoc lists what it writes and when it measures again.

A Scene has no layout, so send a Placement there with mounted(Positioning.TrackPosition, placement).

A Placement is a measurement, so a Model that stores one clears it in restore: after Back the mount reports it again.

Signature

declare const TrackPosition: Factory<{
readonly anchorRect?: {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | null;
readonly anchorSelector: string;
readonly arrowId: string | null;
readonly collisionBoundary: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly disableAnchorTracking: boolean;
readonly inline?: boolean;
readonly inlineHit?: {
readonly line: number | null;
readonly x: number;
readonly y: number;
} | null;
readonly leaveCoordinates?: boolean;
readonly offsetAsPadding: boolean;
readonly options: {
readonly align: "start" | "end" | "center";
readonly alignOffset: number;
readonly arrowPadding: number;
readonly collisionAvoidance: {
readonly align: "shift" | "none" | "flip";
readonly fallbackAxisSide: "start" | "none" | "end";
readonly side: "shift" | "none" | "flip";
};
readonly collisionPadding: {
readonly bottom: number;
readonly left: number;
readonly right: number;
readonly top: number;
};
readonly shiftCrossAxis: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset: number;
readonly sticky: boolean;
};
readonly positionMethod: "fixed" | "absolute";
readonly topLayer?: boolean;
}, {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
}, HTMLElement, never>

Example A hint that stays next to its button

import { Mount, UiSchema, UiStruct } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Positioning } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const HintMessage = UiSchema.TaggedEnum({ ChangedPlacement: { placement: Positioning.Placement } })
const Hint = Html.component({
name: "Hint",
props: Schema.Struct({ open: Schema.Boolean, ...Positioning.PositionerFields }),
model: Schema.Struct({ placement: Schema.NullOr(Positioning.Placement) }),
message: HintMessage,
restore: (model) => UiStruct.evolve(model, { placement: null })
}).make({
init: () => ({ placement: null }),
update: {
ChangedPlacement: ($, { placement }) => $.evolve({ placement })
},
view: (h, model) => {
const anchorId = h.id("anchor")
const args = Positioning.trackArgs(h.props, { side: "bottom", anchorSelector: `[id="${anchorId}"]` })
const positioner = h.div
.popover("manual", h.props.open)
.attrs({
style: Positioning.positionerStyle(args.positionMethod),
"data-side": model.placement?.side ?? args.options.side
})
.children("Saved")
return h.span(
h.button.id(anchorId).children("Save"),
h.props.open
? positioner.onMount(
Positioning.TrackPosition(args).pipe(Mount.map((placement) => HintMessage.ChangedPlacement({ placement })))
)
: positioner
)
}
})
// Before the mount measures, the positioner has its resets and the requested side.
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Hint, { open: true, sideOffset: 8 }))
if (!html.includes("position:absolute;inset:auto;margin:0")) throw new Error("the positioner has no resets")
if (!html.includes("data-side=\"bottom\"")) throw new Error("the positioner doesn't name its side")

Placing

place

unstable
Since v4.2.0

Places a popup against an anchor: on the requested side, lined up as asked, then flipped and shifted as collisionAvoidance allows to stay inside the boundary.

Details

It reads no DOM and has no state, so the same input gives the same result.

Signature

declare function place(input: PlaceInput): PlaceResult

Schemas

Align

unstable
Since v4.2.0

How a popup lines up with its anchor along the side it shows on.

Signature

declare const Align: Literals<readonly ["start", "center", "end"]>
Since v4.2.0

What a popup does when it doesn't fit inside the boundary.

Details

  • side: for a popup that reaches past the boundary away from the anchor. "flip" moves it to the opposite side, "shift" keeps the side and slides the popup over the anchor, and "none" leaves it. "flip" by default.
  • align: for a popup that reaches past the boundary along the anchor's edge. "flip" tries the other alignment and then slides the popup along the edge, "shift" only slides it, and "none" leaves it. "flip" by default.
  • fallbackAxisSide: the side on the other axis to try when neither side fits, or "none" to stay on the requested axis. "end" by default.

Signature

declare const CollisionAvoidance: Struct<{
readonly align: optional<Literals<readonly ["flip", "shift", "none"]>>;
readonly fallbackAxisSide: optional<Literals<readonly ["start", "end", "none"]>>;
readonly side: optional<Literals<readonly ["flip", "shift", "none"]>>;
}>
Since v4.2.0

The area a popup keeps inside: "clipping-ancestors", which is the viewport, an element in the popup's tree named by { id }, or a rectangle in viewport coordinates. An element or a rectangle is cut to the viewport.

Signature

declare const CollisionBoundary: Union<readonly [Literal<"clipping-ancestors">, Struct<{
readonly id: String;
}>, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>
Since v4.2.0

The pixels a popup keeps from the boundary's edges: one number for every edge, or one per edge, where an edge left out is 0.

Signature

declare const CollisionPadding: Union<readonly [Number, Struct<{
readonly bottom: optional<Number>;
readonly left: optional<Number>;
readonly right: optional<Number>;
readonly top: optional<Number>;
}>]>

InlineHit

unstable
Since v4.2.0

Where the pointer rested on an inline anchor: the point, in viewport coordinates, and line, the index of the line under it among the anchor's lines from the top, or null when it was on none.

Signature

declare const InlineHit: Struct<{
readonly line: NullOr<Number>;
readonly x: Number;
readonly y: Number;
}>

Placement

unstable
Since v4.2.0

What TrackPosition reports: the facts about a popup's position that its parts render as attributes. A component keeps the latest in its Model.

Details

  • side, align: where the popup is, for data-side and data-align.
  • anchorHidden: the anchor is scrolled or clipped out of view, for data-anchor-hidden.
  • arrowUncentered: the arrow can't point at the anchor's middle, for data-uncentered.

Signature

declare const Placement: Struct<{
readonly align: Literals<readonly ["start", "center", "end"]>;
readonly anchorHidden: Boolean;
readonly arrowUncentered: Boolean;
readonly side: Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>;
}>
Since v4.2.0

The options place takes, with every default filled in. resolveOptions makes one from a component's props.

Signature

declare const PlaceOptions: Struct<{
readonly align: Literals<readonly ["start", "center", "end"]>;
readonly alignOffset: Number;
readonly arrowPadding: Number;
readonly collisionAvoidance: Struct<{
readonly align: Literals<readonly ["flip", "shift", "none"]>;
readonly fallbackAxisSide: Literals<readonly ["start", "end", "none"]>;
readonly side: Literals<readonly ["flip", "shift", "none"]>;
}>;
readonly collisionPadding: Struct<{
readonly bottom: Number;
readonly left: Number;
readonly right: Number;
readonly top: Number;
}>;
readonly shiftCrossAxis: Boolean;
readonly side: Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>;
readonly sideOffset: Number;
readonly sticky: Boolean;
}>
Since v4.2.0

The positioning options a popup takes as props, to spread into its props Schema: Schema.Struct({ open: Schema.Boolean, ...PositionerFields }). Every one is optional.

Details

  • side: the side of the anchor the popup shows on. The component picks the default.
  • align: how the popup lines up with the anchor along that side, "center" by default.
  • sideOffset: the gap between the anchor and the popup, in pixels.
  • alignOffset: pixels the popup moves along the side, toward the anchor's other end when aligned to the start or the end, and right or down when centred.
  • collisionAvoidance: what happens when the popup doesn't fit. It replaces the component's default as a whole.
  • collisionBoundary: the area the popup keeps inside, the viewport by default.
  • collisionPadding: pixels kept from the boundary's edges, 5 by default.
  • sticky: the popup stays in view when the anchor scrolls out of it.
  • arrowPadding: pixels kept between the arrow and the popup's corners, 5 by default.
  • positionMethod: "absolute" by default.
  • disableAnchorTracking: the popup is placed only when it opens, when the window resizes and when its own size changes, not when the page scrolls or the anchor moves or changes size.
  • anchor: the id of an element in the popup's tree, or a Rect in the viewport, to place the popup against instead of the component's own anchor.
  • topLayer: false draws the positioner in place, as the module's Gotchas describe. true when left out. The component's JSDoc says what else changes.

Signature

declare const PositionerFields: {
align: optional<Literals<readonly ["start", "center", "end"]>>;
alignOffset: optional<Number>;
anchor: optional<Union<readonly [String, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>>;
arrowPadding: optional<Number>;
collisionAvoidance: optional<Struct<{
readonly align: optional<Literals<readonly ["flip", "shift", "none"]>>;
readonly fallbackAxisSide: optional<Literals<readonly ["start", "end", "none"]>>;
readonly side: optional<Literals<readonly ["flip", "shift", "none"]>>;
}>>;
collisionBoundary: optional<Union<readonly [Literal<"clipping-ancestors">, Struct<{
readonly id: String;
}>, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>>;
collisionPadding: optional<Union<readonly [Number, Struct<{
readonly bottom: optional<Number>;
readonly left: optional<Number>;
readonly right: optional<Number>;
readonly top: optional<Number>;
}>]>>;
disableAnchorTracking: optional<Boolean>;
positionMethod: optional<Literals<readonly ["absolute", "fixed"]>>;
side: optional<Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>>;
sideOffset: optional<Number>;
sticky: optional<Boolean>;
topLayer: optional<Boolean>;
}
Since v4.2.0

The CSS position of the positioner. "fixed" doesn't make the page taller when the popup reaches past its end.

Signature

declare const PositionMethod: Literals<readonly ["absolute", "fixed"]>

Rect

unstable
Since v4.2.0

A rectangle in viewport coordinates, in pixels.

Signature

declare const Rect: Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>

Side

unstable
Since v4.2.0

The side of the anchor a popup shows on. "inline-start" and "inline-end" follow the writing direction.

Signature

declare const Side: Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>
Since v4.2.0

The args of TrackPosition. trackArgs makes them from a component's props.

Details

  • options: what place takes.
  • positionMethod: the positioner's CSS position, which decides whether the page's scroll is added to left and top.
  • collisionBoundary: the area the popup keeps inside.
  • disableAnchorTracking: don't follow scrolling or the anchor.
  • anchorSelector: a CSS selector for the anchor.
  • anchorRect: a rectangle in the viewport to place against instead of the element anchorSelector matches, or null.
  • arrowId: the id of the arrow, or null without one.
  • offsetAsPadding: write sideOffset as padding on the positioner's side facing the anchor, and move the positioner up against the anchor. The gap is then part of the positioner, so a pointer can cross it without leaving the popup.
  • leaveCoordinates: don't write left and top, and leave whatever is there. False when left out.
  • inline: the anchor is inline text, such as a link, that can wrap over several lines. The popup is placed against one line instead of the box around all of them: the line inlineHit names, or else the line under its point. Without a hit for the anchor, or when no line is under the point, it is placed against the first line for "top", the last line for "bottom", and the lines that reach furthest toward the side for "left" and "right". An anchor on one line is measured as a whole. False when left out.
  • inlineHit: where the pointer rested on the anchor, for inline.
  • topLayer: false for a positioner drawn in place, as the module's Gotchas describe. true when left out.

Signature

declare const TrackPositionArgs: Struct<{
readonly anchorRect: optional<NullOr<Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>>>;
readonly anchorSelector: String;
readonly arrowId: NullOr<String>;
readonly collisionBoundary: Union<readonly [Literal<"clipping-ancestors">, Struct<{
readonly id: String;
}>, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>;
readonly disableAnchorTracking: Boolean;
readonly inline: optional<Boolean>;
readonly inlineHit: optional<NullOr<Struct<{
readonly line: NullOr<Number>;
readonly x: Number;
readonly y: Number;
}>>>;
readonly leaveCoordinates: optional<Boolean>;
readonly offsetAsPadding: Boolean;
readonly options: Struct<{
readonly align: Literals<readonly ["start", "center", "end"]>;
readonly alignOffset: Number;
readonly arrowPadding: Number;
readonly collisionAvoidance: Struct<{
readonly align: Literals<readonly ["flip", "shift", "none"]>;
readonly fallbackAxisSide: Literals<readonly ["start", "end", "none"]>;
readonly side: Literals<readonly ["flip", "shift", "none"]>;
}>;
readonly collisionPadding: Struct<{
readonly bottom: Number;
readonly left: Number;
readonly right: Number;
readonly top: Number;
}>;
readonly shiftCrossAxis: Boolean;
readonly side: Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>;
readonly sideOffset: Number;
readonly sticky: Boolean;
}>;
readonly positionMethod: Literals<readonly ["absolute", "fixed"]>;
readonly topLayer: optional<Boolean>;
}>

Styles

arrowStyle

unstable
Since v4.2.0

The inline style that puts an arrow where TrackPosition measured it: position: absolute and a left or a top, by the side the popup is on. The arrow has to be inside the positioner, and its offset across the popup's edge is left to the consumer's CSS.

Signature

declare function arrowStyle(side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end"): string
Since v4.2.0

The inline style a positioner needs before TrackPosition places it: its position, resets of the inset and margin a browser gives a popover, and --available-width and --available-height at the viewport's size until the mount measures them.

Details

A headless component puts it after the inline style its consumer gave the positioner, so these declarations win.

Signature

declare function positionerStyle(positionMethod: "fixed" | "absolute"): string