Skip to content

usePopover

@astryxdesign/core v0.7.1 · usePopover

Parameters ​

NameTypeDefaultDescription
placement'above' | 'below' | 'start' | 'end' | MaybeRefOrGetter'below'Side of the trigger the popover is placed on. Logical: start / end mirror under RTL. Flips when there is no room.
alignment'start' | 'center' | 'end' | MaybeRefOrGetter'start'Alignment along the placement axis.
isOpenboolean | undefined | MaybeRefOrGetter—Controlled open state. Leave it out to let the hook own the state.
isEnabledboolean | MaybeRefOrGettertrueWhether the trigger opens the popover.
hasLightDismissboolean | MaybeRefOrGettertrueWhether clicking outside dismisses the popover.
hasEscapeDismissboolean | MaybeRefOrGettertrueWhether pressing Escape dismisses the popover.
hasAutoFocusboolean | MaybeRefOrGettertrueWhether to focus the first genuine content control when opened. A dialog with none falls back to the content container.
closeButtonSelectorstring—Selector of the control that initial focus must skip, such as the component's own close button.
dialogLabelstring | MaybeRefOrGetter—Accessible label for the popover dialog. Provide one when there is no visible title.
role'dialog' | 'none' | MaybeRefOrGetter'dialog'ARIA role on the content container. Use none for listbox/menu popups whose own content role should be exposed and whose trigger keeps DOM focus.
isModalboolean | MaybeRefOrGettertrueWhether a dialog-role popover is modal (aria-modal).
onShow() => void—Called when the popover becomes visible.
onHide() => void—Called when the popover is hidden. Use this to return focus to the trigger when needed.

Returns ​

FieldTypeDescription
isOpenRef<boolean>Whether the popover is currently open.
triggerRefRef<HTMLElement | null>Element that opens the popover. Bind it with :ref; the hook attaches the handlers and ARIA attributes.
anchorRefRef<HTMLElement | null>Positioning anchor. Falls back to triggerRef when unset.
contentRefRef<HTMLElement | null>Content container used by focus trapping and dismissal.
idstringUnique ID for aria-controls.
anchorIdstringCSS identifier for the anchor element, for advanced positioning cases.
contentStyleComputedRef<CSSProperties>Inline coordinates for the surface. Spread it on the content element's style.
resolvedPlacementComputedRef<'above' | 'below' | 'start' | 'end'>Placement actually in effect, after flipping for available space.
surfacePropsComputedRef<Record<string, unknown>>Attributes for the content element: id, role, aria-modal, aria-label, tabindex.
triggerPropsComputedRef<Record<string, unknown>>The ARIA attributes the hook writes onto triggerRef: aria-haspopup, aria-expanded, aria-controls.
show() => voidImperatively show the popover.
hide() => voidImperatively hide the popover.
toggle() => voidToggle the popover open or closed.