vael-ui v0.5.7

Positioning & data

useFloatingPosition

The positioning engine behind Popover, Menu and Tooltip. Use it to build your own anchored panels.

The positioning engine behind Popover, Menu and Tooltip. It computes positionerStyle (absolute top and left, plus visibility) for a reference and a floating element. It flips and shifts to stay on screen, and tracks changes with autoUpdate while active is true. Use it to build an anchored surface that no overlay component fits.

Install

import { useFloatingPosition } from 'vael-ui'

Examples

Parameters

NameTypeDescription
referenceElRef<HTMLElement | null>The anchor element.
floatingElRef<HTMLElement | null>The positioned surface.
activeMaybeRefOrGetter<boolean>Turns positioning on. Scroll and resize tracking run only while it is true.
sideMaybeRefOrGetter<Side>The side of the reference to place it on. It flips when there's no room. Default 'bottom'.
alignMaybeRefOrGetter<'start' | 'center' | 'end'>How it lines up along that side. Default 'center'.
sideOffsetMaybeRefOrGetter<number>The gap from the reference in px, along side. Default 8.
alignOffsetMaybeRefOrGetter<number>The shift along the alignment axis, in px. Default 0.
matchReferenceWidthMaybeRefOrGetter<boolean>Writes the reference's width to --ui-anchor-inline-size in positionerStyle. Your positioner CSS can read that variable.

Returns

NameTypeDescription
positionerStyleRef<Record<string, string>>The position to bind on the floating element: :style="positionerStyle".
placementRef<Placement>The resolved placement, after flipping.
transformOriginRef<string>Points at the reference's center, on the panel's facing edge, so a scale animation grows out of the reference.
maxHeightRef<number | null>The height left for the surface in px, or null while inactive.
update() => Promise<void>Measures again, for a change autoUpdate doesn't catch.