Popover
@codeui/solid v0.3.0
A floating panel anchored to a trigger, for short content and quick settings.
When to use
Use a popover to pick a value for one row or to show short, interactive content next to the control that opened it. It has no scrim and does not block the page. Focus moves into the panel and returns to the trigger on close.
When to choose another component
- Tooltip names a control. It holds text only and cannot take focus.
- DropdownMenu lists actions. Use it when each row runs a command.
- Dialog holds settings or a decision that blocks the page.
- Select picks one value from a list known by name.
Live demo
import { Button, Popover, PopoverContent, PopoverTrigger } from "@codeui/solid";
export default function PopoverBasic() {
return (
<Popover placement="bottom-start">
<PopoverTrigger as={Button} variant="secondary">
Font settings
</PopoverTrigger>
<PopoverContent title="Font settings" description="Applies to every new snippet.">
Ligatures are on for Fira Code and JetBrains Mono.
</PopoverContent>
</Popover>
);
}Popover holds the open state. PopoverTrigger opens it. PopoverContent portals the panel and renders the optional title and description above its children.
Anatomy
Font settings
Applies to every new snippet.
Tap a part to outline it in the demo.
- 01PopoverTrigger
popover-trigger - 02Anchor
popover-anchor - 03Content
popover-contentclasses.content - 04Arrow
popover-arrow - 05Title
popover-titleclasses.title - 06Description
popover-descriptionclasses.description - 07CloseButton
popover-close-button
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Popover, Root | Nothing. Holds the open state | none | none | none |
PopoverTrigger, Trigger | button | none | popover-trigger | Opens and closes the panel |
Anchor (parts only) | div | none | popover-anchor | Element the panel lines up with |
Portal | Nothing. Moves the panel to mount | none | none | none |
Content | div | content | popover-content | role="dialog" |
Arrow (parts only) | div with an svg | none | popover-arrow | Points at the trigger |
Title | h2 | title | popover-title | Accessible name of the panel |
Description | p | description | popover-description | Accessible description |
CloseButton (parts only) | button | none | popover-close-button | Closes the panel |
Variants
Bordered
import { Button, Popover, PopoverContent, PopoverTrigger } from "@codeui/solid";
export default function PopoverBordered() {
return (
<Popover placement="bottom-start">
<PopoverTrigger as={Button} variant="secondary">
Window style
</PopoverTrigger>
<PopoverContent variant="bordered" title="Window style" description="The frame drawn around the code.">
macOS, Windows, or no frame.
</PopoverContent>
</Popover>
);
}variant="bordered" adds a 1px border in --cui-border-menu. Use it when the panel sits on a surface of the same color.
Placement
import { For } from "solid-js";
import { Button, Popover, PopoverContent, PopoverTrigger } from "@codeui/solid";
const placements = [
"top-start",
"top-end",
"right-start",
"right-end",
"bottom-start",
"bottom-end",
"left-start",
"left-end",
] as const;
export default function PopoverPlacements() {
return (
<For each={placements}>
{placement => (
<Popover placement={placement}>
<PopoverTrigger as={Button} variant="secondary" size="sm">
{placement}
</PopoverTrigger>
<PopoverContent title={placement}>The panel opens on this side of the trigger.</PopoverContent>
</Popover>
)}
</For>
);
}placement on Popover sets the side and the alignment: top, right, bottom, or left, each with an optional -start or -end. The default is bottom.
When the panel does not fit, Kobalte flips it to the opposite side.
Gutter and shift
import { Button, Popover, PopoverContent, PopoverTrigger } from "@codeui/solid";
export default function PopoverGutter() {
return (
<>
<Popover placement="bottom">
<PopoverTrigger as={Button} variant="secondary">
Default gutter (6px)
</PopoverTrigger>
<PopoverContent title="Padding">The panel sits 6px below the trigger.</PopoverContent>
</Popover>
<Popover placement="bottom" gutter={16}>
<PopoverTrigger as={Button} variant="secondary">
Gutter 16px
</PopoverTrigger>
<PopoverContent title="Padding">The panel sits 16px below the trigger.</PopoverContent>
</Popover>
<Popover placement="bottom-start" gutter={6} shift={-8}>
<PopoverTrigger as={Button} variant="secondary">
Shift -8px
</PopoverTrigger>
<PopoverContent title="Padding">The panel moves 8px along the trigger edge.</PopoverContent>
</Popover>
</>
);
}gutter is the distance between the trigger and the panel. The kit sets it to 6px. shift moves the panel along the trigger edge.
Rich title and block content
import { Badge, Button, Popover, PopoverContent, PopoverTrigger } from "@codeui/solid";
export default function PopoverRichContent() {
return (
<Popover placement="bottom-start">
<PopoverTrigger as={Button} variant="secondary">
Export styles
</PopoverTrigger>
<PopoverContent
title={
<>
Export styles <Badge tone="info">New</Badge>
</>
}
description="Applies to every new export."
>
<div style={{ display: "grid", "grid-template-columns": "1fr 1fr", gap: "8px" }}>
<Button variant="secondary">PNG</Button>
<Button variant="secondary">SVG</Button>
</div>
</PopoverContent>
</Popover>
);
}title takes JSX, so it can carry a badge. The title names the panel through aria-labelledby.
Children render directly in the content, without a p wrapper. So a grid of buttons or a form is valid HTML inside the panel.
description renders in a p element. Keep it to inline content and put blocks in the children.
Anchor
import { Button } from "@codeui/solid";
import * as P from "@codeui/solid/popover/parts";
export default function PopoverAnchor() {
return (
<P.Root placement="bottom-start">
<P.Anchor
style={{
display: "flex",
gap: "12px",
"align-items": "center",
padding: "8px 8px 8px 16px",
"border-radius": "var(--cui-radius-md)",
background: "var(--cui-surface-input)",
}}
>
<span>Background</span>
<P.Trigger as={Button} variant="secondary" size="sm">
#1d1d1d
</P.Trigger>
</P.Anchor>
<P.Portal>
<P.Content>
<P.Title>Background</P.Title>
<P.Description>The panel lines up with the row, not with the button.</P.Description>
</P.Content>
</P.Portal>
</P.Root>
);
}The Anchor part lines the panel up with an element other than the trigger, such as the whole settings row. The trigger still opens the panel and gets focus back on close.
States
Open, controlled, and uncontrolled
Without open, the popover manages its own state. Set defaultOpen to open it on first render.
To control it, pass open and onOpenChange to Popover.
Modal
modal is false by default, so the rest of the page stays interactive and focus can leave the panel. Moving focus or clicking outside closes it.
Set modal to trap focus inside the panel and hide the rest of the page from assistive technology.
Ready API
Popover
Kobalte's Popover root with a gutter of 6. It renders no element.
Prop
Type
The rest of the root options are in Kobalte's popover docs.
PopoverTrigger
The Trigger part. A button that toggles the panel. Use as={Button} for a kit button.
PopoverContent
Portals the panel and renders the title and the description when they are set.
Prop
Type
Inherited from Kobalte's popover content:
Prop
Type
Styled parts API
Import the parts from @codeui/solid/popover/parts. Each part carries the kit styles and a data-cui attribute, and wraps the matching Kobalte primitive.
import { Button } from "@codeui/solid";
import * as P from "@codeui/solid/popover/parts";
export default function PopoverParts() {
return (
<P.Root placement="bottom-start" gutter={10}>
<P.Trigger as={Button} variant="secondary">
What's new
</P.Trigger>
<P.Portal>
<P.Content variant="bordered">
<P.Arrow />
<div style={{ display: "flex", "align-items": "center", "justify-content": "space-between" }}>
<P.Title>New export panel</P.Title>
<P.CloseButton aria-label="Close what's new" />
</div>
<P.Description>Export styles now live next to the preview.</P.Description>
</P.Content>
</P.Portal>
</P.Root>
);
}This example puts the close button next to the title and adds an arrow. The ready PopoverContent renders neither.
Root
Kobalte's Popover root with a default gutter of 6. Popover is this part.
Prop
Type
Trigger
Kobalte's Popover.Trigger. A button that toggles the panel. PopoverTrigger is this part.
Anchor
Kobalte's Popover.Anchor. A div the panel is positioned against instead of the trigger.
Portal
Kobalte's Popover.Portal. Takes mount. It renders no element.
Content
Kobalte's Popover.Content. The panel.
Prop
Type
Arrow
Kobalte's Popover.Arrow. An arrow that points at the trigger. The kit adds no styles, so it takes the panel fill.
Title
Kobalte's Popover.Title. An h2 that names the panel.
Description
Kobalte's Popover.Description. A p that describes the panel.
CloseButton
Kobalte's Popover.CloseButton, rendered as an extra-small secondary IconButton with a close icon.
Prop
Type
Styles export
popoverStyles
popoverStyles from @codeui/solid/popover/parts maps each part name to a function that returns its class string.
Call popoverStyles.content() for the class and set data-variant="bordered" on custom content. trigger(), anchor(), arrow(), and closeButton() return empty strings.
Call a style function when you render the Kobalte primitive yourself and want the kit look. Add the matching data-cui value from popoverParts too.
Compose styled parts shows a full example.
The root package @codeui/solid also exports a popoverStyles, with a different shape. It is the raw style module: content() returns the base classes and title and description are class strings. Prefer the subpath export.
Accessibility
Keyboard
| Key | Action |
|---|---|
| Enter, Space | On the trigger, opens or closes the panel. |
| Tab | Moves focus through the panel. Moving focus out of a non-modal panel closes it. |
| Escape | Closes the panel and returns focus to the trigger. |
ARIA
- The panel has
role="dialog". Kobalte links it toTitlewitharia-labelledbyand toDescriptionwitharia-describedby. - The trigger has
aria-haspopup="dialog",aria-expanded, andaria-controls. - Without a title, give the panel an accessible name with
aria-labelonPopoverContent. - The close button's accessible name is
close. Change it witharia-label.
Focus
On open, focus moves to the first focusable element in the panel, or to the panel itself. On close, focus returns to the trigger.
SSR notes
An open or force-mounted popover includes its panel in server HTML at the Portal declaration. Hydration adopts the existing nodes and moves them to mount, or document.body by default. Closed content stays absent unless force-mounted. Place Portal in a flow-content context that can contain the panel markup.
The trigger and the anchor render on the server. Their IDs come from Solid's createUniqueId, so they match after hydration.
Theming hooks
Popover reads these --cui-* variables. See Tokens for the defaults.
| Variable | Used for |
|---|---|
--cui-surface-dialog | Panel fill, the floating surface CodeImage uses |
--cui-shadow-dialog | Panel shadow, with a 1px inset ring in dark |
--cui-border-menu, --cui-border-width | Border of the bordered variant |
--cui-text-dialog, --cui-text-dialog-title | Description and title text |
--cui-radius-xl | Panel radius (18px) |
--cui-space-4 | Panel padding, and the phone gutter of the width |
--cui-space-2 | Gap between title, description, and children |
--cui-font-size-sm, --cui-font-line-height-snug | Body and description type (14px / 1.3) |
--cui-font-size-md, --cui-font-weight-semibold | Title type (16px) |
--cui-motion-duration-normal, --cui-motion-duration-fast, --cui-motion-ease-out | Pop: in from scale(0.96) over 160ms, out to scale(0.98) over 120ms |
The panel is at most 360px wide, the Inkstone picker width, and never wider than the viewport minus 16px on each side. That value is a literal in the kit, not a token.
Motion
A popover opened with a pointer pops: it fades in from scale(0.96) over 160ms and leaves toward scale(0.98) in 120ms, growing from the trigger side (--kb-popper-content-transform-origin). Opened from the keyboard, the content gets data-motion="none" and appears and leaves in place. With reduced motion, only the fade is left.
Composition examples
- Compose styled parts builds the same popover three ways.
- Nest overlays opens a menu inside a dialog and shows where Escape goes.
Related
- Tooltip is read-only and opens on hover or focus.
- DropdownMenu lists actions with arrow-key navigation.
- Dialog blocks the page behind a scrim.