# Popover

> Shows extra content or a small form next to its trigger.

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

- Use it to share a link, set a quick filter, or show details about one item.
- Use a [Tooltip](https://design.sosialoka.tech/components/tooltip/) for a one-line name of an icon button, and a [Dialog](https://design.sosialoka.tech/components/dialog/) for a task that needs the whole attention.
- Use a [Dropdown Menu](https://design.sosialoka.tech/components/dropdown-menu/) for a list of actions.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/popover/_

## Anatomy

1. Trigger
2. Arrow
3. Content

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

There is one style. Choose the side (`top`, `right`, `bottom`, `left`) and the alignment (`start`, `center`, `end`).

## Props

| 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. |

## Code

**React**
```tsx
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>
  )
}
```

**Vue**
```vue
<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>
```

**Flutter**
```dart
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

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/popover.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/popover.json
```

## 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".
