Skip to content
Slotted

Popover

A non-modal panel anchored to the control that opened it, for details, a short form or a set of filters that the reader opens, uses and leaves without leaving the page.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Popover, PopoverAnchor, PopoverArrow, PopoverBody,  PopoverClose, PopoverContent, PopoverDefaultsProvider,  PopoverDescription, PopoverFooter, PopoverHeader, PopoverLayer,  PopoverTitle, PopoverTrigger } from '@slotted/react';

Popover or tooltip

A popover opens on a press and holds content the reader can act on: controls, links, a form. A tooltip opens on hover or focus and holds one line of text that names or describes its trigger; use a tooltip when the content has no control in it.

Placement

side names the edge of the trigger the panel opens against: top, bottom (the default), left, right, or the logical inline-start and inline-end, which swap in a right-to-left layout. When the panel does not fit on that side, it moves to the opposite side; flip={false} keeps it where it was asked to be.

Alignment

align places the panel along the side it took: start lines its start edge up with the trigger’s start edge, center (the default) centers it, and end lines up the end edges. When the panel would cross the edge of the screen, it slides along the side until it fits; shift={false} turns the slide off.

Arrow and offset

The arrow points at the middle of the trigger, and stays clear of the panel’s rounded corners. arrow={false} in React and [arrow]="false" in Angular draw the panel without it. The panel always keeps a standard gap from the trigger; sideOffset adds pixels beyond that gap, and alignOffset moves the panel along the alignment axis.

Sizes

size caps the layer’s width at one of three steps: sm (16rem), md (20rem, the default) and lg (24rem), with the inset and the title size to match. The layer holds the gap around the panel, so at the default 16-pixel root size the panel itself is at most 240, 304 or 368 pixels wide. A panel with less content than the cap is as wide as its content.

Matching the trigger’s width

width="anchor" makes the panel exactly as wide as its trigger, for a panel that opens under a full-width control. With align="start", its edges line up with the trigger’s.

Controlled

Pass open and update it from onOpenChange in React, or bind [(open)] to a signal in Angular, when something other than the trigger opens or closes the panel. Here choosing a picker writes the value and closes the panel in one step, and focus returns to the trigger.

Order 10251, picked by Nancy Davolio

Dismissal

A popover closes on a press of its trigger, on Escape, on a press outside the panel, and on the close button. Each request carries a reason, read from the second argument of onOpenChange in React and from (openChangeRequest) in Angular: pointer or keyboard for the trigger, escape, outsidePress, and dismiss for the close button. closeOnEscape={false} and closeOnOutsidePress={false} turn either way off; keep a close button when you do.

Last closed by: not closed yet

Focus

On open, focus moves to the panel itself, so a screen reader announces the panel’s name before its contents. initialFocus takes an element or a selector read inside the panel, and moves focus there instead, for a panel that opens onto its own search field. On close, focus returns to the trigger, unless the reader has already moved it somewhere else on the page. Tab moves through the panel’s controls; Tab past the last one closes the panel and returns focus to the trigger, and the next Tab continues down the page. Focus is never trapped: the popover is not modal, the page behind it stays scrollable and interactive, and a task that has to block the page belongs in a dialog.

A form in a popover

A popover can hold a short form: the fields belong to the page, and the popover holds none of their values. Here a press outside the panel is refused while the count or the reason differs from what the panel opened with: request.cancel() keeps it open, while Escape and Cancel still close it and discard the change. Change the count, then press outside the panel.

Chai: 39 units on hand

In a toolbar

Popover triggers in a toolbar are toolbar controls: the arrow keys move between them, and a popover returns focus to its own trigger when it closes. Use align="start" so each panel opens under its trigger rather than centerd on it.

41 orders

In a table row

PopoverAnchor in React and slPopoverAnchor in Angular name the element the panel is positioned against, when that is not the trigger. Here the panel hangs off the whole row, aligned to its end edge, and the row’s button opens it. A press on the anchor counts as a press inside the popover, so it does not close the panel.

Shipped orders
OrderCustomerShipment
10248Vins et alcools Chevalier
10249Toms Spezialitäten
10250Hanari Carnes

Long content

PopoverBody (slPopoverBody) is the only part that scrolls. Its height is bounded by the space left between the trigger and the edge of the screen, so the header and the footer stay in view and the actions remain in reach.

