Popover
A floating panel of content or controls anchored to a button.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native ARIA (shared positioning)
- 5 parts, named exports
- The trigger has aria-expanded and aria-controls; the panel is role=dialog.
- Focus moves into the panel; Escape or an outside click closes it and focus returns to the trigger.
- Styles in one file:
popover.css
Import
import '@monoline/css';
import {Popover} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add popover
Usage
import {Button, Popover, PopoverContent, PopoverTrigger} from '@monoline/react';
<Popover>
<PopoverTrigger asChild>
<Button variant="line">Details</Button>
</PopoverTrigger>
<PopoverContent aria-label="Entry details">
<p style={{margin: 0}}>Logged today at 14:20. 3 files changed.</p>
</PopoverContent>
</Popover>
Anatomy
Import the parts you need and nest them like this.
import {Popover, PopoverTrigger, PopoverAnchor, PopoverClose, PopoverContent} from '@monoline/react';
<Popover>
<PopoverTrigger />
<PopoverAnchor />
<PopoverClose />
<PopoverContent />
</Popover>
Examples
Basic
Props
PopoverProps
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | – | Controlled open state. |
defaultOpen | boolean | false | Initial open state when uncontrolled. Default false. |
onOpenChange | ((open: boolean) => void) | – | Called with the next open state when the user opens or dismisses it. |
children | ReactNode | – | The parts of the component: a trigger and its content. |
PopoverContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
onEscapeKeyDown | ((event: Event) => void) | – | Called when Escape is pressed; call `event.preventDefault()` to keep it open. |
onInteractOutside | ((event: Event) => void) | – | Called when a press or focus lands outside; call `event.preventDefault()` to keep it open. |
onOpenAutoFocus | ((event: Event) => void) | – | Called after it opens, before focus moves in; `preventDefault()` keeps focus where it is or lets you move it yourself. |
onCloseAutoFocus | ((event: Event) => void) | – | Called after it closes, before focus returns to the trigger; `preventDefault()` lets you move focus yourself. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-disabled] | popover.css |
[data-highlighted] | popover.css |
[data-variant="danger"] | popover.css |
CSS classes
| Class | Stylesheet |
|---|---|
.menu-content | popover.css |
.menu-indicator | popover.css |
.menu-item | popover.css |
.menu-item-check | popover.css |
.menu-label | popover.css |
.popover | popover.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.menu-content {
border-color: var(--accent);
}
.menu-content[data-disabled] {
background: var(--wash);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
example.tsx
<Popover>
<PopoverTrigger asChild>
<Button>Open popover</Button>
</PopoverTrigger>
<PopoverContent>
<p>Dimensions</p>
Set the width and height of the layer.
</PopoverContent>
</Popover>
Accessibility
- The trigger has aria-expanded and aria-controls; the panel is role=dialog.
- Focus moves into the panel; Escape or an outside click closes it and focus returns to the trigger.