Skip to main content
On this pageFunctions

Ui/Popover

Functions

arrowId

functionsource
/**
 * Returns the bare DOM id of the popover arrow, derived from the popover's
 *  base id. The `arrow` bundle already carries this id, so reach for this when
 *  you need the id on its own, such as asserting the panel Mount's `arrowId`
 *  argument in a Scene test.
 */
(id: string): string

buttonId

functionsource
/**
 * Returns the bare DOM id of the popover trigger button, derived from the
 *  popover's base id. Use this to associate an external label with the
 *  trigger via a native `<label for={Popover.buttonId(id)}>` or an
 *  `aria-labelledby` reference.
 */
(id: string): string

Types

InitConfig

typesource
/**
 * Configuration for creating a Popover Model with `init`.
 * 
 *  `isAnimated` enables animation coordination. `isModal` locks page scroll
 *  and marks other elements inert while the Popover is open. Both default to
 *  `false`.
 * 
 *  With `contentFocus: true`, the panel has no tab stop and focus leaving
 *  it does not close the Popover. Focus a descendant when opening and
 *  handle focus leaving the content in the application. Defaults to `false`.
 */
type InitConfig = Readonly<{
  contentFocus: boolean
  id: string
  isAnimated: boolean
  isModal: boolean
}>

RenderInfo

typesource
/**
 * Render-time payload published to the consumer's `toView`.
 * 
 *  - `button`: attribute bundle for the trigger button.
 *  - `panel`: attribute bundle for the floating panel. Includes the
 *    anchor Mount that positions the panel via Floating UI, ARIA
 *    linkage to the button, and panel keydown and focus-leave handlers.
 *  - `backdrop`: attribute bundle for the modal backdrop. Includes the
 *    portal Mount that moves the backdrop to its containing root. Inside a
 *    `<dialog>`, it moves the backdrop to directly before the element it
 *    is rendered in, so render it inside the positioned wrapper that holds
 *    the button. The backdrop's OnClick closes the Popover.
 *  - `arrow`: attribute bundle for an arrow element inside the panel.
 *    Carries the id the anchor Mount resolves and hides the element from
 *    assistive technology. Spread it onto your own element and place it
 *    with the `--arrow-x` and `--arrow-y` custom properties Anchor
 *    publishes on the panel. Nothing renders until you do.
 *  - `isVisible`: derived from `isOpen` and the Animation
 *    `transitionState`. The consumer renders the panel + backdrop only
 *    while this is true.
 */
type RenderInfo = Readonly<{
  arrow: ReadonlyArray<ChildAttribute>
  backdrop: ReadonlyArray<ChildAttribute<Mount.RequirementsOf<typeof PortalPopoverBackdrop>>>
  button: ReadonlyArray<ChildAttribute>
  isVisible: boolean
  panel: ReadonlyArray<ChildAttribute<Mount.RequirementsOf<typeof AnchorPopover>>>
}>

ViewInputs

typesource
/** Per-render view inputs passed to `view` via `h.block`'s `viewInputs` field. */
type ViewInputs = Readonly<{
  anchor: AnchorConfig
  ariaLabel: string
  ariaLabelledBy: string
  arrowPadding: number
  focusSelector: string
  isDisabled: boolean
  toView: (render: RenderInfo) => Html
}>