# Popover

Edit or explore something beside its trigger.

A popover keeps a small task close to the thing it belongs to. Put fields, buttons, or other interactive content inside; it handles placement, focus, and dismissal.

```angular-ts title="basic.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover>
      <button uiPopoverTrigger>Share</button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>Share this document</h2>
        <p uiPopoverDescription>Anyone with the link can view it.</p>
        <div uiField>
          <label uiFieldLabel>Link</label>
          <input uiInput readonly defaultValue="acme.app/d/q3-roadmap" />
        </div>
        <div data-slot="row">
          <button uiPopoverClose>Cancel</button>
          <button uiPopoverClose data-variant="solid">Copy Link</button>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

Press Share to open the popover, then close it with Cancel, Copy Link, Escape, or a press outside. Focus returns to Share.

## Installation

```bash
npm install @ui-sdk/angular @ui-sdk/core
```

## Composition

Use the following composition to build Popover:

```text
uiPopover
├── uiPopoverTrigger
└── uiPopoverContent
    ├── uiPopoverArrow
    ├── uiPopoverTitle
    ├── uiPopoverDescription
    └── uiPopoverClose
```

The content has the dialog role. Its title names it and its description adds context. The arrow is optional, and a popover can have several Close parts. The trigger can live inside the popover or [connect from elsewhere](#triggers-outside-the-popover).

## Usage

Import the parts and put them together:

```ts
import { Component } from "@angular/core"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  selector: "app-example",
  imports: [
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover>
      <button uiPopoverTrigger>Share</button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>Share this document</h2>
        <p uiPopoverDescription>Anyone with the link can view it.</p>
        <button uiPopoverClose>Done</button>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

## Forms

An ordinary form can save a value and then close the popover. Focus starts on the first field and returns to the trigger when the task finishes. A form with `method="dialog"` closes on submission and returns its submit button's value; the [row editor](#triggers-outside-the-popover) shows that version. Inside another form, set `container` so the popover's form doesn't nest in it.

```angular-ts title="form.ts"
import { Component, signal } from "@angular/core"
import { useLog } from "./log"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover [(open)]="open">
      <button uiPopoverTrigger>Edit Profile</button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>Edit profile</h2>
        <p uiPopoverDescription>Your name shows on your posts.</p>
        <form data-slot="stack" (submit)="onSubmit($event)">
          <div uiField>
            <label uiFieldLabel>Name</label>
            <input uiInput name="name" required defaultValue="Hollis Grant" />
          </div>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button type="submit" data-variant="solid">Save</button>
          </div>
        </form>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly log = useLog()

  readonly open = signal(false)

  onSubmit(event: SubmitEvent) {
    event.preventDefault()
    this.log(
      `Saved ${new FormData(event.currentTarget as HTMLFormElement).get("name")}`
    )
    this.open.set(false)
  }
}

export { Example }
```

Open Edit Profile, change the name, and press Save. The popover closes and the console logs the saved name.

## Keep It Open While Editing

Set `dismissible` to false while there is unsaved work. Escape and outside presses then keep the popover open and report `(dismissAttempt)`, so you can ask whether to discard it. Focus leaving is refused quietly. The trigger, Close parts, and controller can still close it.

```angular-ts title="draft.ts"
import { Component, ElementRef, signal, viewChild } from "@angular/core"
import { useLog } from "./log"
import { Field, FieldControl, FieldLabel } from "@ui-sdk/angular/field"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
  type PopoverDismissReason,
} from "@ui-sdk/angular/popover"
import { type DismissAttemptDetails } from "@ui-sdk/core"

@Component({
  imports: [
    Field,
    FieldControl,
    FieldLabel,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container
      uiPopover
      [open]="open()"
      (openChange)="$event ? open.set(true) : close()"
      [dismissible]="note() === ''"
      (dismissAttempt)="onDismissAttempt($event)"
    >
      <button uiPopoverTrigger>Add Note</button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>Add a note</h2>
        <p uiPopoverDescription>Only your team can see it.</p>
        <div uiField>
          <label uiFieldLabel>Note</label>
          <textarea
            uiFieldControl
            [value]="note()"
            (input)="note.set(field.value)"
            #field
            placeholder="Call the printer about the proofs."
          ></textarea>
        </div>
        @if (asking()) {
          <div data-slot="row" role="alert">
            Discard your note?
            <div data-slot="row">
              <button type="button" data-size="sm" (click)="keepEditing()">
                Keep Editing
              </button>
              <button
                type="button"
                data-size="sm"
                data-variant="solid"
                (click)="discard()"
              >
                Discard
              </button>
            </div>
          </div>
        } @else {
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button type="button" data-variant="solid" (click)="save()">
              Save
            </button>
          </div>
        }
      </div>
    </ng-container>
  `,
})
class Example {
  readonly log = useLog()

  readonly open = signal(false)

  readonly note = signal("")

  readonly asking = signal(false)

  readonly field = viewChild<ElementRef<HTMLTextAreaElement>>("field")

  close() {
    this.open.set(false)
    this.note.set("")
    this.asking.set(false)
  }

  onDismissAttempt(details: DismissAttemptDetails<PopoverDismissReason>) {
    this.log(`Kept open (${details.reason})`)
    this.asking.set(true)
  }

  keepEditing() {
    this.asking.set(false)
    this.field()?.nativeElement?.focus()
  }

  discard() {
    this.log("Discarded the note")
    this.close()
  }

  save() {
    this.log(this.note() ? "Saved the note" : "Nothing to save")
    this.close()
  }
}

export { Example }
```

Open Add Note, type something, then press Escape or click outside. Keep Editing returns to the field; Discard closes the popover and clears the note.

## Placement

`side` chooses an edge of the trigger, `bottom` by default, and `align` lines the popover up with its start, center, or end. Start and end follow text direction. The popover flips or shifts when the requested position doesn't fit, and `data-side` and `data-align` report where it landed. The [popup guide](/docs/angular/popups#place-the-content) covers the shared positioning options.

```angular-ts title="placement.ts"
import { Component, signal } from "@angular/core"
import { LucideCheck, LucideChevronDown } from "@lucide/angular"
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from "@ui-sdk/angular/select"

type Side = "top" | "right" | "bottom" | "left"

type Align = "start" | "center" | "end"

