---
title: Overlays
description: Anchored popovers for confirmations, renames and small forms, dialogs, and menus on the Popover API.
---

## Popover

Whatever a button asks or offers opens next to that button, not in the middle of the screen, so it stays tied to what was pressed. That covers a confirmation, a rename, a small form and a question that follows the action, such as asking to restart after a save: it opens from the Save button. On phones it's a bottom sheet.

<Demo id="popover">
  <gw-button variant="danger" data-opens="forget-device">Forget device</gw-button>
  <gw-popover id="forget-device" confirm>
    <p>Forget Living room speaker? It has to be paired again before it can connect.</p>
    <gw-button slot="actions" size="small" variant="neutral" appearance="plain" value="cancel">Cancel</gw-button>
    <gw-button slot="actions" size="small" variant="danger" value="forget">Forget</gw-button>
  </gw-popover>
  <gw-button variant="neutral" appearance="filled" data-opens="rename-section">Rename</gw-button>
  <gw-popover id="rename-section" heading="Rename section">
    <gw-input label="Name" value="Living room"></gw-input>
    <gw-button slot="actions" size="small" variant="neutral" appearance="plain" value="cancel">Cancel</gw-button>
    <gw-button slot="actions" size="small" value="save">Save</gw-button>
  </gw-popover>
  <gw-button data-opens="restart-after-save" data-toast="Settings saved" data-tone="success">Save settings</gw-button>
  <gw-popover id="restart-after-save" heading="Restart now?">
    <p>The new settings take effect after a restart.</p>
    <gw-button slot="actions" size="small" variant="neutral" appearance="plain" value="later">Later</gw-button>
    <gw-button slot="actions" size="small" value="restart">Restart</gw-button>
  </gw-popover>
  <gw-toaster></gw-toaster>
</Demo>

Keep a popover to one or two fields. A longer form is a view of its own, not a popover or a dialog stacked on the page.

| Attribute or method | What it does |
| --- | --- |
| `show(anchor)` | Opens under `anchor`, or above it when there's more room there, lined up with the edge on the button's side of the screen. Without one it opens in the middle, which is only for something nothing on screen started |
| `heading` | A heading. A confirmation that's only a question leaves it out, and the question is the message |
| `confirm` | Makes it an `alertdialog`, for a question that needs an answer |
| `close(value)` | Closes it; `returnValue` holds the value when it fires `close` |

It's on the Popover API, in the top layer, so a scrolling parent never clips it. Esc or a click outside closes it, focus starts on the first action (put Cancel first, so Enter never confirms by accident) and goes back to the button afterward. It follows the button as the page scrolls, and it's a bottom sheet below 600px wide.

## Dialog

<Demo id="dialog">
  <gw-button variant="neutral" appearance="plain" data-opens="connection-lost">Lose the connection</gw-button>
  <gw-dialog id="connection-lost" heading="Connection lost">
    <p>Can't reach the server. Changes made since will be lost if this page is closed.</p>
    <gw-button slot="actions" variant="neutral" appearance="plain" value="wait">Keep waiting</gw-button>
    <gw-button slot="actions" value="retry">Try again</gw-button>
  </gw-dialog>
</Demo>

Only for something nothing on screen started, that needs the whole screen's attention: a lost connection, an expired sign-in or an update that's ready. Anything a button starts is a [popover](#popover) instead. The button in the demo stands in for the app losing its connection.

It's a native `<dialog>` opened as a modal, so focus moves into it and back when it closes, Esc closes it, and the page behind can't be reached. Open it with `show()`. A button in the `actions` slot with a `value` closes it with that value, which is in `returnValue` when it fires `close`.

## Menus

The [menu button](/components/actions#menu-button) shows its menu on the Popover API, in the top layer, with contextual actions pinned below its items.

## References

- Home Assistant: [Adaptive dialog](https://contributors.home-assistant.io/design/components/adaptive-dialog/), [Dialog](https://contributors.home-assistant.io/design/components/dialog/) · Code: [adaptive dialog](https://github.com/home-assistant/frontend/blob/dev/src/components/ha-adaptive-dialog.ts), [dialog](https://github.com/home-assistant/frontend/blob/dev/src/components/ha-dialog.ts)
- Web Awesome: [Popover](https://webawesome.com/docs/components/popover), [Dialog](https://webawesome.com/docs/components/dialog) · Code: [popover](https://github.com/shoelace-style/webawesome/tree/next/packages/webawesome/src/components/popover), [dialog](https://github.com/shoelace-style/webawesome/tree/next/packages/webawesome/src/components/dialog)
- Primer: [Dialog](https://primer.style/product/components/dialog/) · [Code](https://github.com/primer/react/tree/main/packages/react/src/Dialog)
