# Popover

Connect an authored trigger to a native popover. (Custom element.)

Reference: https://timeless.build/docs/components/popover/

> **Choosing between components.** Popover opens from a click and can hold interactive content. For hover or focus intent, use [Hover Card](/docs/components/hover-card/); for a modal that blocks the page, use [Dialog](/docs/components/dialog/).

## Markup

```html
<ui-popover>
  <button class="ui-button" data-ui-part="trigger" type="button" popovertarget="release-popover" aria-controls="release-popover" aria-expanded="false" aria-haspopup="dialog">Release status</button>
  <div id="release-popover" popover="auto" role="dialog" aria-labelledby="release-popover-title" aria-describedby="release-popover-description">
    <h2 id="release-popover-title">Ready to publish</h2>
    <p id="release-popover-description">All required package checks passed.</p>
  </div>
</ui-popover>
```

## Install

```js
import '@timelessui/components/css/tokens.css'
import '@timelessui/components/css/core/floating.css'
import '@timelessui/components/css/core/popover.css'
import '@timelessui/components/css/core/button.css'
import '@timelessui/components/css/themes/atmosphere/tokens.css'
import '@timelessui/components/css/themes/atmosphere/button.css'
import '@timelessui/components/css/themes/atmosphere/popover.css'
import '@timelessui/components/register/ui-popover'
```

A `register/` import is a side effect: it defines the element as the module evaluates, so it
has to run in code the browser loads. To register explicitly instead — to control the timing,
or to define into another window — call the function from the matching `define/` entry point,
which registers nothing on its own:

```js
import { definePopoverElement } from '@timelessui/components/define/ui-popover'
definePopoverElement()
```

## Anatomy

Parts are authored in your own markup and identified by the selector below. Required parts
must be present for the component to work. Private `data-ui-internal-*` hooks are written by
the runtime and must never be authored.

| Part | Required | Selector | Purpose |
| --- | --- | --- | --- |
| `trigger` | Yes | `[data-ui-part~='trigger']` | Native button that opens the surface. |
| `content` | Yes | `[popover]` | The surface. Author the `popover` attribute so it stays hidden before enhancement. |

## Attributes

Every value below is implemented by the stylesheets this component ships. Boolean attributes
are presence-based: author the attribute with no value, or omit it.

| Attribute | Values | Default | Description |
| --- | --- | --- | --- |
| `placement` | `bottom` · `top` · `right` · `left` | `bottom` | Preferred side of the trigger. Positioning uses CSS anchor positioning, so the browser may flip the surface to keep it on screen. |
| `role` | `dialog` · `menu` · `listbox` · `tooltip` | `dialog` | Semantics applied to the surface, and the `aria-haspopup` value set on the trigger. Choose it from the interaction, not the appearance. |

## Element API

Attributes above are the authoring surface. These are the DOM properties and events the
registered element adds once it upgrades.

### `<ui-popover>`

| Property | Type | Notes |
| --- | --- | --- |
| `placement` | `'bottom' | 'top' | 'right' | 'left'` | Reflects the `placement` attribute |
| `roleValue` | `'dialog' | 'menu' | 'listbox' | 'tooltip'` | Reflects the `role` attribute |

This element dispatches no component events.

## Styling

Root identity: `ui-popover`.
Required stylesheets: `tokens.css`, `core/floating.css`, `core/popover.css`, `core/button.css`, `themes/atmosphere/tokens.css`, `themes/atmosphere/button.css`, `themes/atmosphere/popover.css`.

Set these custom properties to restyle the component:

| Custom property | Controls |
| --- | --- |
| `--ui-floating-offset` | Gap between the trigger and the surface. |

Design tokens this component reads (30), global and set at the theme level: `--ui-accent`, `--ui-bg-accent`, `--ui-bg-accent-active`, `--ui-bg-accent-hover`, `--ui-bg-control`, `--ui-bg-control-active`, `--ui-bg-control-hover`, `--ui-bg-control-muted`, `--ui-bg-danger`, `--ui-bg-danger-active`, `--ui-bg-danger-hover`, `--ui-bg-surface`, `--ui-duration-fast`, `--ui-ease-standard`, `--ui-fg`, `--ui-fg-muted`, `--ui-focus`, `--ui-line`, `--ui-radius-control`, `--ui-radius-lg`, `--ui-radius-md`, `--ui-shadow-control-accent`, `--ui-shadow-control-active`, `--ui-shadow-control-danger`, `--ui-shadow-floating`, `--ui-shadow-outline-control`, `--ui-shadow-tooltip`, `--ui-space-2`, `--ui-space-3`, `--ui-space-4`.

## Accessibility

Keep the native elements, roles, and relationships shown in the markup. Timeless adds only the
state and keyboard coordination the platform does not already provide, and it never supplies
your accessible names — those depend on your content.

Follows the [Disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/) from the ARIA Authoring Practices Guide.

| Key | Action |
| --- | --- |
| `Escape` | Close the surface. Handled by the Popover API, not by Timeless. |

Light dismiss, Escape, and top-layer stacking come from the Popover API. Timeless wires `popovertarget`, `aria-controls`, `aria-expanded`, and `aria-haspopup`, and gives the surface the `role` you asked for. Name the surface yourself when it is a dialog.

## Before JavaScript runs

The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.
