> Markdown version of [Dialog](https://vaadin.com/docs/v23/components/dialog). Section index: [llms.txt](https://vaadin.com/docs/v23/components/llms.txt)

# Dialog

Dialog is a small window that can be used to present information and user interface elements in an overlay.

**TypeScript** — `dialog-basic.ts`

```html
<vaadin-dialog
  header-title="New employee"
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogRenderer(this.renderDialog, [])}
  ${dialogFooterRenderer(this.renderFooter, [])}
></vaadin-dialog>

<vaadin-button
  @click="${() => {
    this.dialogOpened = true;
  }}"
>
  Show dialog
</vaadin-button>
```

**Java** — `DialogBasic.java`

```java
Dialog dialog = new Dialog();

dialog.setHeaderTitle("New employee");

VerticalLayout dialogLayout = createDialogLayout();
dialog.add(dialogLayout);

Button saveButton = createSaveButton(dialog);
Button cancelButton = new Button("Cancel", e -> dialog.close());
dialog.getFooter().add(cancelButton);
dialog.getFooter().add(saveButton);

Button button = new Button("Show dialog", e -> dialog.open());

add(dialog, button);
```

## <a id="structure"></a>Structure

The Dialog component has static header and footer areas, and a scrolling content area between them. The header and footer are optional, and automatically hidden if empty and not explicitly enabled.

### <a id="header"></a>Header (since V23.1)

The header contains an optional title element, and a slot next to it for custom header content, such as a close button.

**TypeScript** — `dialog-header.ts`

```html
<vaadin-dialog
  header-title="User details"
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogHeaderRenderer(
    () => html`
      <vaadin-button theme="tertiary" @click="${this.close}">
        <vaadin-icon icon="lumo:cross"></vaadin-icon>
      </vaadin-button>
    `,
    []
  )}
  ${dialogRenderer(this.renderDialog, this.user)}
></vaadin-dialog>
```

**Java** — `DialogHeader.java`

```java
dialog.setHeaderTitle("User details");

Button closeButton = new Button(new Icon("lumo", "cross"),
        (e) -> dialog.close());
closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
dialog.getHeader().add(closeButton);
```

### <a id="footer"></a>Footer (since V23.1)

Buttons for closure actions, such as *Save*, *Cancel*, *Delete*, and so on, should be placed in the footer. See the [Button](https://vaadin.com/docs/v23/components/button.md#buttons-in-dialogs) component for guidelines for the placement of buttons in dialogs. Footer content is right-aligned by default. Components can be left-aligned by applying a margin:

**TypeScript** — `dialog-footer.ts`

```html
<vaadin-dialog
  header-title="${`Delete user "${this.user?.firstName} ${this.user?.lastName}"?`}"
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogRenderer(() => html`Are you sure you want to delete this user permanently?`, [])}
  ${dialogFooterRenderer(
    () => html`
      <vaadin-button theme="primary error" @click="${this.close}" style="margin-right: auto;">
        Delete
      </vaadin-button>
      <vaadin-button theme="tertiary" @click="${this.close}">Cancel</vaadin-button>
    `,
    []
  )}
></vaadin-dialog>
```

**Java** — `DialogFooter.java`

```java
Button deleteButton = new Button("Delete", (e) -> dialog.close());
deleteButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY,
        ButtonVariant.LUMO_ERROR);
deleteButton.getStyle().set("margin-right", "auto");
dialog.getFooter().add(deleteButton);

Button cancelButton = new Button("Cancel", (e) -> dialog.close());
cancelButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
dialog.getFooter().add(cancelButton);
```

### <a id="padding"></a>Padding

The content area’s built-in padding can be removed by applying the `no-padding` theme variant.

**TypeScript** — `dialog-no-padding.ts`

```html
<vaadin-dialog
  theme="no-padding"
  header-title="Filter reports by users:"
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogRenderer(
    () => html`
      <vaadin-grid .items="${this.people}" style="width: 500px; max-width: 100%;">
        <vaadin-grid-selection-column></vaadin-grid-selection-column>
        <vaadin-grid-column
          header="Name"
          ${columnBodyRenderer<Person>(
            (item) => html`${item.firstName} ${item.lastName}`,
            []
          )}
        ></vaadin-grid-column>
      </vaadin-grid>
    `,
    this.people
  )}
  ${dialogFooterRenderer(
    () => html`
      <vaadin-button theme="primary" @click="${this.close}">Filter</vaadin-button>
    `,
    []
  )}
></vaadin-dialog>
```

**Java** — `DialogNoPadding.java`

```java
dialog.addThemeVariants(DialogVariant.LUMO_NO_PADDING);
```

## <a id="modality"></a>Modality

A modal dialog blocks the user from interacting with the rest of the user interface while the dialog is open. A non-modal dialog, however, doesn’t block interaction.

Dialogs are modal by default.

Use modal dialogs for:

- displaying important information, like system errors

- requesting user input as part of a workflow, for example an edit dialog

- confirmation of irreversible actions, such as deleting data (Confirm Dialog is a convenient alternative for these use cases)

- breaking out sub-tasks into a separate user interface

> **Important: Modal parent dialogs in Flow**
>
> See the [Technical](#technical) section for details on the behavior of modal dialogs in Vaadin Flow.

Use non-modal dialogs:

- when the user needs access to the content below the dialog

- for less critical, optional, and/or support tasks

**TypeScript**

```html
<vaadin-dialog modeless>...</vaadin-dialog>
```

**Java**

```java
Dialog dialog = new Dialog();
dialog.setModal(false);
```

Usually, non-modal dialogs should be draggable, so that the user can move them to access the user interface beneath.

## <a id="draggable"></a>Draggable

Dialogs can be made draggable, enabling the user to move them around using a pointing device.

By default, the outer edges of a dialog, as well as the space between its components, can be used to move the dialog around.

The default areas from which a dialog can be dragged depend on whether the built-in header is used:

- If the built-in header or footer is used, they function as the default drag handles of the dialog

- Without the built-in header, any empty space within the dialog functions as a drag handle

Any component contained within a dialog can be marked and used as a drag handle by applying the `draggable` class name to it. You can choose whether to make the component’s content draggable as well, or only the component itself.

**TypeScript** — `dialog-draggable.ts`

```html
<vaadin-dialog
  aria-label="Add note"
  draggable
  modeless
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogHeaderRenderer(
    () => html`
      <h2
        class="draggable"
        style="flex: 1; cursor: move; margin: 0; font-size: 1.5em; font-weight: bold; padding: var(--lumo-space-m) 0;"
      >
        Add note
      </h2>
    `,
    []
  )}
  ${dialogRenderer(
    () => html`
      <vaadin-vertical-layout
        theme="spacing"
        style="width: 300px; max-width: 100%; align-items: stretch;"
      >
        <vaadin-vertical-layout style="align-items: stretch;">
          <vaadin-text-field label="Title"></vaadin-text-field>
          <vaadin-text-area label="Description"></vaadin-text-area>
        </vaadin-vertical-layout>
      </vaadin-vertical-layout>
    `,
    []
  )}
  ${dialogFooterRenderer(
    () =>
      html`
        <vaadin-button @click="${this.close}">Cancel</vaadin-button>
        <vaadin-button theme="primary" @click="${this.close}">Add note</vaadin-button>
      `,
    []
  )}
></vaadin-dialog>
```

**Java** — `DialogDraggable.java`

```java
dialog.setModal(false);
dialog.setDraggable(true);

...

H2 headline = new H2("Add note");
headline.addClassName("draggable");
```

It’s recommended to make non-modal dialogs draggable, so that the user can interact with content that might otherwise be obscured by the Dialog. For example, a Dialog for taking notes or for adding widgets to a dashboard by dragging can offer a better experience by allowing the user to move the Dialog around.

Modal dialogs don’t benefit from being draggable, as their modality curtain (the dark overlay behind the dialog) obscures the underlying user interface.

## <a id="resizable"></a>Resizable

A resizable dialog allows the user to resize the Dialog by dragging from the edges of the Dialog with a pointing device. Dialogs aren’t resizable by default.

Dialogs containing dynamic content and/or a lot of information, such as complex forms or Grids, may benefit from being resizable, as this offers the user some flexibility with how much data is visible at once. It also gives the user control over which part of the underlying user interface is obscured.

Dialogs that contain very little, or compact, information don’t need to be resizable.

**TypeScript** — `dialog-resizable.ts`

```html
<vaadin-dialog
  header-title="Employee list"
  resizable
  draggable
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogRenderer(
    () => html`
      <vaadin-vertical-layout
        theme="spacing"
        style="max-width: 100%; min-width: 300px; height: 100%; align-items: stretch;"
      >
        <vaadin-grid .items="${this.people}">
          <vaadin-grid-column path="firstName" title="First name"></vaadin-grid-column>
          <vaadin-grid-column path="lastName" title="Last name"></vaadin-grid-column>
          <vaadin-grid-column path="email" title="Email"></vaadin-grid-column>
          <vaadin-grid-column path="profession" title="Profession"></vaadin-grid-column>
          <vaadin-grid-column path="membership" title="Membership"></vaadin-grid-column>
        </vaadin-grid>
      </vaadin-vertical-layout>
    `,
    this.people
  )}
></vaadin-dialog>
```

**Java** — `DialogResizable.java`

```java
dialog.setDraggable(true);
dialog.setResizable(true);
```

## <a id="closing"></a>Closing

Modal dialogs are closable in three ways:

1. Pressing the `Esc` key

2. Clicking outside the Dialog

3. Programmatically, for example through the click of a Button

Providing an explicit button for closing a Dialog is recommended.

**TypeScript** — `dialog-closing.ts`

```html
<vaadin-dialog
  aria-label="System maintenance notice"
  .opened="${this.dialogOpened}"
  @opened-changed="${(event: DialogOpenedChangedEvent) => {
    this.dialogOpened = event.detail.value;
  }}"
  ${dialogRenderer(
    () => html`
      <vaadin-vertical-layout
        theme="spacing"
        style="width: 300px; max-width: 100%; align-items: stretch;"
      >
        <h2 style="margin: var(--lumo-space-m) 0; font-size: 1.5em; font-weight: bold;">
          System maintenance
        </h2>
        <p>
          System maintenance will begin at 3 PM. It is schedule to conclude at 5PM. We
          apologise for any inconvenience.
        </p>
        <vaadin-button @click="${this.close}" style="align-self: flex-end;">
          Close
        </vaadin-button>
      </vaadin-vertical-layout>
    `,
    []
  )}
></vaadin-dialog>
```

**Java** — `DialogClosing.java`

```java
Button closeButton = new Button("Close");
closeButton.addClickListener(e -> dialog.close());
```

## <a id="best-practices"></a>Best Practices

### <a id="use-sparingly"></a>Use Sparingly

Dialogs are disruptive by nature and should be used sparingly. Don’t use them to communicate non-essential information, such as success messages like “Logged in”, “Copied”, and so on. Instead, use [Notifications](https://vaadin.com/docs/v23/components/notification.md) when appropriate.

### <a id="button-placement"></a>Button Placement

See [Buttons in Dialogs](https://vaadin.com/docs/v23/components/button.md#buttons-in-dialogs).

## <a id="related-components"></a>Related Components

| Component                                                                  | Usage recommendations                            |
| -------------------------------------------------------------------------- | ------------------------------------------------ |
| [Confirm Dialog](https://vaadin.com/docs/v23/components/confirm-dialog.md) | Dialog for confirming user actions and decisions |

## <a id="technical"></a>Technical

### <a id="multiple-dialogs-and-server-side-modality-in-flow"></a>Multiple Dialogs and Server-side Modality in Flow

By default, opening multiple Dialog components simultaneously in Flow adds each subsequent Dialog as a child of the previous one.

Due to the [server-side modality mechanism in Flow](https://vaadin.com/docs/v23/advanced/server-side-modality.md#server-side-modality), this means that closing a modal Dialog automatically also closes all its children, that is, any subsequent Dialogs opened after the modal.

This can be avoided by explicitly adding each Dialog to the UI before opening it:

```java
Dialog d1 = new Dialog();
Dialog d2 = new Dialog();
add(d1, d2);  // Add dialogs to the UI before opening
d1.open();
d2.open();
```

`EBCF8110-6074-4DAB-BE6B-662C813EDDC9`
