Popover
A floating panel anchored to the button that opens it.
The popover flips or shifts when there isn’t room on its side. Set side, align and
sideOffset on PopoverContent to place it.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Scroll AreaprimitiveTextprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Popover
Rich content in a floating panel, opened from a button. Put its trigger and content inside.
- closeDelay
Milliseconds before the popover closes once the pointer leaves it and its trigger, with
openOnHover.Type number · Default 0
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- controller
Opens, closes and inspects the popover from anywhere, and connects triggers outside it. Create one with
createPopoverController().Type PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultOpen
Whether the popover starts open, when uncontrolled.
Type boolean · Default false
- delay
Milliseconds the pointer rests on the trigger before the popover opens, with
openOnHover.Type number · Default 300
- dismissible
Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass
falsewhile it holds unsaved work, and ask inonDismissAttempt.Type boolean · Default true
- modal
false: the rest of the page stays usable, and focus leaving the popover closes it.true: also traps focus, locks scroll and makes the rest of the page inert, and an outside press only closes the popover."trap-focus": traps focus but leaves the page scrollable and clickable.Type boolean | "trap-focus" · Default false, or true while it presents as a sheet
- onDismissAttempt
Runs when
dismissiblerefused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.Type (details: { reason: "outside-press"; event?: MouseEvent; } | { reason: "escape-key"; event?: KeyboardEvent; } | { reason: "back"; event?: Event; } | { reason: "swipe"; event?: PointerEvent | TouchEvent; }) => void
- onOpenChange
Runs when the popover wants to open or close.
details.reasonsays why, anddetails.cancel()stops it.Type (open: boolean, details: ChangeDetails<PopoverOpenChangeReason>) => void
- onOpenChangeComplete
Runs once the popover has finished opening or closing, after any animation.
Type (open: boolean) => void
- onPayloadChange
Runs when the payload the content shows changes: a trigger with another payload opens the popover, or takes the open popover over, which fires no
onOpenChange, and so does a controller'sopen({ payload })on the open popover.details.cancel()keeps the previous payload.Type (payload: unknown, details: ChangeDetails<PopoverPayloadChangeReason>) => void
- open
Whether the popover is open. Pass it to control the popover.
Type boolean
- openOnHover
Whether resting the pointer on the trigger opens the popover. Pressing the trigger still opens it, so keyboard and touch users can too.
Type boolean · Default false
- presentation
How the popover presents.
"sheet"slides it up from the bottom of the screen, where it can be swiped away, and"auto"does that on small touch screens. Decided each time it opens; the server renders"popover"for"auto".Type PresentationSetting<"popover"> · Default "popover"
PopoverContent
The floating panel. Placed below its trigger with an 8px gap unless you set side and sideOffset.
- align
How the popup lines up with the anchor along that side.
startandendfollow the reading direction. How the popover lines up with the trigger along that side.Type "center" | "start" | "end" · Default "center"
- alignOffset
Shift along the anchor, in pixels. Shift along the trigger, in pixels.
Type number · Default 0
- anchor
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like
{ x, y }, or anything withgetBoundingClientRect(). It's read on every check, so it can move. A controller'sopen({ anchor })wins for that open.Type string | Anchor | null
- arrowPadding
Space to keep between the arrow and the popup's corners, in pixels.
Type number · Default 6
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: PopoverContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: PopoverContentState<unknown>) => string)
- collisionPadding
Space to keep from the viewport edges, in pixels.
Type number · Default 8
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- finalFocus
Where focus goes when the popover closes while focus is inside it.
Type PopupFocusTarget · Default "trigger"
- initialFocus
Where focus goes when the popover opens. Opening on hover never moves focus, and opening with touch focuses the popover itself so no on-screen keyboard appears, unless this is set to something other than
"auto".Type PopoverInitialFocus · Default "auto"
- inline
Renders the popover where it is in the page instead of above it, inside its parent's layout and stacking, and leaves placing it to your CSS:
side,alignand the offsets don't apply.Type boolean · Default false
- keepMounted
Whether the popover stays in the page, hidden, while closed. Its content keeps its state between opens.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<PopoverContentState<unknown>>
- side
Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the popover opens on.
Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "bottom"
- sideOffset
Gap between the anchor and the popup, in pixels. Gap between the trigger and the popover, in pixels.
Type number · Default 8
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: PopoverContentState<unknown>) => CSSProperties)
PopoverDescription
Describes the popover.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
PopoverTitle
Names the popover.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
PopoverTrigger
The button that opens the popover. A trigger outside the popover connects through controller.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: PopoverTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: PopoverTriggerState) => string)
- controller
Connects a trigger outside the popover, like one per table row, to the popover with this controller.
Type PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>
- disabled
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless
focusableWhenDisabledis set.Type boolean · Default false
- focusableWhenDisabled
Keeps a disabled trigger in the tab order with
aria-disabledinstead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.Type boolean · Default false
- payload
Data for the content to render when this trigger opens the popover, like the row it belongs to.
Type unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<PopoverTriggerState>
- shortcut
A keyboard shortcut that presses the trigger, like
"mod+i".modis Command on Apple platforms and Control elsewhere. Setsaria-keyshortcuts.Type string
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: PopoverTriggerState) => CSSProperties)