@Component({
  imports: [
    Popover,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    Select,
    SelectContent,
    SelectItem,
    SelectItemIndicator,
    SelectLabel,
    SelectTrigger,
    SelectValue,
    LucideCheck,
    LucideChevronDown,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <ng-container
          uiSelect
          [items]="sides"
          [value]="side()"
          (beforeValueChange)="$event.value && side.set($event.value)"
        >
          <div uiSelectLabel>Side</div>
          <button uiSelectTrigger>
            <span uiSelectValue></span>
            <svg lucideChevronDown></svg>
          </button>
          <div *uiSelectContent>
            @for (option of sides; track option.value) {
              <div uiSelectItem [value]="option.value">
                {{ option.label }}
                <span *uiSelectItemIndicator>
                  <svg lucideCheck></svg>
                </span>
              </div>
            }
          </div>
        </ng-container>
        <ng-container
          uiSelect
          [items]="aligns"
          [value]="align()"
          (beforeValueChange)="$event.value && align.set($event.value)"
        >
          <div uiSelectLabel>Align</div>
          <button uiSelectTrigger>
            <span uiSelectValue></span>
            <svg lucideChevronDown></svg>
          </button>
          <div *uiSelectContent>
            @for (option of aligns; track option.value) {
              <div uiSelectItem [value]="option.value">
                {{ option.label }}
                <span *uiSelectItemIndicator>
                  <svg lucideCheck></svg>
                </span>
              </div>
            }
          </div>
        </ng-container>
      </div>
      <ng-container uiPopover>
        <button uiPopoverTrigger>Delivery</button>
        <div
          *uiPopoverContent="{ side: side(), align: align(), sideOffset: 8 }"
        >
          <h2 uiPopoverTitle>Delivery window</h2>
          <p uiPopoverDescription>Arrives Tuesday between 9 AM and noon.</p>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly sides = [
    { value: "top", label: "Top" },
    { value: "right", label: "Right" },
    { value: "bottom", label: "Bottom" },
    { value: "left", label: "Left" },
  ]

  readonly aligns = [
    { value: "start", label: "Start" },
    { value: "center", label: "Center" },
    { value: "end", label: "End" },
  ]

  readonly side = signal<Side>("bottom")

  readonly align = signal<Align>("center")
}

export { Example }
```

Choose a side and an alignment, then open Delivery. Near a window edge, the popover flips or shifts to stay visible.

## Offsets

`sideOffset` is the gap to the trigger, 4 pixels by default. `alignOffset` shifts the popover along the trigger's edge, and `collisionPadding` is the space kept from the edges of the window.

```angular-ts title="offsets.ts"
import { Component, signal } from "@angular/core"
import { LucideCheck, LucideChevronDown } from "@lucide/angular"
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectLabel,
  SelectTrigger,
  SelectValue,
  type SelectValueChange,
} from "@ui-sdk/angular/select"

const choices = {
  sideOffset: { label: "Side offset", values: ["4", "8", "16", "24"] },
  alignOffset: { label: "Align offset", values: ["-16", "0", "16"] },
  collisionPadding: { label: "Collision padding", values: ["8", "24", "48"] },
}

type Name = keyof typeof choices

@Component({
  imports: [
    Popover,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    Select,
    SelectContent,
    SelectItem,
    SelectItemIndicator,
    SelectLabel,
    SelectTrigger,
    SelectValue,
    LucideCheck,
    LucideChevronDown,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        @for (name of names; track name) {
          <ng-container
            uiSelect
            [items]="choices[name].values"
            [value]="offsets()[name]"
            (beforeValueChange)="setOffset(name, $event)"
          >
            <div uiSelectLabel>{{ choices[name].label }}</div>
            <button uiSelectTrigger>
              <span uiSelectValue></span>
              <svg lucideChevronDown></svg>
            </button>
            <div *uiSelectContent>
              @for (value of choices[name].values; track value) {
                <div uiSelectItem [value]="value">
                  {{ value }}px
                  <span *uiSelectItemIndicator>
                    <svg lucideCheck></svg>
                  </span>
                </div>
              }
            </div>
          </ng-container>
        }
      </div>
      <ng-container uiPopover>
        <button uiPopoverTrigger>Delivery</button>
        <div
          *uiPopoverContent="{
            align: 'start',
            sideOffset: +offsets().sideOffset,
            alignOffset: +offsets().alignOffset,
            collisionPadding: +offsets().collisionPadding,
          }"
        >
          <h2 uiPopoverTitle>Delivery window</h2>
          <p uiPopoverDescription>Arrives Tuesday between 9 AM and noon.</p>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly choices = choices
  readonly names = Object.keys(choices) as Name[]
  readonly offsets = signal<Record<Name, string>>({
    sideOffset: "8",
    alignOffset: "0",
    collisionPadding: "8",
  })

  setOffset(name: Name, change: SelectValueChange) {
    const next = change.value
    if (next) {
      this.offsets.update((offsets) => ({ ...offsets, [name]: next }))
    }
  }
}

export { Example }
```

Change the offsets and the padding, then open Delivery. The popover moves away from the trigger and along it.

## Arrow

`uiPopoverArrow` follows the side the popover actually uses, including after a flip, and gets the same `data-side`. `arrowPadding` keeps it away from the corners; `data-arrow-clamped` tells you when it can't point at the middle of the trigger. This example cancels dismissal when you press its side buttons, so the open arrow can move.

```angular-ts title="arrow.ts"
import { Component, ElementRef, signal, viewChild } from "@angular/core"
import { LucideCircleQuestionMark } from "@lucide/angular"
import {
  Popover,
  PopoverArrow,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
  type PopoverOpenChange,
} from "@ui-sdk/angular/popover"

const sides = [
  { value: "top", label: "Top" },
  { value: "right", label: "Right" },
  { value: "bottom", label: "Bottom" },
  { value: "left", label: "Left" },
] as const

type Side = (typeof sides)[number]["value"]

@Component({
  imports: [
    Popover,
    PopoverArrow,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    LucideCircleQuestionMark,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls" role="group" aria-label="Side" #controls>
        @for (option of sides; track option.value) {
          <button
            type="button"
            data-size="sm"
            [attr.aria-pressed]="side() === option.value"
            (click)="side.set(option.value)"
          >
            {{ option.label }}
          </button>
        }
      </div>
      <ng-container
        uiPopover
        [open]="open()"
        (beforeOpenChange)="onOpenChange($event)"
      >
        <button uiPopoverTrigger aria-label="Help">
          <svg lucideCircleQuestionMark></svg>
        </button>
        <div
          *uiPopoverContent="{ side: side(), sideOffset: 10, arrowPadding: 12 }"
        >
          <div uiPopoverArrow></div>
          <h2 uiPopoverTitle>Keyboard shortcuts</h2>
          <p uiPopoverDescription>Press ? anywhere to see them all.</p>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly sides = sides

  readonly open = signal(false)

  readonly side = signal<Side>("bottom")

  readonly controls = viewChild<ElementRef<HTMLDivElement>>("controls")

  onOpenChange(change: PopoverOpenChange) {
    const target = change.event?.target
    const inControls =
      target instanceof Node && this.controls()?.nativeElement?.contains(target)
    if (inControls && change.reason !== "escape-key") {
      return change.cancel()
    }
    this.open.set(change.value)
  }
}

export { Example }
```

Open Help, then press Top, Right, Bottom, or Left. The popover stays open while it and its arrow move to that side.

Keep overflow visible around an arrow that extends outside the panel. If the body needs to scroll, put scrolling on an inner element. You can also draw an arrow with `::before`, using `data-side` and `--arrow-offset` to position it.

## Anchor

Set `anchor` to position against something other than the trigger. It accepts an element, a selector, a point such as `{ x, y }`, or an object with `getBoundingClientRect()`, such as a text range. The position is read again as the anchor moves. If the anchor stops rendering while the popover is open, like a trigger a breakpoint hides, the popover closes with reason `anchor-hidden`.

```angular-ts title="anchor.ts"
import { Component } from "@angular/core"
import { LucideCheck, LucideSlidersHorizontal } from "@lucide/angular"
import { Checkbox, CheckboxIndicator } from "@ui-sdk/angular/checkbox"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Checkbox,
    CheckboxIndicator,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    LucideCheck,
    LucideSlidersHorizontal,
  ],
  template: `
    <div data-slot="row">
      <input
        #anchor
        type="search"
        placeholder="Search files…"
        aria-label="Search files"
      />
      <ng-container uiPopover>
        <button uiPopoverTrigger aria-label="Search filters">
          <svg lucideSlidersHorizontal></svg>
        </button>
        <div
          *uiPopoverContent="{ anchor: anchor, align: 'start', sideOffset: 8 }"
        >
          <h2 uiPopoverTitle>Filters</h2>
          <p uiPopoverDescription>Show only these kinds of files.</p>
          <div data-slot="stack">
            @for (type of types; track type.label) {
              <label data-slot="label">
                <button uiCheckbox [defaultChecked]="type.checked">
                  <span uiCheckboxIndicator>
                    <svg lucideCheck></svg>
                  </span>
                </button>
                {{ type.label }}
              </label>
            }
          </div>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button uiPopoverClose data-variant="solid">Apply</button>
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly types = [
    { label: "Documents", checked: true },
    { label: "Images", checked: false },
    { label: "Shared with me", checked: true },
  ]
}

export { Example }
```

Press the filters button. The popover lines up with the search field instead of the small button beside it.

## Modal

`modal` controls how the popover shares the page:

- `false`, the default, leaves the page usable, and focus leaving the popover closes it.
- `"trap-focus"` keeps Tab inside while the page can still scroll and receive clicks.
- `true` also makes the rest of the page inert and locks scrolling.

```angular-ts title="modal.ts"
import { Component, computed, signal } from "@angular/core"
import { LucideCheck, LucideChevronDown } from "@lucide/angular"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from "@ui-sdk/angular/select"
import { Textarea } from "@ui-sdk/angular/textarea"

type Mode = "false" | "trap-focus" | "true"

@Component({
  imports: [
    Field,
    FieldLabel,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    Select,
    SelectContent,
    SelectItem,
    SelectItemIndicator,
    SelectLabel,
    SelectTrigger,
    SelectValue,
    Textarea,
    LucideCheck,
    LucideChevronDown,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <ng-container
          uiSelect
          [items]="modes"
          [value]="mode()"
          (beforeValueChange)="$event.value && mode.set($event.value)"
        >
          <div uiSelectLabel>Modal</div>
          <button uiSelectTrigger>
            <span uiSelectValue></span>
            <svg lucideChevronDown></svg>
          </button>
          <div *uiSelectContent>
            @for (option of modes; track option.value) {
              <div uiSelectItem [value]="option.value">
                {{ option.label }}
                <span *uiSelectItemIndicator>
                  <svg lucideCheck></svg>
                </span>
              </div>
            }
          </div>
        </ng-container>
      </div>
      <ng-container uiPopover [modal]="modal()">
        <button uiPopoverTrigger>Add Comment</button>
        <div *uiPopoverContent>
          <h2 uiPopoverTitle>Add a comment</h2>
          <p uiPopoverDescription>{{ notes[mode()] }}</p>
          <div uiField>
            <label uiFieldLabel>Comment</label>
            <textarea uiTextarea defaultValue="Looks good to me."></textarea>
          </div>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button uiPopoverClose data-variant="solid">Comment</button>
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly modes = [
    { value: "false", label: "Non-modal" },
    { value: "trap-focus", label: "Trap focus" },
    { value: "true", label: "Modal" },
  ]

  readonly notes = {
    false: "Tab can leave, and focus leaving closes it.",
    "trap-focus": "Tab stays inside. The page still scrolls and takes clicks.",
    true: "Tab stays inside. The page is inert and doesn't scroll.",
  }

  readonly mode = signal<Mode>("false")

  readonly modal = computed(() =>
    this.mode() === "true"
      ? true
      : this.mode() === "false"
        ? false
        : "trap-focus"
  )
}

export { Example }
```

Choose a mode, open Add Comment, and try Tab or clicking the page.

## Focus

Use `initialFocus` to choose the first focused element, or `"none"` to leave focus where it is. `finalFocus` controls where focus returns. Opening on hover leaves focus alone; opening with touch focuses the panel itself so no on-screen keyboard appears, unless you set `initialFocus`. See [popup focus](/docs/angular/popups#focus) for the shared focus rules.

```angular-ts title="focus.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <div data-slot="row">
      <ng-container uiPopover>
        <button uiPopoverTrigger>Rename</button>
        <div *uiPopoverContent>
          <h2 uiPopoverTitle>Rename file</h2>
          <p uiPopoverDescription>Focus starts in the first field.</p>
          <div uiField>
            <label uiFieldLabel>Name</label>
            <input uiInput defaultValue="Q3 roadmap.pdf" />
          </div>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button uiPopoverClose data-variant="solid">Save</button>
          </div>
        </div>
      </ng-container>
      <ng-container uiPopover>
        <button uiPopoverTrigger>Publish</button>
        <div *uiPopoverContent="{ initialFocus: '[data-autofocus]' }">
          <h2 uiPopoverTitle>Publish changes?</h2>
          <p uiPopoverDescription>Focus starts on Publish, not Cancel.</p>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button uiPopoverClose data-autofocus="" data-variant="solid">
              Publish
            </button>
          </div>
        </div>
      </ng-container>
      <ng-container uiPopover>
        <button uiPopoverTrigger>Status</button>
        <div *uiPopoverContent="{ initialFocus: 'none', finalFocus: 'none' }">
          <h2 uiPopoverTitle>All systems normal</h2>
          <p uiPopoverDescription>Focus stays on the trigger.</p>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {}

export { Example }
```

Open each one: Rename focuses its field, Publish focuses its Publish button, and Status leaves focus on the trigger.

## Open on Hover

`openOnHover` adds pointer opening while keeping click, keyboard, and touch activation. `delay` and `closeDelay` control the pause before opening and closing. You can cross the gap into the content and interact with it. Another popover or hover card opening on hover closes it, unless that one is inside it, so a row of hover triggers shows one at a time.

```angular-ts title="hover.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
  Popover,
  PopoverArrow,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Popover,
    PopoverArrow,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover openOnHover [delay]="200" [closeDelay]="150">
      <button uiPopoverTrigger>@kofi</button>
      <div *uiPopoverContent="{ sideOffset: 8 }">
        <div uiPopoverArrow></div>
        <h2 uiPopoverTitle>Kofi Mensah</h2>
        <p uiPopoverDescription>Engineering manager, platform team.</p>
        <div data-slot="row">
          <button
            type="button"
            data-size="sm"
            data-variant="solid"
            (click)="log('Followed @kofi')"
          >
            Follow
          </button>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly log = useLog()
}

export { Example }
```

Hover @kofi, then move into the popover and press Follow. You can also open it by pressing the trigger.

## Controlled

Use `[(open)]` to keep the popover's state in your component. Cancel a proposed change with `$event.cancel()` in `(beforeOpenChange)`. See [state and events](/docs/angular/state-and-events) for the common change contract.

```angular-ts title="controlled.ts"
import { Component, ElementRef, signal, viewChild } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import { Checkbox, CheckboxIndicator } from "@ui-sdk/angular/checkbox"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
  type PopoverOpenChange,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Checkbox,
    CheckboxIndicator,
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
    LucideCheck,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls" #controls>
        <label data-slot="label">
          <button
            uiCheckbox
            [checked]="open()"
            (beforeCheckedChange)="open.set($event.value === true)"
          >
            <span uiCheckboxIndicator>
              <svg lucideCheck></svg>
            </span>
          </button>
          Open
        </label>
      </div>
      <ng-container
        uiPopover
        [(open)]="open"
        (beforeOpenChange)="onOpenChange($event)"
      >
        <button uiPopoverTrigger>Set Status</button>
        <div *uiPopoverContent>
          <h2 uiPopoverTitle>Set a status</h2>
          <p uiPopoverDescription>Your team sees it next to your name.</p>
          <div uiField>
            <label uiFieldLabel>Status</label>
            <input uiInput defaultValue="In a meeting" />
          </div>
          <div data-slot="row">
            <button uiPopoverClose>Cancel</button>
            <button uiPopoverClose data-variant="solid">Save</button>
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly log = useLog()

  readonly open = signal(false)

  readonly controls = viewChild<ElementRef<HTMLDivElement>>("controls")

  onOpenChange(change: PopoverOpenChange) {
    const target = change.event?.target
    const inControls =
      target instanceof Node && this.controls()?.nativeElement?.contains(target)
    if (inControls && change.reason !== "escape-key") {
      return change.cancel()
    }
    this.log(`${change.value ? "Opened" : "Closed"} (${change.reason})`)
  }
}

export { Example }
```

Check Open or press Set Status, then close the popover. The console logs each change and its reason.

## Keyboard Shortcut

Set a trigger's `shortcut` to toggle the popover from the keyboard. `mod+i` means Command+I on Apple platforms and Control+I elsewhere. The Shortcut part displays the platform's keys, and the trigger advertises them through `aria-keyshortcuts`.

```angular-ts title="shortcut.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverShortcut,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverShortcut,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover>
      <button uiPopoverTrigger shortcut="mod+i">
        Invite
        <kbd uiPopoverShortcut></kbd>
      </button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>Invite people</h2>
        <p uiPopoverDescription>They'll get an email with a link to join.</p>
        <div uiField>
          <label uiFieldLabel>Email</label>
          <input uiInput type="email" placeholder="wren@example.com" />
        </div>
        <div data-slot="row">
          <button uiPopoverClose>Cancel</button>
          <button uiPopoverClose data-variant="solid">Send Invite</button>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

Press Command+I or Control+I to open Invite. Press the same shortcut again, or Escape, to close it.

## Triggers Outside the Popover

Connect the triggers and popover to one `createPopoverController<Member>()`. Each trigger passes its row as `payload`; the content reads the active row from its state. Only the active trigger is expanded and receives focus back. Opening from another row updates the same panel, so one editor can serve the whole list.

`controller.open({ payload, anchor })` opens it from code and returns a promise with the closing reason and any `returnValue`. The payload stays available during the exit animation. See [controllers](/docs/angular/controllers) for the shared pattern.

```angular-ts title="payload.ts"
import { Component, computed, signal } from "@angular/core"
import { useLog } from "./log"
import { Field, FieldControl, FieldLabel } from "@ui-sdk/angular/field"
import {
  createPopoverController,
  Popover,
  PopoverContent,
  type PopoverContentState,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
  type PopoverPayloadChange,
} from "@ui-sdk/angular/popover"

type Member = { name: string; role: string }

@Component({
  imports: [
    Field,
    FieldControl,
    FieldLabel,
    Popover,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <button type="button" (click)="editNewestMember($event)">
          Edit Newest Member
        </button>
      </div>
      <ul data-slot="list">
        @for (member of members(); track member.name) {
          <li data-slot="row">
            {{ member.name }}
            <span data-slot="hint">{{ member.role }}</span>
            <button
              uiPopoverTrigger
              [controller]="popover"
              [payload]="member"
              [disabled]="member.role === 'Owner'"
              data-size="sm"
              data-variant="ghost"
              [attr.aria-label]="\`Edit \${member.name}\`"
            >
              Edit
            </button>
          </li>
        }
      </ul>
      <ng-container
        uiPopover
        [controller]="popover"
        (beforePayloadChange)="onPayloadChange($event)"
      >
        <div *uiPopoverContent="{ align: 'end', sideOffset: 8 }; let content">
          <h2 uiPopoverTitle>{{ payloadOf(content)?.name }}</h2>
          <p uiPopoverDescription>Roles decide what they can change.</p>
          <form
            data-slot="stack"
            method="dialog"
            (submit)="save($event, payloadOf(content))"
          >
            <div uiField>
              <label uiFieldLabel>Role</label>
              <select uiFieldControl name="role">
                @for (role of roles; track role) {
                  <option [selected]="role === payloadOf(content)?.role">
                    {{ role }}
                  </option>
                }
              </select>
            </div>
            <div data-slot="row">
              <button type="submit" value="cancel" formnovalidate>
                Cancel
              </button>
              <button type="submit" value="save" data-variant="solid">
                Save
              </button>
            </div>
          </form>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly roles = ["Admin", "Editor", "Viewer"]

  readonly log = useLog()

  readonly popover = createPopoverController<Member>()

  readonly members = signal<Member[]>([
    { name: "Hollis Grant", role: "Owner" },
    { name: "Inès Moreau", role: "Editor" },
    { name: "Kofi Mensah", role: "Viewer" },
    { name: "Wren Takahashi", role: "Viewer" },
  ])

  readonly newest = computed(() => this.members()[this.members().length - 1])

  save(event: SubmitEvent, member: Member | undefined) {
    if ((event.submitter as HTMLButtonElement).value !== "save" || !member) {
      return
    }
    const role = String(
      new FormData(event.currentTarget as HTMLFormElement).get("role")
    )
    this.members.set(
      this.members().map((entry) =>
        entry.name === member.name ? { ...entry, role } : entry
      )
    )
  }

  payloadOf(state: { payload?: unknown }) {
    return state.payload as Member | undefined
  }

  async editNewestMember(event: MouseEvent) {
    const result = await this.popover.open({
      payload: this.newest(),
      anchor: event.currentTarget as HTMLElement,
    })
    this.log(
      `Closed (${result.reason}), returned ${result.returnValue ?? "nothing"}`
    )
  }

  onPayloadChange(change: PopoverPayloadChange) {
    const member = change.value as Member | undefined
    if (member) {
      this.log(`Editing ${member.name}`)
    }
  }
}

export { Example }
```

Edit Inès Moreau or Kofi Mensah and save a new role. The owner can't be edited. Edit Newest Member opens the same editor from code, and the console logs how it closed.

## Animation

The content has `data-starting-style` while it opens and `data-ending-style` while it closes. Transition from those states, and the popover stays mounted until the exit finishes. `(openChangeComplete)` runs after the transition, and `keepMounted` keeps the closed content in the page, hidden. See [styling and animation](/docs/angular/styling-and-animation) for the common lifecycle.

```angular-ts title="animation.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container
      uiPopover
      (beforeOpenChange)="log($event.value ? 'Opening' : 'Closing')"
      (openChangeComplete)="log($event ? 'Open' : 'Closed')"
    >
      <button uiPopoverTrigger>What's New</button>
      <div *uiPopoverContent="{ keepMounted: true }">
        <h2 uiPopoverTitle>What's new</h2>
        <p uiPopoverDescription>Comments now support threads and reactions.</p>
        <div data-slot="row">
          <button uiPopoverClose data-variant="solid">Got It</button>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly log = useLog()
}

export { Example }
```

Open What's New, then press Got It. The console logs Opening, Open, Closing, and Closed.

## Presentation

`presentation="sheet"` shows the task as a sheet; `"auto"` chooses a sheet on small touch screens each time it opens. A sheet is modal by default and can be swiped down to dismiss. If dismissal is disabled, it springs back and reports the attempt.

Style `data-presentation` for both layouts. The sheet manages its own position and movement, so leave its translation alone and avoid the floating panel's fixed width. `--sheet-backdrop` sets the dim behind it.

```angular-ts title="presentation.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Input } from "@ui-sdk/angular/input"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Field,
    FieldLabel,
    Input,
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover presentation="sheet">
      <button uiPopoverTrigger>Add Reminder</button>
      <div *uiPopoverContent>
        <h2 uiPopoverTitle>New reminder</h2>
        <p uiPopoverDescription>We'll notify you at the time you pick.</p>
        <div uiField>
          <label uiFieldLabel>Remind me to</label>
          <input uiInput defaultValue="Send the Q3 roadmap" />
        </div>
        <div data-slot="row">
          <button uiPopoverClose>Cancel</button>
          <button uiPopoverClose data-variant="solid">Save</button>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

Open Add Reminder as a sheet. Dismiss it with Cancel, Save, Escape, the dimmed area, or a downward swipe on a touch screen.

## Container

Popovers render in place by default and use the browser's top layer. `container` moves their DOM to another element while keyboard order still follows the trigger. See [popups](/docs/angular/popups#mounting-and-containers) for the shared container behavior.

```ts
import { Component } from "@angular/core"
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  selector: "app-example",
  imports: [Popover, PopoverContent, PopoverTrigger],
  template: `
    <div #container></div>
    <ng-container uiPopover>
      <button uiPopoverTrigger>Details</button>
      <div *uiPopoverContent="{ container: container }">...</div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

## In Place

A popover opens above the page. Set `inline` on the content to render it where it is, inside its parent's layout and stacking, like a panel that opens out of a corner widget. Your CSS places it, so `side`, `align` and the offsets don't apply.

```angular-ts title="inline.ts"
import { Component } from "@angular/core"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <div data-slot="popover-frame">
      <div data-slot="popover-corner">
        <ng-container uiPopover>
          <button uiPopoverTrigger>Feedback</button>
          <div *uiPopoverContent="{ inline: true }">
            <h2 uiPopoverTitle>Send feedback</h2>
            <p uiPopoverDescription>
              The panel sits in the corner box, above its trigger.
            </p>
            <div data-slot="row">
              <button uiPopoverClose>Close</button>
            </div>
          </div>
        </ng-container>
      </div>
    </div>
  `,
})
class Example {}

export { Example }
```

Open Feedback. The panel opens above the button, inside the corner box.

## Custom Rendering

Each directive goes on an element you write. Read a part's state from a template reference, like `#trigger="uiPopoverTrigger"` and then `trigger.state().open`, and the content's from `*uiPopoverContent="let content"`. The content's state has its payload too, as the row editor shows.

```angular-ts title="custom-rendering.ts"
import { Component } from "@angular/core"
import {
  Popover,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverShortcut,
  PopoverTitle,
  PopoverTrigger,
} from "@ui-sdk/angular/popover"

@Component({
  imports: [
    Popover,
    PopoverClose,
    PopoverContent,
    PopoverDescription,
    PopoverShortcut,
    PopoverTitle,
    PopoverTrigger,
  ],
  template: `
    <ng-container uiPopover>
      <button
        uiPopoverTrigger
        #popoverTrigger="uiPopoverTrigger"
        shortcut="mod+u"
      >
        {{ popoverTrigger.state().open ? "Hide Updates" : "Show Updates" }}
        <kbd uiPopoverShortcut #popoverShortcut="uiPopoverShortcut">{{
          popoverShortcut.state().text
        }}</kbd>
      </button>
      <div *uiPopoverContent>
        <h3 uiPopoverTitle>Updates</h3>
        <p uiPopoverDescription>Version 2.4 adds threaded comments.</p>
        <a uiPopoverClose href="#">Read the Changelog</a>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

Open Show Updates. The trigger's label comes from its state, the title renders as an h3, and Close renders as a link.

## Styling

Use `data-open` on the trigger to mark it while its popover shows, and `data-side` and `data-align` to style the content and arrow for where they landed. Put `transform-origin: var(--transform-origin)` on the content so a scale animation starts from the trigger.

Each part has a `data-slot`, such as `popover-content`, and its state attributes are listed under [Data Attributes](#data-attributes).

### PopoverContent
- `--anchor-width`: Width of the anchor, usually the trigger. Use it to match widths.
- `--anchor-height`: Height of the anchor.
- `--available-width`: Space beside the popup, up to the viewport edge. Not inherited either.
- `--available-height`: Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like `[--list-height:var(--available-height)]`, and reads `max-h-(--list-height)`. The first popup registers both names for the whole page with `CSS.registerProperty`, so they don't inherit anywhere. A page that needs them to inherit calls it first, with `inherits: true`. An `@property` rule can't, since a registration in script wins.
- `--transform-origin`: The point on the anchor the popup opens from. Use it to scale from the right place.
- `--arrow-offset`: Where the anchor's center falls along the popup's edge, kept `arrowPadding` from the corners. Position a ::before arrow with it.
- `--drawer-progress`: While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
- `--drawer-dim`: While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
- `--drawer-expand`: While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
- `--drawer-stack`: While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
- `--sheet-backdrop`: Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

### Viewport
- `--keyboard-inset`: While it presents as a sheet: how many pixels of the page the on-screen keyboard covers, 0 without one.
- `--visual-viewport-width`: While it presents as a sheet: the width of the part of the page you can see.
- `--visual-viewport-height`: While it presents as a sheet: the height of the part of the page you can see, above the keyboard.
- `--visual-viewport-top`: While it presents as a sheet: how far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.

## Data Attributes

`uiPopoverTitle`, `uiPopoverDescription` and `uiPopoverClose` have no state attributes.

### PopoverTrigger
`[data-slot="popover-trigger"]`

- `data-closed`: Present while the popover is closed, including while it animates out.
- `data-disabled`: Present when the trigger is disabled.
- `data-open`: Present while the popover is open. On a trigger, while it's open from that trigger.

### PopoverContent
`[data-slot="popover-content"]`

- `data-closed`: Present while the popover is closed, including while it animates out.
- `data-presentation` (`popover`, `sheet`): How the popover presents this time it's open.
- `data-open`: Present while the popover is open. On a trigger, while it's open from that trigger.
- `data-starting-style`: Present for the first frame. Style the state you animate from.
- `data-ending-style`: Present while the popover animates out. Style the state you animate to.
- `data-side` (`top`, `right`, `bottom`, `left`): Where the popover ended up, after flipping away from edges. Set on the arrow too.
- `data-align` (`start`, `center`, `end`): How the popover lines up with its trigger.

### PopoverArrow
`[data-slot="popover-arrow"]`

- `data-closed`: Present while the popover is closed, including while it animates out.
- `data-open`: Present while the popover is open. On a trigger, while it's open from that trigger.
- `data-side` (`top`, `right`, `bottom`, `left`): Where the popover ended up, after flipping away from edges. Set on the arrow too.
- `data-align` (`start`, `center`, `end`): How the popover lines up with its trigger.
- `data-arrow-clamped`: Present on the arrow when it stops short of the middle of the trigger, held back by `arrowPadding`.

## API Reference

Each option below is an input on the directive, and each callback an output. A change callback is two outputs: `(beforeOpenChange)`, with the details and `cancel()`, then `(openChange)` with the new value alone. Bind `open` with `[(open)]`.

### Popover

- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- `open?` (`boolean`): Whether the popover is open. Pass it to control the popover.
- `defaultOpen?` (`boolean`): Whether the popover starts open, when uncontrolled.
- `(beforeOpenChange)`: Runs when the popover wants to open or close. `details.reason` says why, and `details.cancel()` stops it.
- `(openChangeComplete)`: Runs once the popover has finished opening or closing, after any animation.
- `(beforePayloadChange)`: Runs when the payload the content shows changes: a trigger with another payload opens the popover, or takes the open popover over, which fires no `(beforeOpenChange)`, and so does a controller's `open({ payload })` on the open popover. `details.cancel()` keeps the previous payload.
- `modal?` (`"trap-focus" | boolean`): `false`: the rest of the page stays usable, and focus leaving the popover closes it. `true`: also traps focus, locks scroll and makes the rest of the page inert, and an outside press only closes the popover. `"trap-focus"`: traps focus but leaves the page scrollable and clickable.
- `openOnHover?` (`boolean`): Whether resting the pointer on the trigger opens the popover. Pressing the trigger still opens it, so keyboard and touch users can too.
- `delay?` (`number`): Milliseconds the pointer rests on the trigger before the popover opens, with `openOnHover`.
- `closeDelay?` (`number`): Milliseconds before the popover closes once the pointer leaves it and its trigger, with `openOnHover`.
- `presentation?` (`PresentationSetting<"popover">`): How the popover presents. `"sheet"` slides it up from the bottom of the screen, where it can be swiped away, and `"auto"` does that on small touch screens. Decided each time it opens; the server renders `"popover"` for `"auto"`.
- `controller?` (`PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>`): Opens, closes and inspects the popover from anywhere, and connects triggers outside it. Create one with `createPopoverController()`.
- `dismissible?` (`boolean`): Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass `false` while it holds unsaved work, and ask in `(dismissAttempt)`.
- `(dismissAttempt)`: Runs when `dismissible` refused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.

### PopoverTrigger

A trigger outside the popover also takes `controller`.

- `disabled?` (`boolean`): Stops the trigger from opening the popover. A native button can't be focused or pressed, unless `focusableWhenDisabled` is set.
- `focusableWhenDisabled?` (`boolean`): Keeps a disabled trigger in the tab order with `aria-disabled` instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.
- `payload?` (`unknown`): Data for the content to render when this trigger opens the popover, like the row it belongs to.
- `shortcut?` (`string`): A keyboard shortcut that presses the trigger, like `"mod+i"`. `mod` is Command on Apple platforms and Control elsewhere. Sets `aria-keyshortcuts`.
- `controller?` (`PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>`): Connects a trigger outside the popover, like one per table row, to the popover with this controller.

### PopoverContent

- `side?` (`Side`): Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the popover opens on.
- `align?` (`Align`): How the popup lines up with the anchor along that side. `start` and `end` follow the reading direction. How the popover lines up with the trigger along that side.
- `sideOffset?` (`number`): Gap between the anchor and the popup, in pixels. Gap between the trigger and the popover, in pixels.
- `alignOffset?` (`number`): Shift along the anchor, in pixels. Shift along the trigger, in pixels.
- `collisionPadding?` (`number`): Space to keep from the viewport edges, in pixels.
- `arrowPadding?` (`number`): Space to keep between the arrow and the popup's corners, in pixels.
- `anchor?` (`string | Anchor | null`): Positions the popup against this instead of its trigger: an element, a CSS selector, a point like `{ x, y }`, or anything with `getBoundingClientRect()`. It's read on every check, so it can move. A controller's `open({ anchor })` wins for that open.
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- `initialFocus?` (`PopoverInitialFocus`): Where focus goes when the popover opens. Opening on hover never moves focus, and opening with touch focuses the popover itself so no on-screen keyboard appears, unless this is set to something other than `"auto"`.
- `finalFocus?` (`PopupFocusTarget`): Where focus goes when the popover closes while focus is inside it.
- `keepMounted?` (`boolean`): Whether the popover stays in the page, hidden, while closed. Its content keeps its state between opens.
- `inline?` (`boolean`): Renders the popover where it is in the page instead of above it, inside its parent's layout and stacking, and leaves placing it to your CSS: `side`, `align` and the offsets don't apply.

### PopoverArrow

Points at the trigger from the side the popover landed on. Goes on a `div`.

### PopoverTitle

Names the popover. Goes on a `h2`.

### PopoverDescription

Describes the popover while it's rendered. Goes on a `p`.

### PopoverClose

Closes the popover. Goes on a `button`.

### PopoverShortcut

- `shortcut?` (`string`): The keys to show. Inside a trigger, its `shortcut`.

### State

What each part's `state()` signal holds, per part.

`uiPopoverTrigger`:

- `open` (`boolean`): Whether the popover is open from this trigger.
- `disabled` (`boolean`): Set by the trigger's `disabled` prop, which stops it opening the popover.

`uiPopoverContent`:

- `open` (`boolean`): Whether the popover is open. False while it animates out.
- `modal` (`boolean | "trap-focus"`): The `modal` setting.
- `presentation` (`"popover" | "sheet"`): How it presents this time it's open.
- `payload` (`Payload | undefined`): The payload of the last open, from the trigger that opened it or a controller, typed as the controller's `Payload`.

`uiPopoverArrow`:

- `open` (`boolean`): Whether the popover is open. False as soon as it starts closing, while it still animates out.

`uiPopoverShortcut`:

- `text` (`string`): The shortcut formatted for this platform: `⌘I` on Apple platforms and `Ctrl+I` elsewhere. Empty without one.

### Reasons

`$event.reason` says why the popover opened or closed.

- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
- `trigger-hover` (`PointerEvent`): The pointer rested on a trigger, or left it, with hover opening.
- `outside-press` (`MouseEvent`): A press outside the layer.
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
- `focus-out` (`KeyboardEvent | FocusEvent`): Focus left the layer, or Tab moved it out.
- `window-blur` (`FocusEvent`): The window lost focus.
- `close-press` (`MouseEvent | KeyboardEvent | SubmitEvent`): A Close part was pressed, or a form with `method="dialog"` was submitted.
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
- `shortcut` (`KeyboardEvent`): A keyboard shortcut, like a trigger's `shortcut`.
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
- `anchor-hidden` (`none`): The element the popup sits beside stopped rendering, like a trigger a breakpoint hides.
- `imperative` (`none`): A controller or `api` call.

For a payload change, it says what opened the popover or took it over.

- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
- `trigger-hover` (`PointerEvent`): The pointer rested on a trigger, or left it, with hover opening.
- `shortcut` (`KeyboardEvent`): A keyboard shortcut, like a trigger's `shortcut`.
- `imperative` (`none`): A controller or `api` call.

With `dismissible` false, the refused dismissals `(dismissAttempt)` reports:

- `outside-press` (`MouseEvent`): A press outside the layer.
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.

### Controller

Create one with `createPopoverController<Payload>()` and pass it to `[controller]`, on the popover and on any triggers outside it. `Payload` is the type of the data triggers and `open()` pass.

Every write method takes an optional `{ reason, event }`, passed to `(beforeOpenChange)`.

- `isOpen()` (`() => boolean`): Whether it's open. False as soon as it starts closing, while it still animates out.
- `setOpen(open, options?)` (`(open: boolean, options?: PopupChangeOptions<PopoverOpenChangeReason> | undefined) => boolean`): Opens or closes it. Returns false when the change was canceled or it was already open or closed.
- `open(options?)` (`(options?: (PopupChangeOptions<PopoverPayloadChangeReason> & { payload?: Payload | undefined; anchor?: Anchor | undefined; signal?: AbortSignal | undefined; }) | undefined) => Promise<...>`): Opens it, and resolves once it closes, with why, how and any return value. Resolves exactly once and never rejects: on the next close from any source, when `signal` aborts, or with reason `"unmount"` when the component leaves the page.
- `close(options?)` (`(options?: (PopupChangeOptions<PopoverOpenChangeReason> & { returnValue?: Result | undefined; }) | undefined) => boolean`): Closes it. `returnValue` is passed to the promise `open()` returned. Returns false when the close was canceled or it was already closed.
- `toggle(options?)` (`(options?: PopupChangeOptions<PopoverOpenChangeReason> | undefined) => boolean`): Opens it when it's closed, and closes it when it's open. Returns false when the change was canceled.
- `getPayload()` (`() => Payload | undefined`): The payload of the last open, from a controller or the trigger that opened it.
- `focus()` (`() => void`): Moves focus to the trigger that opened it last, or the first trigger.

### Events

A `before` output emits `{ value, reason, event, cancel() }` before the change, and its plain output follows with the value alone. A bound `open` only updates when `(beforeOpenChange)` wasn't canceled.

| Binding                 | On          | Receives                                                                             |
| ----------------------- | ----------- | ------------------------------------------------------------------------------------ |
| `[(open)]`              | `uiPopover` | Whether the popover is open                                                          |
| `(beforeOpenChange)`    | `uiPopover` | `{ value, reason, cancel() }`: the new state, and the [reason](#reasons)             |
| `(openChangeComplete)`  | `uiPopover` | `$event`, whether it's open, after the animation                                     |
| `(beforePayloadChange)` | `uiPopover` | `{ value, reason, cancel() }`: the content's new payload, and the [reason](#reasons) |
| `(dismissAttempt)`      | `uiPopover` | `{ reason, event }`, when a dismissal was refused                                    |

## Accessibility

The trigger is a button that opens a dialog, and focus inside follows the [WAI-ARIA dialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/).

### Tested Behavior

Every line below is an automated test.

**Trigger**

- Reflects the open state.
- Click opens the popover.
- Click on the open trigger closes the popover.
- Enter opens the popover.
- Space opens the popover.
- The popover closes when its trigger stops rendering, and stays closed when it's back.
- Points to the popover it controls while open.

**Focus**

- Opening moves focus to the first focusable element.
- Each time focus moves in, the popover is named by its title and described by its description.
- Tab moves through the popover in order.
- Shift+Tab from the first element returns focus to the trigger.
- Tab from the last element moves focus to the element after the trigger.
- Focus leaving the popover closes it.
- Escape closes the popover and returns focus to the trigger.
- An ancestor hears Escape already handled.
- Escape after a click returns focus to the trigger.
- The close button closes the popover and returns focus to the trigger.
- With initial focus none, opening leaves focus on the trigger.
- A virtual click from a screen reader moves focus into the popover.
- A touch press focuses the popover itself, so no on-screen keyboard appears.
- Closing after the trigger is gone moves focus to the element after where it was.
- Pressing a button inside keeps the popover open.

**Dismissal**

- Clicking outside closes the popover.
- Clicking inside the popover keeps it open.
- An outside press reaches what it hits.
- A press on empty space returns focus to the trigger.
- Escape while an input method is composing text leaves the popover open.
- Pressing a scrollbar outside the popover leaves it open.
- Pressing a button in a shadow root inside keeps the popover open.
- Tab into a button in a shadow root inside keeps the popover open.
- Escape on a button in a shadow root inside returns focus to the trigger.
- Switching windows leaves the popover open.

**Modal**

- With modal true, Tab stays inside the popover.
- With modal trap-focus, Tab stays inside the popover.
- With modal true, an outside press only closes the popover.
- With modal true, the page doesn't scroll while open.

**Hover**

- Resting the pointer on the trigger opens the popover.
- Moving the pointer into the popover keeps it open.
- Moving the pointer away closes the popover.
- Opening on hover leaves focus where it was.
- Keyboard focus on the trigger doesn't open the popover.
- Escape on a popover opened by hover leaves focus where it was.
- Pressing the trigger still opens the popover.

**Nested popovers**

- Using a nested popover keeps both open.
- Escape closes only the nested popover and returns focus to its trigger.
- Clicking outside closes every popover.

Runs in React, Vue and web components.

Additional behaviors:

**Enhancements**

- The popup writes --arrow-offset, where the trigger's center falls along its edge.
- Without a title, the trigger names the popover.
- Tab from the trigger of a popover opened by hover moves into it.
- A controller opens the popover from anywhere and moves focus in.
- With no trigger, Shift+Tab from the first field goes back to where it opened from.
- Tab past the last control closes the popover when nothing on the page follows.
- A control that turns disabled after Tab reaches it keeps the popover open.
- A popover open from the start leaves focus alone.
- Modal popovers make the rest of the page inert and restore it exactly.
- Live regions keep announcing while a modal popover makes the page inert.
- Clicking into an iframe closes the popover.
- An infinite exit animation still unmounts.

**Shortcuts**

- A trigger's shortcut opens and closes the popover.
- The trigger advertises its shortcut, and its Shortcut part shows the keys to sighted users only.
- A Shortcut part shows its own keys.
- A trigger connected through a controller shows and binds its own shortcut.

**Web components**

- A title added after the popover connects names it. Web components only.
- Changing an attribute updates the part. Web components only.

Runs in React, Vue and web components.

Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:

- Announcements while using the popover with a keyboard.

Runs in React, Vue and web components.
