# Popover

A floating panel opened from a button, and the parts popouts are built from: a section label, a separator, a search field and a person row. Built on ui-sdk's Popover: Escape and an outside press close it, focus returns to the trigger, and it opens in the top layer.

- Beta: ready to use; its API can still change in a minor release.
- Category: Overlays

```tsx
import { Popover, PopoverTrigger, PopoverContent } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for a small panel tied to a control, like sharing an opportunity, where the rest of the page stays usable while it is open.
- Do: Name it with `PopoverTitle`, and close it from its own actions with `PopoverClose`. Focus returns to the trigger when it closes.
- Do: For a list of rows, pass `className="w-56 p-0"` and build it from `PopoutSearch`, `PopoutSectionLabel`, `PopoutSeparator` and `PopoutPersonRow`.
- Do: Give `PopoutSearch` an `aria-label`, like Search people. The placeholder is not a name.
- Do: Keep a custom row's corners smaller than the panel's, as `PopoutPersonRow` does, and put its selection tick on the right.
- Don't: Use it for a list of actions on a record. Use `DropdownMenu`, which adds arrow keys, typeahead and the menu role.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Open the popover from its trigger. |
| Tab | Moves through the popover in order; from the last element, moves to the element after the trigger. |
| Shift + Tab | From the first element, returns focus to the trigger. |
| Escape | Closes the popover and returns focus to the trigger. |

## Related

- [Dropdown Menu](./dropdown-menu.md)
- [Hover Card](./hover-card.md)
- [Tooltip](./tooltip.md)
- [Dialog](./dialog.md)

## Examples

What the examples import:

```tsx
import { Link2, UserPlus } from "lucide-react";
import { Button, PopoutPersonRow, PopoutSearch, PopoutSectionLabel, PopoutSeparator, Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const recent = [
  { name: "Ada Hartley", detail: "Client · ada@hartley.com", selected: true },
  { name: "Ben Okafor", detail: "Other side · ben@okafor.law" },
] as const;

const everyone = [
  { name: "Chloe Nguyen", detail: "Staff · Conveyancing" },
  { name: "Dev Patel", detail: "Staff · Family law" },
] as const;

function SharePanel() {
  return (
    <Popover>
      <PopoverTrigger
        render={
          <Button intent="outline" icon={<Link2 />}>
            Share
          </Button>
        }
      />
      <PopoverContent>
        <div className="flex flex-col gap-3">
          <div className="flex flex-col gap-1">
            <PopoverTitle>Share this opportunity</PopoverTitle>
            <PopoverDescription>
              Anyone at the firm with the link can open it.
            </PopoverDescription>
          </div>
          <div className="flex justify-end gap-2">
            <PopoverClose
              render={
                <Button intent="ghost" size="sm">
                  Cancel
                </Button>
              }
            />
            <PopoverClose render={<Button size="sm">Copy link</Button>} />
          </div>
        </div>
      </PopoverContent>
    </Popover>
  );
}
```

### Panel

A title, a description and actions. PopoverClose closes it from inside; focus goes back to Share.

```tsx
<SharePanel />
```

### Popout

A list of rows: a search field with a rule under it, quiet section labels, dividers between groups, and two-line person rows with a navy tick on the selected one. Pass className="w-70 p-0" to drop the panel's padding.

```tsx
<Popover>
  <PopoverTrigger
    render={
      <Button intent="outline" icon={<UserPlus />}>
        Assign
      </Button>
    }
  />
  <PopoverContent align="start" className="w-70 p-0">
    <PopoutSearch aria-label="Search people" />
    <div className="p-1">
      <PopoutSectionLabel>Recent</PopoutSectionLabel>
      {recent.map(person => (
        <PopoutPersonRow key={person.name} {...person} />
      ))}
      <PopoutSeparator />
      <PopoutSectionLabel>Everyone</PopoutSectionLabel>
      {everyone.map(person => (
        <PopoutPersonRow key={person.name} {...person} />
      ))}
    </div>
  </PopoverContent>
</Popover>
```

### Popout parts

Each part on its own: Section label (12/16, 450, muted), Separator (the divider colour, 4 px above and below), Search (36 px) and Person row (48 px; highlighted as data-highlighted).

```tsx
<div className="border-neutral-border bg-neutral-surface w-70 rounded-md border p-1">
  <PopoutSearch aria-label="Search people" />
  <PopoutSectionLabel>Recent</PopoutSectionLabel>
  <PopoutPersonRow
    name="Ada Hartley"
    detail="Client · ada@hartley.com"
  />
  <PopoutPersonRow
    name="Ben Okafor"
    detail="Other side · ben@okafor.law"
    data-highlighted=""
  />
  <PopoutSeparator />
  <PopoutPersonRow
    name="Chloe Nguyen"
    detail="Staff · Conveyancing"
    selected
  />
</div>
```

### Placement

Below the trigger and centred by default; it flips when there isn't room and grows out of the side it opens from.

```tsx
<div className="flex flex-wrap gap-3 py-6">
  {(["top", "right", "bottom", "left"] as const).map(side => (
    <Popover key={side}>
      <PopoverTrigger
        render={
          <Button intent="outline" className="capitalize">
            {side}
          </Button>
        }
      />
      <PopoverContent side={side} className="w-56">
        <PopoverDescription>Opens {side}.</PopoverDescription>
      </PopoverContent>
    </Popover>
  ))}
</div>
```

## Props

Popover also takes ui-sdk's options (open, defaultOpen, onOpenChange, modal, openOnHover, delay, presentation, controller). PopoverContent takes its position and focus props (side, alignOffset, collisionPadding, anchor, initialFocus, finalFocus, keepMounted), and PopoverTrigger and PopoverClose take render.

### Popover

No props of its own.

### PopoverContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `align` | `unknown` | `"center"` | How it lines up along that side: start, center or end. |
| `sideOffset` | `unknown` | `4` | The gap between it and what it opens from, in pixels. |

### PopoverTitle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### PopoverDescription

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### PopoutSectionLabel

No props of its own.

### PopoutSeparator

No props of its own.

### PopoutSearch

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `aria-label` (required) | `string` |  | Names the field for screen readers; the placeholder is not a name. |
| `placeholder` | `unknown` | `"Search…"` | Grey hint text while it's empty. Never a replacement for a label. |

### PopoutPersonRow

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name` (required) | `string` |  | The person's name, on the row's first line. |
| `detail` | `string` |  | The grey second line, like "Client · ada@hartley.com". |
| `initials` | `string` |  | Two letters for the avatar. From the name when left out. |
| `selected` | `boolean` | `false` | Shows the navy tick on the right. |