Narrow screens

The panel keeps 16 pixels from each edge of the screen, whatever its size: the 8 pixels of collisionPadding plus the gap the layer keeps around the panel. A panel that would cross the edge slides back inside it, and the arrow keeps pointing at the trigger. On a 390-pixel phone screen this lg panel, aligned to the start of a trigger at the end of the row, is 358 pixels wide instead of 368.

A sheet on a phone

presentation="auto" presents the panel as a bottom sheet on a phone, under (max-width: 480px) and (pointer: coarse), and as the anchored panel anywhere else. Use it for a note of several paragraphs, which an anchored panel opens over what it explains. The sheet is modal: a press on the scrim, a pull of its grip, Escape and the platform’s way back close it, and focus returns to the trigger. Its heading is the title of the panel or, without one, the panel’s aria-label.

Defaults for a section

PopoverDefaultsProvider in React and providePopoverDefaults in Angular set any option once for every popover under them, such as size and arrow for a row of payment terms. A value set on one popover still wins: the last popover here draws its arrow.

Accessibility

KeyEffectFocus
Entertoggles the popover, from the consumer's own buttonthe panel, or the element initialFocus names
Spacetoggles the popover, under the same rulethe panel, or the element initialFocus names
Escapecloses the popover, from the topmost layer onlythe trigger, or the element finalFocus names
Tabmoves through the panel's own focusable elements; past the last one it reaches the trailing focus guard, which closes the popoverthe next element in the panel, then the trigger
Shift+Tabmoves back through the panel; before the first element it reaches the leading focus guard, which closes the popoverthe previous element in the panel, then the trigger
  • The panel is a non-modal dialog: aria-modal is not written, nothing behind it becomes inert, and the page keeps scrolling. The sheet of presentation="auto" is the exception: it covers a phone’s screen, so it is modal, holds focus and returns it to the trigger. Use Dialog for content that has to block the page.
  • The trigger carries aria-expanded, aria-haspopup="dialog", and aria-controls while the panel is in the document. The panel is named by its title through aria-labelledby and described by its description through aria-describedby. A popover without a title has no accessible name until you write aria-label on PopoverContent.
  • Focus moves to the panel on open, so a screen reader announces its name before its contents, and returns to the trigger on close. If the reader has moved focus elsewhere on the page, focus stays there. initialFocus and finalFocus name other targets.
  • Tab past the last control in the panel, or Shift+Tab before the first, closes the popover and returns focus to the trigger; the next Tab continues down the page. Focus is never trapped in the panel.

API

Popover

Props

