Popover
A small surface its button unfolds into, right where the button is: the button lets go of its label, its glass grows over it into the popover and settles, and closing folds it back.
Latest changeImprovedv1.6.8Closing is no longer the opening played backwards. The content fades first, then the surface slides back into the button and slows as it lands, with no throw and no flash at the end, and the button's label comes back letter by letter. A press on a Close part now lights the surface where it lands, and the light goes into the button with it.
- v1.6.8ImprovedClosing is no longer the opening played backwards. The content fades first, then the surface slides back into the button and slows as it lands, with no throw and no flash at the end, and the button's label comes back letter by letter. A press on a Close part now lights the surface where it lands, and the light goes into the button with it.
- v1.6.8ImprovedThe popover now opens around its button and comes up into place from below.
over="edge"onGlassPopoverContentbrings back the opening from the button's edge, and the newfromprop onGlassPopoverpicks the way:from="top"brings back the drop from above. - v1.6.2ImprovedThe content now follows the width and the height of the glass, so it takes the glass's swing instead of resting inside it while it still moves. It fades up gradually as it comes into focus, and closing is quicker.
- v1.6.0NewPopover: a small surface its button unfolds into, right where the button is. It grows from the button's edge, thrown a little way by its own weight, and settles with the content coming into focus inside. The button, the card and the light are Select's. Positioning, focus, Escape and ARIA come from UI SDK.
- v1.6.0Improved
GlassPopuphas a second way out:useGlassPopup({ opening: 'morph' })turns any control into the surface it opens, for a menu of your own. Popover is built on it; Select and Dropdown Menu keep their stretch. - v1.6.0ImprovedPopover answers its own closing: as the surface comes back in, the button swells, lights up and is thrown the other way before it settles. The light reaches the label and the content too.
- All changes →
Use it for
- A little more about one control, or a few choices for it, without leaving the page: a reminder time, a colour, a short field.
- Content that belongs to the button and should come out of it and go back into it.
Not for
- A plain list of actions: use Dropdown Menu. Picking a value for a form: use Select.
- A hint shown on hover: the button is hidden while the popover is out, so it must be pressed.
Installation
npx shadcn@latest add https://onemorethink.dev/r/popover.jsonThe behaviour (the top layer, positioning, focus, Escape, the outside press, ARIA) comes from UI SDK, so Popover needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.
Usage
import {
GlassPopover,
GlassPopoverClose,
GlassPopoverContent,
GlassPopoverTitle,
GlassPopoverTrigger,
} from '@/components/liquid-glass/glass-popover'
<GlassPopover>
<GlassPopoverTrigger>Remind me</GlassPopoverTrigger>
<GlassPopoverContent>
<GlassPopoverTitle>Remind me</GlassPopoverTitle>
<GlassPopoverClose onClick={() => remind('hour')}>In an hour</GlassPopoverClose>
<GlassPopoverClose onClick={() => remind('tomorrow')}>Tomorrow morning</GlassPopoverClose>
</GlassPopoverContent>
</GlassPopover>The popover settles around the button, the button in its middle (over="edge" grows it from the button's own edge instead, downwards unless side says otherwise). Around the button it stays where it is instead of flipping, so keep the button away from the top and bottom of the screen. Opening, the label goes and a surface comes out of the button, in Card's glass from the first frame; its own weight throws it a little way and it comes up into place from below (from="top" on GlassPopover: down from above), it lands a little past its size and settles, and its corners come last. The content is inside from the start, moves with the glass on both sides, and fades up and sharpens as the glass arrives. The press's light grows with it and reaches the content, and the shadow goes along. Closing is a calmer motion of its own: the content fades first, the surface slides back into the button and slows as it lands, and the button swells a little as it takes it while its label comes back letter by letter. A press on a Close part lights the surface where it lands, and that light goes into the button with it and fades there. While it is out the button is hidden, so it closes by a press outside, Escape or a Close part.
Your own surface
The motion is GlassPopup's second way out, and it is not tied to a popover. For a surface of your own, useGlassPopup({ opening: 'morph' }) turns any control into what it opens (a menu, say); the surface should lie over its control, so give its content a negative sideOffset, the control's height:
import { GlassPopupAnchor, GlassPopupSurface, useGlassPopup } from '@/components/liquid-glass'
const popup = useGlassPopup({ opening: 'morph' })
<MenuTrigger data-glass-host className="rounded-full px-5 h-12 bg-white/60 dark:bg-white/10">
<GlassPopupAnchor popup={popup} />
<span>Actions</span>
</MenuTrigger>
<MenuContent data-glass-popup data-glass-skip sideOffset={-48} className="rounded-3xl p-1.5">
<GlassPopupSurface popup={popup} />
<div data-glass-list>
<MenuItem>Rename</MenuItem>
<MenuItem>Duplicate</MenuItem>
</div>
</MenuContent>- What rides the glass is the element marked
data-glass-list(orrole="menu"/role="listbox") inside the content: wrap your content in one. - The control keeps its place while the surface is out, with its label hidden: it is the surface now.
- The surface takes its corners from the content's own
rounded-*class.
API reference
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeOn | boolean / boolean / (open: boolean) => void | — |
modal
| boolean | 'trap-focus' | false |
GlassPopoverTrigger classNameClasses for the button: 3rem tall with Button's glass by default. Any height works: the popover follows it. | string | — |
fromOn | 'bottom' | 'top' | 'bottom' |
GlassPopoverContent overWhere it lies over the button: around it, the button in its middle, or from the button's own edge. | 'center' | 'edge' | 'center' |
GlassPopoverContent side / align
| 'top' | 'bottom' / 'start' | 'center' | 'end' | 'bottom' / 'center' |
GlassPopoverContent sideOffsetPlace it yourself. Left out, the popover lies over the button as | number | — |
GlassPopoverContent classNameClasses for the popover: | string | — |
GlassPopoverTitle / GlassPopoverDescriptionName the popover and say what it is for. | className | — |
GlassPopoverClose variantA soft button in the popover's own tone, or the main action. It closes the popover; | 'quiet' | 'solid' | 'quiet' |
Accessibility
- A button with
aria-expandedthat opens adialognamed by its title. - Focus moves into the popover as it opens. Escape, a press outside, focus leaving and every Close part close it, and focus returns to the button.
- An icon-only button needs an
aria-label. - With reduced motion the popover opens and closes at once. Without WebGL2 it is a plain frosted panel.