Fragiola

API: components

Popover

Non-modal floating content anchored to a trigger, following the APG's non-modal dialog disclosed by a button, in each framework.

A panel the user opens, uses and leaves, next to its trigger. The page stays usable while it is open: focus is not trapped and nothing is inert. It is a non-modal dialog disclosed by a button (WAI-ARIA APG dialog pattern, without the modal parts). A menu of actions is a Menu; a description shown on hover is a Tooltip.

Notifications
Gallery

Behaviour

  • Open: a press on the Trigger toggles it. Focus moves to initialFocus, else the first tabbable element of the popup, else the popup itself (the APG dialog pattern).
  • Inside: in the tab order, the popup comes right after its trigger, even though it is portalled. Tab from its last element moves on to the element after the trigger and closes it; Shift+Tab from its first goes back to the trigger and closes it (reason focus-out).
  • Close: Escape (escape-key) or a Close part (close-press) or the Trigger again (trigger-press) return focus to finalFocus, else the trigger. A press outside (outside-press) returns it to the trigger unless the press landed on a focusable element, which keeps the focus it got (Base UI's rule).
  • Layers: the popover is a layer of the nested overlay tree. Opened inside a dialog, it is the dialog's child: it closes first on Escape and on a press inside the dialog, and a menu opened from it is its own child. Closing it closes them.
  • Detached triggers: Triggers anywhere in the page open the same Root through a handle, each with a payload (detached triggers). The popup anchors to the active trigger and focus returns to it; a press on another trigger while open moves the popover there, with that trigger's payload.
  • Positioning: side of the anchor, flipped to the other side when there is no room, shifted along it to stay in the viewport, following scroll and resize. inline-start and inline-end follow the direction; left and right do not. data-side says where it ended up.
  • Lifecycle: onOpenChange is called before the change (details.cancel() keeps it as it is, change details), onOpenChangeComplete(open) reports the end of each transition, the actions close() and unmount() act from code, and the Portal's keepMounted keeps the Positioner in the page while closed (hidden, data-closed).

Anatomy

partelementdata-primitives-partrole
Rootnoneholds the state
Triggerbuttonpopover-triggertoggles the popover, and anchors it
Portalnonemoves the Positioner to the end of body
Positionerdivpopover-positionerplaces the popup next to the anchor
Popupdivpopover-popupthe popover
Arrowdivpopover-arrowpoints at the anchor (optional)
Titleh2popover-titlenames the popover
Descriptionppopover-descriptiondescribes it
Closebuttonpopover-closecloses it

Usage

import { Popover } from "@fragiola/primitives-react/popover";

<Popover.Root onOpenChange={(open, { reason }) => console.log(open, reason)}>
    <Popover.Trigger>Notifications</Popover.Trigger>
    <Popover.Portal>
        <Popover.Positioner side="bottom" sideOffset={8}>
            <Popover.Popup>
                <Popover.Arrow />
                <Popover.Title>Notifications</Popover.Title>
                <Popover.Description>You have 2 unread messages.</Popover.Description>
                <Popover.Close>Mark all as read</Popover.Close>
            </Popover.Popup>
        </Popover.Positioner>
    </Popover.Portal>
</Popover.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (v-model:open, @open-change, :side-offset), and Angular as inputs and outputs ([(open)], (openChangeDetails), [sideOffset]).

Root

proptypedefaultdescription
openbooleanthe open state, controlled
defaultOpenbooleanfalsethe initial open state, uncontrolled
onOpenChange(open: boolean, details: OpenChangeDetails) => voidevery change, with its reason (trigger-press, close-press, escape-key, outside-press, focus-out); called before the change, details.cancel() stops it
onOpenChangeComplete(open: boolean) => voidonce an opening or a closing has finished its transitions (not on the first render, nor for an exit a reopening interrupted)
actionsRef (react){ current: OverlayActions | null }receives close() (reason imperative-action) and unmount() (ends an exit now); Vue exposes them on the Root's template ref, Angular as the root directive's methods
handlePopoverHandle<Payload>connects Triggers rendered outside the Root (detached triggers)
triggerIdstring | nullthe active trigger's id, controlled together with open
defaultTriggerIdstring | nullnullthe initial active trigger, uncontrolled

Trigger

proptypedefaultdescription
disabledbooleanfalsea disabled trigger opens nothing
handlePopoverHandle<Payload>the handle of a Root this Trigger opens from anywhere, outside it
payloadPayloadwhat the Root's content receives while this Trigger is the active one
idstringgeneratedthe Trigger's id: triggerId and the handle's open(id) name it

Portal

proptypedefaultdescription
container (react, vue)Elementdocument.bodywhere the Positioner goes
keepMounted (react, vue)booleanfalsekeep the content rendered while closed (before the first opening and after an exit), hidden and data-closed; reopening shows the same elements
options (angular)Element | { container?, keepMounted? }{}the same two options: *popoverPortal="{ keepMounted: true }", or *popoverPortal="element" for a container alone

Positioner

proptypedefaultdescription
side"top" | "bottom" | "inline-start" | "inline-end" | "left" | "right""bottom"the side of the anchor; inline-* follow the direction
align"start" | "center" | "end""center"the alignment along that side
sideOffsetnumber0the distance from the anchor, in px
alignOffsetnumber0the shift along the anchor's edge, in px
collisionPaddingnumber8the space kept from the viewport's edges, in px
anchorElementthe triggerthe element to place the popup next to
proptypedefaultdescription
initialFocusan element, a ref, or falsethe first tabbable element, else the popupfocused on open (false: nothing moves); Vue and Angular also take a getter
finalFocusan element, a ref, or falsethe triggerfocused when focus returns on close (false: nothing moves)

Arrow

No props of its own.

Title

proptypedefaultdescription
id (angular)stringgeneratedthe id the popup's aria-labelledby points at; React and Vue take it as a plain attribute

Description

proptypedefaultdescription
id (angular)stringgeneratedthe id the popup's aria-describedby points at; React and Vue take it as a plain attribute

Close

No props of its own.

State and part attributes

partattributes
Triggeraria-haspopup="dialog", aria-expanded, aria-controls (the popup while open), data-popup-open, data-disabled
Positionerrole="presentation", data-side, data-align, data-open / data-closed; the CSS variables --anchor-width, --anchor-height, --available-width, --available-height, --transform-origin; hidden while kept mounted and closed
Popuprole="dialog" (no aria-modal), aria-labelledby, aria-describedby, tabindex="-1", data-side, data-align, data-open / data-closed, data-starting-style, data-ending-style
Arrowaria-hidden="true", data-side, data-align
Title, Descriptionan id (generated unless given)

Keyboard

keyaction
Enter, Space on the Triggertoggles
Tabthrough the popup's content; from its last element, to the element after the trigger, closing it
Shift+Tabfrom the popup's first element, back to the trigger, closing it
Escapecloses, focus on the trigger (only the topmost layer, when one is open inside)

Exports

entryexports
@fragiola/primitives-react/popoverPopover, PopoverRootProps, PopoverTriggerProps, PopoverTriggerState, PopoverPortalProps, PopoverPositionerProps, PopoverPositionerState, PopoverPopupProps, PopoverPopupState, PositionerProps, Side, Align, FocusTarget, ChangeDetails, ChangeReason, RenderProp, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalProps, OverlayRootProps, OverlayTriggerProps, OverlayTriggerRootProps, PopoverHandle, createPopoverHandle
@fragiola/primitives-vue/popoverPopover, PopoverRootProps, PopoverRootEmits, PopoverTriggerProps, PopoverTriggerState, PopoverPortalProps, PopoverPositionerState, PopoverPopupProps, PopoverPopupState, PopoverArrowState, PositionerProps, Side, Align, FocusTarget, ChangeDetails, ChangeReason, RenderSlotProps, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalProps, OverlayRootEmits, OverlayRootProps, OverlayRootSlots, OverlayTriggerProps, OverlayTriggerRootProps, PopoverHandle, createPopoverHandle
@fragiola/primitives-angular/popoverPopoverRoot, PopoverTrigger, PopoverPortal, PopoverPositioner, PopoverPopup, PopoverArrow, PopoverTitle, PopoverDescription, PopoverClose, injectPopover, PopoverState, PopoverTriggerState, PopoverPositionerState, PopoverPopupState, Side, Align, FocusTarget, ChangeDetails, ChangeReason, OpenChangeEvent, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalOptions, PopoverHandle, createPopoverHandle