---
id: dialog
title: fast-dialog
sidebar_label: dialog
custom_edit_url: https://github.com/microsoft/fast/edit/master/sites/website/versioned_docs/version-legacy/components/fast-dialog.mdx
description: fast-dialog is a web component implementation of a dialog.
keywords:
    - fast-dialog
---

As defined by the [W3C](https://w3c.github.io/aria-practices/#dialog_modal):

> A dialog is a window overlaid on either the primary window or another dialog window. Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, and in some implementations, attempts to interact with the inert content cause the dialog to close.
>
> Like non-modal dialogs, modal dialogs contain their tab sequence. That is, Tab and Shift + Tab do not move focus outside the dialog. However, unlike most non-modal dialogs, modal dialogs do not provide means for moving keyboard focus outside the dialog window without closing the dialog.

## Setup

```ts
import {
    provideFASTDesignSystem,
    fastDialog
} from "@microsoft/fast-components";

provideFASTDesignSystem()
    .register(
        fastDialog()
    );
```

## Usage

```html
<fast-dialog id="example1" class="example-dialog" aria-label="Simple modal dialog" modal="true" hidden>
    <h2>Dialog</h2>
    <p>This is an example dialog.</p>
    <fast-button>Close Dialog</fast-button>
</fast-dialog>
```

## Create your own design

```ts
import { Dialog, dialogTemplate as template } from "@microsoft/fast-foundation";
import { dialogStyles as styles } from "./my-dialog.styles";

export const myDialog = Dialog.compose({
    baseName: "dialog",
    template,
    styles,
});
```

## API



### class: `Dialog`

#### Superclass

| Name                | Module                                        | Package |
| ------------------- | --------------------------------------------- | ------- |
| `FoundationElement` | /src/foundation-element/foundation-element.js |         |

#### Fields

| Name              | Privacy | Type                                  | Default | Description                                                                                                                                                                                                   | Inherited From    |
| ----------------- | ------- | ------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `modal`           | public  | `boolean`                             | `true`  | Indicates the element is modal. When modal, user mouse interaction will be limited to the contents of the element by a modal overlay.  Clicks on the overlay will cause the dialog to emit a "dismiss" event. |                   |
| `hidden`          | public  | `boolean`                             | `false` | The hidden state of the element.                                                                                                                                                                              |                   |
| `trapFocus`       | public  | `boolean`                             | `true`  | Indicates that the dialog should trap focus.                                                                                                                                                                  |                   |
| `ariaDescribedby` | public  | `string`                              |         | The id of the element describing the dialog.                                                                                                                                                                  |                   |
| `ariaLabelledby`  | public  | `string`                              |         | The id of the element labeling the dialog.                                                                                                                                                                    |                   |
| `ariaLabel`       | public  | `string`                              |         | The label surfaced to assistive technologies.                                                                                                                                                                 |                   |
| `$presentation`   | public  | `ComponentPresentation or null`       |         | A property which resolves the ComponentPresentation instance for the current component.                                                                                                                       | FoundationElement |
| `template`        | public  | `ElementViewTemplate or void or null` |         | Sets the template of the element instance. When undefined, the element will attempt to resolve the template from the associated presentation or custom element definition.                                    | FoundationElement |
| `styles`          | public  | `ElementStyles or void or null`       |         | Sets the default styles for the element instance. When undefined, the element will attempt to resolve default styles from the associated presentation or custom element definition.                           | FoundationElement |

#### Methods

| Name              | Privacy   | Description                    | Parameters | Return | Inherited From    |
| ----------------- | --------- | ------------------------------ | ---------- | ------ | ----------------- |
| `show`            | public    | The method to show the dialog. |            | `void` |                   |
| `hide`            | public    | The method to hide the dialog. |            | `void` |                   |
| `templateChanged` | protected |                                |            | `void` | FoundationElement |
| `stylesChanged`   | protected |                                |            | `void` | FoundationElement |

#### Events

| Name     | Type | Description                                                     | Inherited From |
| -------- | ---- | --------------------------------------------------------------- | -------------- |
| `cancel` |      | Fires a custom 'cancel' event when the modal overlay is clicked |                |
| `close`  |      | Fires a custom 'close' event when the dialog is hidden          |                |

#### Attributes

| Name               | Field           | Inherited From |
| ------------------ | --------------- | -------------- |
|                    | modal           |                |
|                    | hidden          |                |
| `trap-focus`       | trapFocus       |                |
| `aria-describedby` | ariaDescribedby |                |
| `aria-labelledby`  | ariaLabelledby  |                |
| `aria-label`       | ariaLabel       |                |

#### CSS Parts

| Name                 | Description                                                                 |
| -------------------- | --------------------------------------------------------------------------- |
| `positioning-region` | A wrapping element used to center the dialog and position the modal overlay |
| `overlay`            | The modal dialog overlay                                                    |
| `control`            | The dialog element                                                          |

#### Slots

| Name | Description                             |
| ---- | --------------------------------------- |
|      | The default slot for the dialog content |

<hr/>


## Additional resources

* [Component explorer examples](https://explore.fast.design/components/fast-dialog)
* [Component technical specification](https://github.com/microsoft/fast/blob/master/packages/web-components/fast-foundation/src/dialog/dialog.spec.md)
* [W3C Component Aria Practices](https://w3c.github.io/aria-practices/#dialog_modal)
* [Open UI Analysis](https://open-ui.org/components/dialog.research)
