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.
import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Popover, PopoverArrow, PopoverBody, PopoverClose, PopoverContent, PopoverDescription, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';const stock = [ { term: 'On hand', value: '39 units' }, { term: 'Reserved', value: '12 units' }, { term: 'Reorder point', value: '25 units' }, { term: 'Next delivery', value: 'Oct 14, Exotic Liquids' },];export default function PopoverBasic() { return ( <Popover> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Chai stock </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Chai</PopoverTitle> <PopoverDescription>SKU NW-1001, Seattle warehouse</PopoverDescription> <PopoverClose /> </PopoverHeader> <PopoverBody> <DescriptionList> {stock.map((row) => ( <DescriptionListItem key={row.term}> <DescriptionListTerm>{row.term}</DescriptionListTerm> <DescriptionListDescription>{row.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> );}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.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { 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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverLayer, type PopoverSide, PopoverTrigger,} from '@slotted/react/popover';const sides: { side: PopoverSide; text: string }[] = [ { side: 'top', text: 'Speedy Express collects at 4:00 PM.' }, { side: 'bottom', text: 'United Package collects at 5:30 PM.' }, { side: 'inline-start', text: 'Federal Shipping collects at 11:00 AM.' }, { side: 'inline-end', text: 'Northwind Courier collects at 2:00 PM.' },];export default function PopoverPlacement() { return ( <Inline gap={3} justify="center" wrap="wrap"> {sides.map(({ side, text }) => ( <Popover key={side} side={side}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {side} </Button> )} /> <PopoverLayer> <PopoverContent aria-label={`Pickup, ${side}`}> <PopoverBody>{text}</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> ))} </Inline> );}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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, type PopoverAlign, PopoverArrow, PopoverBody, PopoverContent, PopoverLayer, PopoverTrigger,} from '@slotted/react/popover';const alignments: PopoverAlign[] = ['start', 'center', 'end'];export default function PopoverAlignment() { return ( <Inline gap={3} justify="center" wrap="wrap"> {alignments.map((align) => ( <Popover key={align} align={align}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Align {align} </Button> )} /> <PopoverLayer> <PopoverContent aria-label={`Restock, aligned ${align}`}> <PopoverBody>Restock 40 units of Chang from Exotic Liquids by Oct 14.</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> ))} </Inline> );}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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverLayer, PopoverTrigger,} from '@slotted/react/popover';export default function PopoverArrowAndOffset() { return ( <Inline gap={3} justify="center" wrap="wrap"> <Popover> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> With arrow </Button> )} /> <PopoverLayer> <PopoverContent aria-label="Pickup window"> <PopoverBody>Speedy Express collects between 3:30 and 4:00 PM.</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> <Popover arrow={false} sideOffset={8}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> No arrow, 8px further </Button> )} /> <PopoverLayer> <PopoverContent aria-label="Pickup window"> <PopoverBody>Speedy Express collects between 3:30 and 4:00 PM.</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> </Inline> );}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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverHeader, PopoverLayer, type PopoverSize, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';const sizes: PopoverSize[] = ['sm', 'md', 'lg'];export default function PopoverSizes() { return ( <Inline gap={3} justify="center" wrap="wrap"> {sizes.map((size) => ( <Popover key={size} size={size}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {size} </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Order 10248</PopoverTitle> </PopoverHeader> <PopoverBody> Vins et alcools Chevalier, Reims. Three lines, 440.00 USD, shipped by Federal Shipping on Jul 16. </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> ))} </Inline> );}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.
import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverLayer, PopoverTrigger,} from '@slotted/react/popover';const warehouses = [ { name: 'Seattle', stock: '39 units' }, { name: 'Tacoma', stock: '120 units' }, { name: 'Portland', stock: 'Out of stock' },];export default function PopoverWidth() { return ( <Popover align="start" width="anchor"> <PopoverTrigger render={(props) => ( <Button {...props} fullWidth tone="secondary" variant="outline"> Chai, stock by warehouse </Button> )} /> <PopoverLayer> <PopoverContent aria-label="Chai stock by warehouse"> <PopoverBody> <DescriptionList> {warehouses.map((warehouse) => ( <DescriptionListItem key={warehouse.name}> <DescriptionListTerm>{warehouse.name}</DescriptionListTerm> <DescriptionListDescription>{warehouse.stock}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Radio, RadioGroup } from '@slotted/react/radio-group';import { Text } from '@slotted/react/typography';const pickers = ['Nancy Davolio', 'Andrew Fuller', 'Janet Leverling', 'Margaret Peacock'];export default function PopoverControlled() { const [open, setOpen] = useState(false); const [picker, setPicker] = useState('Nancy Davolio'); return ( <Inline align="center" gap={3}> <Text size="sm">Order 10251, picked by {picker}</Text> <Popover open={open} onOpenChange={setOpen} align="end"> <PopoverTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Reassign </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Picker for order 10251</PopoverTitle> </PopoverHeader> <PopoverBody> <RadioGroup aria-label="Picker" value={picker} onValueChange={(next) => { setPicker(next); setOpen(false); }} > {pickers.map((name) => ( <Radio key={name} value={name}> {name} </Radio> ))} </RadioGroup> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> </Inline> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverClose, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Text } from '@slotted/react/typography';export default function PopoverDismissal() { const [reason, setReason] = useState('not closed yet'); return ( <Inline align="center" gap={3}> <Popover onOpenChange={(open, request) => { if (!open) setReason(request.reason); }} > <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Delivery note </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Order 10249 delivery note</PopoverTitle> <PopoverClose /> </PopoverHeader> <PopoverBody> Leave at the loading dock behind Toms Spezialitäten. The gate closes at 6:00 PM. </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> <Text size="sm" tone="muted"> Last closed by: {reason} </Text> </Inline> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Field, FieldLabel } from '@slotted/react/field';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';const customers = [ 'Alfreds Futterkiste', 'Ernst Handel', 'Frankenversand', 'Königlich Essen', 'Wartian Herkku',];export default function PopoverFocus() { const [query, setQuery] = useState(''); const matches = customers.filter((name) => name.toLowerCase().includes(query.trim().toLowerCase()), ); return ( <Popover align="start" initialFocus="input"> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Find a customer </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Find a customer</PopoverTitle> </PopoverHeader> <PopoverBody> <Stack gap={3}> <Field> <FieldLabel>Company name</FieldLabel> <TextField type="search" value={query} onValueChange={setQuery} /> </Field> <Text size="sm" tone="muted"> {matches.length === 0 ? 'No customer matches.' : matches.join(', ')} </Text> </Stack> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { NumberField } from '@slotted/react/number-field';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverDescription, PopoverFooter, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';export default function PopoverForm() { const [open, setOpen] = useState(false); const [onHand, setOnHand] = useState(39); const [count, setCount] = useState<number | null>(39); const [note, setNote] = useState(''); const dirty = count !== onHand || note !== ''; return ( <Inline align="center" gap={3}> <Text size="sm">Chai: {onHand} units on hand</Text> <Popover initialFocus="input" open={open} onOpenChange={(next, request) => { if (!next && request.reason === 'outsidePress' && dirty) { request.cancel(); return; } if (next) { setCount(onHand); setNote(''); } setOpen(next); }} > <PopoverTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Adjust stock </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Adjust Chai stock</PopoverTitle> <PopoverDescription>Seattle warehouse, bin A-14</PopoverDescription> </PopoverHeader> <PopoverBody> <Stack gap={3}> <Field> <FieldLabel>Counted quantity</FieldLabel> <NumberField end="units" min={0} value={count} onValueChange={setCount} /> </Field> <Field> <FieldLabel>Reason</FieldLabel> <TextField value={note} onValueChange={setNote} /> </Field> </Stack> </PopoverBody> <PopoverFooter> <Button size="sm" tone="secondary" variant="ghost" onClick={() => setOpen(false)}> Cancel </Button> <Button size="sm" disabled={count === null} onClick={() => { if (count !== null) setOnHand(count); setOpen(false); }} > Save </Button> </PopoverFooter> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> </Inline> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Checkbox } from '@slotted/react/checkbox';import { CheckboxGroup } from '@slotted/react/checkbox-group';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Toolbar, ToolbarSpacer } from '@slotted/react/toolbar';import { Text } from '@slotted/react/typography';const statuses = [ { value: 'pending', label: 'Pending', orders: 14 }, { value: 'shipped', label: 'Shipped', orders: 27 }, { value: 'delivered', label: 'Delivered', orders: 112 }, { value: 'returned', label: 'Returned', orders: 3 },];export default function PopoverToolbar() { const [shown, setShown] = useState<readonly string[]>(['pending', 'shipped']); const count = statuses .filter((status) => shown.includes(status.value)) .reduce((sum, status) => sum + status.orders, 0); return ( <Toolbar aria-label="Orders"> <Popover align="start"> <PopoverTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="ghost"> Status </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Show orders that are</PopoverTitle> </PopoverHeader> <PopoverBody> <CheckboxGroup aria-label="Status" value={shown} onValueChange={setShown}> {statuses.map((status) => ( <Checkbox key={status.value} value={status.value}> {status.label} </Checkbox> ))} </CheckboxGroup> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> <Popover align="start"> <PopoverTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="ghost"> Columns </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Columns</PopoverTitle> </PopoverHeader> <PopoverBody> <CheckboxGroup aria-label="Columns" defaultValue={['customer', 'total']}> <Checkbox value="customer">Customer</Checkbox> <Checkbox value="ship-via">Ship via</Checkbox> <Checkbox value="total">Total</Checkbox> </CheckboxGroup> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> <ToolbarSpacer /> <Text size="sm" tone="muted"> {count} orders </Text> </Toolbar> );}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.
| Order | Customer | Shipment |
|---|---|---|
| 10248 | Vins et alcools Chevalier | |
| 10249 | Toms Spezialitäten | |
| 10250 | Hanari Carnes |
import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverClose, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Table, TableBody, TableCaption, TableCell, TableColumnHeader, TableContent, TableHead, TableRow, TableRowHeader,} from '@slotted/react/table';const orders = [ { id: '10248', customer: 'Vins et alcools Chevalier', carrier: 'Federal Shipping', tracking: 'FS-4471-0921', shipped: 'Jul 16', }, { id: '10249', customer: 'Toms Spezialitäten', carrier: 'Speedy Express', tracking: 'SE-2210-3384', shipped: 'Jul 10', }, { id: '10250', customer: 'Hanari Carnes', carrier: 'United Package', tracking: 'UP-9035-1172', shipped: 'Jul 12', },];export default function PopoverTableRow() { return ( <Table columns={3}> <TableContent> <TableCaption>Shipped orders</TableCaption> <TableHead> <TableRow> <TableColumnHeader>Order</TableColumnHeader> <TableColumnHeader>Customer</TableColumnHeader> <TableColumnHeader>Shipment</TableColumnHeader> </TableRow> </TableHead> <TableBody> {orders.map((order) => ( <Popover key={order.id} align="end"> <PopoverAnchor render={(props) => ( <TableRow {...props} value={order.id}> <TableRowHeader>{order.id}</TableRowHeader> <TableCell>{order.customer}</TableCell> <TableCell> <PopoverTrigger render={(triggerProps) => ( <Button {...triggerProps} size="sm" tone="secondary" variant="ghost"> Tracking </Button> )} /> </TableCell> </TableRow> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Order {order.id} shipment</PopoverTitle> <PopoverClose /> </PopoverHeader> <PopoverBody> <DescriptionList> <DescriptionListItem> <DescriptionListTerm>Carrier</DescriptionListTerm> <DescriptionListDescription>{order.carrier}</DescriptionListDescription> </DescriptionListItem> <DescriptionListItem> <DescriptionListTerm>Tracking</DescriptionListTerm> <DescriptionListDescription>{order.tracking}</DescriptionListDescription> </DescriptionListItem> <DescriptionListItem> <DescriptionListTerm>Shipped</DescriptionListTerm> <DescriptionListDescription>{order.shipped}</DescriptionListDescription> </DescriptionListItem> </DescriptionList> </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> ))} </TableBody> </TableContent> </Table> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Popover, PopoverArrow, PopoverBody, PopoverClose, PopoverContent, PopoverFooter, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const activity = [ 'Jul 4, 9:12 AM. Order placed by Vins et alcools Chevalier.', 'Jul 4, 9:40 AM. Payment authorized, 440.00 USD.', 'Jul 5, 8:05 AM. Allocated to the Seattle warehouse.', 'Jul 5, 2:30 PM. Picked by Nancy Davolio.', 'Jul 6, 10:15 AM. Packed in two cartons, 14.2 kg.', 'Jul 8, 11:00 AM. Customs documents filed for France.', 'Jul 16, 4:00 PM. Collected by Federal Shipping.', 'Jul 18, 7:20 AM. Arrived at the Le Havre hub.', 'Jul 19, 9:45 AM. Out for delivery in Reims.', 'Jul 19, 3:10 PM. Delivered, signed by P. Henriot.',];export default function PopoverScrolling() { const [open, setOpen] = useState(false); return ( <Popover open={open} onOpenChange={setOpen}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Order 10248 activity </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Order 10248 activity</PopoverTitle> <PopoverClose /> </PopoverHeader> <PopoverBody> <Stack gap={3}> {activity.map((entry) => ( <Text key={entry} size="sm"> {entry} </Text> ))} </Stack> </PopoverBody> <PopoverFooter> <Button size="sm" onClick={() => setOpen(false)}> Done </Button> </PopoverFooter> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> );}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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverHeader, PopoverLayer, PopoverTitle, PopoverTrigger,} from '@slotted/react/popover';export default function PopoverNarrow() { return ( <Inline justify="end"> <Popover align="start" size="lg"> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Volume pricing </Button> )} /> <PopoverLayer> <PopoverContent> <PopoverHeader> <PopoverTitle>Volume pricing for Chai</PopoverTitle> </PopoverHeader> <PopoverBody> 18.00 USD a case up to 24 cases, 16.20 USD from 25 cases, and 15.30 USD from 100 cases. Prices apply to orders shipped from the Seattle warehouse. </PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> </Inline> );}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.
import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverDefaultsProvider, PopoverLayer, PopoverTrigger,} from '@slotted/react/popover';const terms = [ { label: 'Net 30', text: 'Payment is due 30 days after the invoice date.' }, { label: 'Net 60', text: 'Payment is due 60 days after the invoice date.' },];export default function PopoverDefaults() { return ( <PopoverDefaultsProvider arrow={false} size="sm"> <Inline gap={3} justify="center" wrap="wrap"> {terms.map((term) => ( <Popover key={term.label}> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {term.label} </Button> )} /> <PopoverLayer> <PopoverContent aria-label={term.label}> <PopoverBody>{term.text}</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> ))} <Popover arrow> <PopoverTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Cash in advance </Button> )} /> <PopoverLayer> <PopoverContent aria-label="Cash in advance"> <PopoverBody>The order ships once the payment has cleared.</PopoverBody> </PopoverContent> <PopoverArrow /> </PopoverLayer> </Popover> </Inline> </PopoverDefaultsProvider> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Enter | toggles the popover, from the consumer's own button | the panel, or the element initialFocus names |
| Space | toggles the popover, under the same rule | the panel, or the element initialFocus names |
| Escape | closes the popover, from the topmost layer only | the trigger, or the element finalFocus names |
| Tab | moves through the panel's own focusable elements; past the last one it reaches the trailing focus guard, which closes the popover | the next element in the panel, then the trigger |
| Shift+Tab | moves back through the panel; before the first element it reaches the leading focus guard, which closes the popover | the 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.
defaultOpenbooleanDefaultfalse- The open state an uncontrolled popover starts with. It is read once.
size'sm' | 'md' | 'lg'Defaultmd- 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'Defaultauto- 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'Defaultbottom- 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'Defaultcenter- Where the panel sits along the side it opened on.
mount'active' | 'lazy' | 'eager'Defaultactive- 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'Defaultabsolute- The CSS position of the layer. Use fixed for a layer inside an overflow: hidden container, and absolute for one inside a transformed container.
arrowbooleanDefaulttrue- Whether PopoverArrow is drawn.
autoFocusbooleanDefaulttrue- 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.
closeOnEscapebooleanDefaulttrue- Whether Escape closes the popover. Escape reaches only the topmost layer.
closeOnOutsidePressboolean | (target, event) => booleanDefaulttrue- 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.
flipbooleanDefaulttrue- Whether the panel moves to the opposite side when it does not fit.
shiftbooleanDefaulttrue- Whether the panel slides along its side to stay inside the boundary.
hideWhenDetachedbooleanDefaultfalse- 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.
portalbooleanDefaulttrue- 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'Defaultpopover- 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.
disabledbooleanDefaultfalse- 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.
sideOffsetnumberDefault0- Extra distance from the anchor in pixels, added to the standard gap.
alignOffsetnumberDefault0- Distance in pixels along the alignment axis.
collisionPaddingnumberDefault8- The minimum distance in pixels between the panel and the edge of the boundary.
arrowPaddingnumberDefault12- 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
| Name | Payload | When |
|---|---|---|
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 | nullDefaultdocument.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
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, rendered by PopoverLayer | Yes | The 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. |
content | div | Yes | The 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. |
header | div | No | The row that holds the title, the description and the close button. It keeps its height while the body scrolls. |
title | div, or the element render returns | No | The 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. |
description | p | No | One line under the title, referenced by the panel through aria-describedby. |
body | div | No | The only part that scrolls, bounded by --slotted-positioner-available-height. A scroll shadow at the cut edge shows that there is more content. |
footer | div | No | The actions row, separated from the body by a rule and kept under it. |
close | button | No | The 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. |
arrow | div | No | A 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. |
backdrop | div | No | The scrim of the sheet presentation="auto" draws on a phone. A press on it closes the sheet. |
grip | span | No | The line at the top of that sheet, hidden from assistive technology. A pull down on it closes the sheet. |
focus-guard | span (two of them) | Yes | Two 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
| Token | Default |
|---|---|
--slotted-popover-arrow-size | 0.625rem |
--slotted-popover-arrow-tip-radius | var(--slotted-radius-xs, 2px) |
--slotted-popover-backdrop-filter | none |
--slotted-popover-border-color | var(--slotted-border-subtle, #e2e8f0) |
--slotted-popover-gap | var(--slotted-space-4, 0.5rem) |
--slotted-popover-measure | 20rem |
--slotted-popover-measure-lg | 24rem |
--slotted-popover-measure-sm | 16rem |
--slotted-popover-padding-block | var(--slotted-space-5, 0.75rem) |
--slotted-popover-padding-block-lg | var(--slotted-space-6, 1rem) |
--slotted-popover-padding-block-sm | var(--slotted-space-4, 0.5rem) |
--slotted-popover-padding-inline | var(--slotted-space-6, 1rem) |
--slotted-popover-padding-inline-lg | var(--slotted-space-7, 1.25rem) |
--slotted-popover-padding-inline-sm | var(--slotted-space-5, 0.75rem) |
--slotted-popover-radius | var(--slotted-radius-lg, 8px) |
--slotted-popover-shadow | var(--slotted-shadow-md) |
--slotted-popover-surface | var(--slotted-surface-raised, #ffffff) |
--slotted-popover-text | var(--slotted-text, #0f172a) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-strong | Set per scheme by the theme |
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-control-gap-md | comfortable 8px · compact 6px · dense 4px |
--slotted-control-height-sm | comfortable 30px · compact 26px · dense 24px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-drawer-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-drawer-radius | var(--_radius) |
--slotted-drawer-resizer-line-color | var(--slotted-border-strong, ButtonBorder) |
--slotted-drawer-scrim | var(--slotted-scrim, Canvas) |
--slotted-drawer-scrim-backdrop-filter | none |
--slotted-drawer-slide-duration | var(--slotted-duration-short) |
--slotted-drawer-slide-easing | var(--slotted-easing-standard) |
--slotted-drawer-slide-exit-duration | var(--slotted-drawer-slide-duration, var(--slotted-duration-short)) |
--slotted-drawer-slide-exit-easing | var(--slotted-easing-exit) |
--slotted-drawer-surface | var(--slotted-surface-raised, Canvas) |
--slotted-duration-long | 320ms |
--slotted-duration-medium | 200ms |
--slotted-duration-short | 120ms |
--slotted-easing-enter | cubic-bezier(0.05, 0.7, 0.1, 1) |
--slotted-easing-exit | cubic-bezier(0.3, 0, 0.8, 0.15) |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-heading | var(--slotted-font-family-sans) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-lg | 1rem |
--slotted-font-size-md | 0.875rem |
--slotted-font-size-sm | 0.8125rem |
--slotted-font-size-xl | 1.125rem |
--slotted-font-weight-semibold | 600 |
--slotted-line-height-lg | 1.5 |
--slotted-line-height-md | 1.5 |
--slotted-line-height-sm | 1.45 |
--slotted-overlay-max-block-size | 100vh |
--slotted-radius-lg | 8px |
--slotted-radius-sm | 4px |
--slotted-radius-xs | 2px |
--slotted-scrim | Set per scheme by the theme |
--slotted-shadow-lg | Set per scheme by the theme |
--slotted-shadow-md | Set per scheme by the theme |
--slotted-space-11 | 3rem |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-space-7 | 1.25rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-target-min | 24px |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |
--slotted-z-index-popover | 1100 |