openboolean
Whether the panel is open. Passing it makes the popover controlled for the life of the component; update it from onOpenChange.
defaultOpenbooleanDefault false
The open state an uncontrolled popover starts with. It is read once.
size'sm' | 'md' | 'lg'Default md
The maximum width of the layer, which holds the panel and the gap around it: 16rem, 20rem or 24rem, with the inset and the title size to match.
width'auto' | 'anchor'Default auto
auto sizes the panel to its content, up to the width size sets. anchor makes it exactly as wide as the anchor.
side'top' | 'bottom' | 'inline-start' | 'inline-end' | 'left' | 'right'Default bottom
The edge of the anchor the panel opens against. inline-start and inline-end follow the writing direction of the layer.
align'start' | 'center' | 'end'Default center
Where the panel sits along the side it opened on.
mount'active' | 'lazy' | 'eager'Default active
When the layer exists. active builds it on open and removes it after the exit animation. lazy builds it on the first open and keeps it, for a panel whose content is expensive to build. eager builds it from the start.
strategy'absolute' | 'fixed'Default absolute
The CSS position of the layer. Use fixed for a layer inside an overflow: hidden container, and absolute for one inside a transformed container.
arrowbooleanDefault true
Whether PopoverArrow is drawn.
autoFocusbooleanDefault true
Whether focus moves into the popover on open. Focus goes to the panel itself rather than to its first control, so a screen reader announces the panel’s name first and a destructive first control is not focused by default.
closeOnEscapebooleanDefault true
Whether Escape closes the popover. Escape reaches only the topmost layer.
closeOnOutsidePressboolean | (target, event) => booleanDefault true
Whether a press outside the panel closes the popover. A function decides per press, for a panel that has to stay open when the reader presses a toast beside it.
flipbooleanDefault true
Whether the panel moves to the opposite side when it does not fit.
shiftbooleanDefault true
Whether the panel slides along its side to stay inside the boundary.
hideWhenDetachedbooleanDefault false
Whether the panel hides when its anchor scrolls out of view. It is off, unlike Tooltip’s, so a task the reader is halfway through does not disappear when the row behind it scrolls.
portalbooleanDefault true
Whether the layer is rendered into the shared portal root at the end of the document. The portalled layer keeps the theme, color scheme, density and direction of the region it was opened from.
presentation'popover' | 'auto'Default popover
auto presents the panel as a bottom sheet under (max-width: 480px) and (pointer: coarse): modal, with a scrim, a grip and focus held in it, headed by PopoverTitle or by the panel’s aria-label. It reads the drawer’s surface, radius, scrim and motion tokens.
disabledbooleanDefault false
Whether the popover never opens. It does not disable the trigger; set disabled on the trigger element for that.
messagesPartial<PopoverMessages>
Text that replaces the language’s messages for this popover, key by key. close is the close button’s accessible name; an aria-label on PopoverClose takes precedence.
sideOffsetnumberDefault 0
Extra distance from the anchor in pixels, added to the standard gap.
alignOffsetnumberDefault 0
Distance in pixels along the alignment axis.
collisionPaddingnumberDefault 8
The minimum distance in pixels between the panel and the edge of the boundary.
arrowPaddingnumberDefault 12
The minimum distance in pixels between the arrow and the panel’s corners, so the arrow stays off the rounded corner.
initialFocusElement | RefObject | string
What takes focus on open instead of the panel, such as a search field. A string is a selector read inside the panel.
finalFocusElement | RefObject | string
What takes focus on close instead of the trigger, for a popover whose trigger is gone by then, such as one that deleted its own row.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: PopoverChangeRequest)Before the panel opens or closes, once per change. request.reason is pointer, keyboard, escape, outsidePress, dismiss or programmatic. request.cancel() refuses the change: an uncontrolled popover stays as it is.

Composition

render(props) => ReactNode
On every partRenders the part as the element it returns, with the props it receives spread on it. The trigger uses it to render a Button, and the title uses it to render a heading.
refRef<PopoverHandle>
A handle with open(), close() and reposition(), for code that has to open, close or re-measure the popover outside a render.
PopoverAnchorcomponent
On compositionThe element the panel is positioned against, when it is not the trigger, such as a table row. It writes no attributes. A press on it counts as a press inside the popover.
PopoverDefaultsProvidercomponent
On applicationSets any option for every popover inside it. An option set on a popover takes precedence.
containerElement | nullDefault document.body
On PopoverDefaultsProviderWhere every layer inside the provider is rendered, for an application shell with its own stacking context. It calls setPortalContainer.
native propsComponentPropsWithRef
On every partEach part takes the props of its element. An onClick on the trigger runs before the popover’s own handler, and event.preventDefault() stops the popover’s handler.

Parts

PartElementRequiredPurpose
rootdiv, rendered by PopoverLayerYesThe positioned layer. The positioner writes its position on this element, and this element scales and fades. Its padding is the gap between the trigger and the panel, which is where the arrow stands. It carries data-ui="popover", data-side, data-align, data-size, data-width, data-presentation and data-open.
contentdivYesThe panel, with role="dialog" and tabindex="-1". It is named by its title and described by its description when those parts are present. aria-modal is written on the sheet of a phone alone, because the anchored panel is not modal. It draws no padding: PopoverHeader, PopoverBody and PopoverFooter carry the panel inset, set by --slotted-popover-padding-inline and --slotted-popover-padding-block.
headerdivNoThe row that holds the title, the description and the close button. It keeps its height while the body scrolls.
titlediv, or the element render returnsNoThe panel’s accessible name. It is a div by default, because only the page knows whether the title belongs in the document outline; render it as a heading when it does.
descriptionpNoOne line under the title, referenced by the panel through aria-describedby.
bodydivNoThe only part that scrolls, bounded by --slotted-positioner-available-height. A scroll shadow at the cut edge shows that there is more content.
footerdivNoThe actions row, separated from the body by a rule and kept under it.
closebuttonNoThe close button, for a pointer or a touch screen, where there is no Escape key. It draws a cross glyph unless you pass children. With no text of its own it is named by the close message of the language in force; with text, such as Done, the text is its name.
arrowdivNoA rotated square in the panel’s background and border colors, which continues the panel’s outline towards the anchor. Place it beside PopoverContent inside PopoverLayer, not inside the content: the stylesheet selects it as a direct child of the layer.
backdropdivNoThe scrim of the sheet presentation="auto" draws on a phone. A press on it closes the sheet.
gripspanNoThe line at the top of that sheet, hidden from assistive technology. A pull down on it closes the sheet.
focus-guardspan (two of them)YesTwo zero-sized, focusable elements hidden from assistive technology, one on each side of the panel. Tab or Shift+Tab onto either one closes the popover and returns focus to the trigger.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every popover inside it.

