> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/apps/components/feedback/modal.md). Agents can also search and read this documentation through its [MCP server](https://docs.devolutions.net/~gitbook/mcp).

# Modal

Add modal dialogs in PowerShell Universal apps to display critical information, request decisions, and control full screen, width, and persistence.

Modals inform users about a task and can contain critical information, require decisions, or involve multiple tasks.

## Basic

```powershell
New-UDButton -Text 'Basic' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    }
}
```

## Full Screen

```powershell
New-UDButton -Text 'Full Screen' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    } -Footer {
        New-UDButton -Text "Close" -OnClick { Hide-UDModal }
    }  -FullScreen
}
```

## Full Width

Full width modals take up the full width as defined by the `-MaxWidth` parameter.

```powershell
New-UDButton -Text 'Full Width' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    } -FullWidth -MaxWidth 'md'
}
```

## Persistent

Persistent modals do not close when you click off of them. You will have to close it with `Hide-UDModal`.

```powershell
New-UDButton -Text 'Persistent' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    } -Footer {
        New-UDButton -Text "Close" -OnClick { Hide-UDModal }
    } -Persistent
}
```

## Hide a Modal

You can use the `Hide-UDModal` button to hide a modal that is currently show.

```powershell
New-UDButton -Text 'Basic' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    }
    Start-Sleep 5
    Hide-UDModal
}
```

When opening multiple modals, you can also use the `-All` parameter of `Hide-UDModal` to hide all of them instead of one at a time.

```powershell
New-UDButton -Text 'Parent' -OnClick {
    Show-UDModal -Content {
       New-UDButton -Text 'Child' -OnClick {
          Show-UDModal -Content {
              New-UDButton -Text 'hide current' -OnClick {
                  Hide-UDModal
              }
              New-UDButton -Text 'hide all' -OnClick {
                  Hide-UDModal -All
              }
          } 
       }
    }
}
```

## Styling

You can style modules using the `-Style`, `-HeaderStyle`, `-ContentStyle` and `-FooterStyle` parameters. Style is applied to the entire modal itself and the individual section styles are only applied to those sections. The value for these parameters are hashtables of CSS values.

```powershell
New-UDButton -Text 'Styling' -OnClick {
    Show-UDModal -Content {
        New-UDTypography -Text "Hello"
    } -Style @{
        backgroundColor = "red"
    }
}
```

Use `-PaperStyle` to style the dialog box itself rather than the whole modal.

## Header, Dividers and Height

Use `-Header` to add a title section above the content. `-Dividers` draws dividers above and below the content. `-FullHeight` makes the modal use the height of the window, minus 64 pixels.

```powershell
New-UDButton -Text 'Header' -OnClick {
    Show-UDModal -Header {
        New-UDTypography -Text "Title" -Variant h5
    } -Content {
        New-UDTypography -Text "Hello"
    } -Footer {
        New-UDButton -Text "Close" -OnClick { Hide-UDModal }
    } -Dividers -FullHeight
}
```

## Confirmation Prompt

`Show-UDConfirm` asks the user a question in a dialog and returns `$true` when the user selects the first choice. The dialog shows the `-Title`, the `-Question`, a drop-down list of the `-Choices`, and **Cancel** and **Ok** buttons. The second choice is selected by default, and **Cancel** returns the default choice, so the command returns `$false`. The script waits for the answer for up to 30 minutes.

```powershell
New-UDButton -Text 'Delete' -OnClick {
    if (Show-UDConfirm -Title 'Delete' -Question 'Delete this item?' -Choices 'Yes', 'No') {
        Show-UDToast 'Deleted'
    }
}
```

| Name     | Type      | Description                                                                                                   |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------- |
| Title    | Object    | The title of the dialog. Default: `Confirm`. Position 0.                                                      |
| Question | Object    | The question to show. Default: `Do you want to continue?`. Position 1.                                        |
| Choices  | String\[] | The choices. The command returns `$true` when the first choice is selected. Default: `Yes`, `No`. Position 2. |

When the app is created with the `-DisableInteractiveHost` parameter of `New-PSUApp`, no dialog is shown and `Show-UDConfirm` returns `$true`.

## Parameters

### Show-UDModal

| Name         | Type        | Description                                                                                |
| ------------ | ----------- | ------------------------------------------------------------------------------------------ |
| Content      | ScriptBlock | The content of the modal.                                                                  |
| Header       | ScriptBlock | The header (title section) of the modal.                                                   |
| Footer       | ScriptBlock | The footer of the modal, commonly buttons.                                                 |
| FullScreen   | Switch      | Shows the modal full screen.                                                               |
| FullWidth    | Switch      | Makes the modal take the full width allowed by `-MaxWidth`.                                |
| FullHeight   | Switch      | Makes the modal use the height of the window, minus 64 pixels.                             |
| MaxWidth     | String      | The maximum width of the modal: `xs`, `sm`, `md`, `lg` or `xl`.                            |
| Persistent   | Switch      | The modal does not close when the user clicks outside of it. Close it with `Hide-UDModal`. |
| Dividers     | Switch      | Draws dividers above and below the content.                                                |
| Style        | Hashtable   | CSS styles to apply to the modal.                                                          |
| HeaderStyle  | Hashtable   | CSS styles to apply to the header.                                                         |
| ContentStyle | Hashtable   | CSS styles to apply to the content.                                                        |
| FooterStyle  | Hashtable   | CSS styles to apply to the footer.                                                         |
| PaperStyle   | Hashtable   | CSS styles to apply to the dialog box.                                                     |

### Hide-UDModal

| Name | Type   | Description                                            |
| ---- | ------ | ------------------------------------------------------ |
| All  | Switch | Hides all open modals instead of only the current one. |

## API

* [Show-UDModal](https://docs.devolutions.net/powershell-universal/powershell-commands/show-udmodal.md)
* [Hide-UDModal](https://docs.devolutions.net/powershell-universal/powershell-commands/hide-udmodal.md)
* [Show-UDConfirm](https://docs.devolutions.net/powershell-universal/powershell-commands/show-udconfirm.md)

### See also

* [Devolutions Academy – Adding reset user password](https://academy.devolutions.net/student/activity/3546111-part-6-adding-reset-user-password)
* [Devolutions Academy – Adding the search users function](https://academy.devolutions.net/student/activity/3542903-part-2-adding-the-search-users-function)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/apps/components/feedback/modal.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
