Skip to content

useLayer

@astryxdesign/core v0.7.1 · useLayer

Parameters ​

NameTypeDefaultDescription
mode'context' | 'fixed'requiredPositioning strategy: context follows an anchor element, fixed uses explicit x / y coordinates.
anchorRef<HTMLElement | null>—External anchor element for context mode. Leave it out and bind the returned anchorRef to the trigger instead.
placement'above' | 'below' | 'start' | 'end' | MaybeRefOrGetter'below'Side of the anchor the layer is placed on. Logical: start / end mirror under RTL. Flips when there is no room.
alignment'start' | 'center' | 'end' | MaybeRefOrGetter'center'Alignment along the placement axis.
gapnumber4Clearance between the anchor and the layer, in pixels.
xnumber | MaybeRefOrGetter0Horizontal viewport coordinate for fixed mode.
ynumber | MaybeRefOrGetter0Vertical viewport coordinate for fixed mode.
isDefaultOpenbooleanfalseWhether the layer is open on the first render.
lightDismissboolean | MaybeRefOrGetterfalseWhether clicking outside dismisses the layer.
lazyMountboolean | MaybeRefOrGetterfalseWhether to wait for the first show() before rendering the content. isMounted reports the answer.
onShow() => void—Called when show() opens the layer. Opening through isDefaultOpen is not a show, so it does not fire.
onHide() => void—Called when hide() closes the layer.

Returns ​

FieldTypeDescription
isOpenShallowRef<boolean>Whether the layer is currently open.
anchorRefRef<HTMLElement | null>Anchor element for context mode. Bind it with :ref; unset in fixed mode.
contentRefRef<HTMLElement | null>Layer container. Measured for positioning and used for outside clicks.
contentStyleComputedRef<CSSProperties>Inline coordinates: measured top / left in context mode, position: fixed plus x / y in fixed mode.
resolvedPlacementComputedRef<'above' | 'below' | 'start' | 'end'>Placement actually in effect after flipping for available space. Equal to the requested placement in fixed mode.
isMountedComputedRef<boolean>Whether the content should render. Stays false until the first show() while lazyMount is on.
idstringUnique ID for aria-controls or aria-describedby.
anchorIdstringCSS identifier for the anchor element, for advanced positioning cases.
show() => voidImperatively show the layer.
hide() => voidImperatively hide the layer.