Popover tokens

TokenDefault
--slotted-popover-arrow-size0.625rem
--slotted-popover-arrow-tip-radiusvar(--slotted-radius-xs, 2px)
--slotted-popover-backdrop-filternone
--slotted-popover-border-colorvar(--slotted-border-subtle, #e2e8f0)
--slotted-popover-gapvar(--slotted-space-4, 0.5rem)
--slotted-popover-measure20rem
--slotted-popover-measure-lg24rem
--slotted-popover-measure-sm16rem
--slotted-popover-padding-blockvar(--slotted-space-5, 0.75rem)
--slotted-popover-padding-block-lgvar(--slotted-space-6, 1rem)
--slotted-popover-padding-block-smvar(--slotted-space-4, 0.5rem)
--slotted-popover-padding-inlinevar(--slotted-space-6, 1rem)
--slotted-popover-padding-inline-lgvar(--slotted-space-7, 1.25rem)
--slotted-popover-padding-inline-smvar(--slotted-space-5, 0.75rem)
--slotted-popover-radiusvar(--slotted-radius-lg, 8px)
--slotted-popover-shadowvar(--slotted-shadow-md)
--slotted-popover-surfacevar(--slotted-surface-raised, #ffffff)
--slotted-popover-textvar(--slotted-text, #0f172a)

Theme tokens it reads

TokenDefault
--slotted-border-strongSet per scheme by the theme
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-control-gap-mdcomfortable 8px · compact 6px · dense 4px
--slotted-control-height-smcomfortable 30px · compact 26px · dense 24px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-drawer-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-drawer-radiusvar(--_radius)
--slotted-drawer-resizer-line-colorvar(--slotted-border-strong, ButtonBorder)
--slotted-drawer-scrimvar(--slotted-scrim, Canvas)
--slotted-drawer-scrim-backdrop-filternone
--slotted-drawer-slide-durationvar(--slotted-duration-short)
--slotted-drawer-slide-easingvar(--slotted-easing-standard)
--slotted-drawer-slide-exit-durationvar(--slotted-drawer-slide-duration, var(--slotted-duration-short))
--slotted-drawer-slide-exit-easingvar(--slotted-easing-exit)
--slotted-drawer-surfacevar(--slotted-surface-raised, Canvas)
--slotted-duration-long320ms
--slotted-duration-medium200ms
--slotted-duration-short120ms
--slotted-easing-entercubic-bezier(0.05, 0.7, 0.1, 1)
--slotted-easing-exitcubic-bezier(0.3, 0, 0.8, 0.15)
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-headingvar(--slotted-font-family-sans)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-size-lg1rem
--slotted-font-size-md0.875rem
--slotted-font-size-sm0.8125rem
--slotted-font-size-xl1.125rem
--slotted-font-weight-semibold600
--slotted-line-height-lg1.5
--slotted-line-height-md1.5
--slotted-line-height-sm1.45
--slotted-overlay-max-block-size100vh
--slotted-radius-lg8px
--slotted-radius-sm4px
--slotted-radius-xs2px
--slotted-scrimSet per scheme by the theme
--slotted-shadow-lgSet per scheme by the theme
--slotted-shadow-mdSet per scheme by the theme
--slotted-space-113rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-target-min24px
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme
--slotted-z-index-popover1100