Popover
A popover opens a small panel next to the button that opened it, for extra content or a short task that doesn’t need a dialog.
When to use
Section titled “When to use”- Use it to share a link, set a quick filter, or show details about one item.
- Use a Tooltip for a one-line name of an icon button, and a Dialog for a task that needs the whole attention.
- Use a Dropdown Menu for a list of actions.
Anatomy
Section titled “Anatomy”- 1Trigger
- 2Arrow
- 3Content
A panel on popover with a border, radius-lg and shadow-lg, 288px wide by default, placed beside its trigger. It renders outside the page flow, so a card never clips it. A title and one sentence of description may head it.
Variants
Section titled “Variants”There is one style. Choose the side (top, right, bottom, left) and the alignment (start, center, end).
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
open / onOpenChange |
v-model:open |
controller |
boolean | false |
Opens and closes it from code. |
side on PopoverContent |
side on PopoverContent |
anchor |
text | bottom |
Which side of the trigger it opens on. |
align on PopoverContent |
align on PopoverContent |
anchor |
text | center |
How it lines up with the trigger. |
PopoverTrigger render |
PopoverTrigger as-child |
child |
element | none | The button that opens it. |
import { useId } from "react"import { Button } from "@/components/ui/button"import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"import { Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger } from "@/components/ui/popover"
export default function PopoverDemo() { const id = useId() return ( <Popover> <PopoverTrigger render={<Button variant="outline" />}>Bagikan</PopoverTrigger> <PopoverContent> <PopoverHeader> <PopoverTitle>Bagikan rilis</PopoverTitle> <PopoverDescription>Siapa pun yang punya tautan ini bisa mendengarkan.</PopoverDescription> </PopoverHeader> <div className="grid gap-2"> <Label htmlFor={`${id}-link`}>Tautan rilis</Label> <div className="flex gap-2"> <Input id={`${id}-link`} readOnly defaultValue="https://contoh.id/senja-di-kota" /> <Button>Salin</Button> </div> </div> </PopoverContent> </Popover> )}<script setup lang="ts">import { useId } from "vue"import { Button } from "@/components/ui/button"import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
const id = useId()</script>
<template> <Popover> <PopoverTrigger as-child> <Button variant="outline">Bagikan</Button> </PopoverTrigger> <PopoverContent class="grid gap-2.5" :aria-describedby="`${id}-description`"> <div class="grid gap-1"> <p class="font-medium">Bagikan rilis</p> <p :id="`${id}-description`" class="text-muted-foreground">Siapa pun yang punya tautan ini bisa mendengarkan.</p> </div> <div class="grid gap-2"> <Label :for="`${id}-link`">Tautan rilis</Label> <div class="flex gap-2"> <Input :id="`${id}-link`" readonly default-value="https://contoh.id/senja-di-kota" /> <Button>Salin</Button> </div> </div> </PopoverContent> </Popover></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class PopoverDemo extends StatefulWidget { const PopoverDemo({super.key});
@override State<PopoverDemo> createState() => _PopoverDemoState();}
class _PopoverDemoState extends State<PopoverDemo> { final controller = ShadPopoverController();
@override void dispose() { controller.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { final theme = ShadTheme.of(context); return ShadPopover( controller: controller, popover: (context) => SizedBox( width: 288, child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, spacing: 8, children: [ Text('Bagikan rilis', style: theme.textTheme.large), Text('Siapa pun yang punya tautan ini bisa mendengarkan.', style: theme.textTheme.muted), Row( spacing: 8, children: [ const Expanded( child: ShadInput(initialValue: 'https://contoh.id/senja-di-kota', readOnly: true), ), ShadButton(child: const Text('Salin'), onPressed: () {}), ], ), ], ), ), child: ShadButton.outline(onPressed: controller.toggle, child: const Text('Bagikan')), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/popover.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/popover.jsonAccessibility
Section titled “Accessibility”- The panel is a dialog that takes the focus when it opens and gives it back to the trigger when it closes.
- Escape and a click outside close it.
- Give the trigger a clear name, such as “Bagikan”.
