Services
TwDialogProvider
TwDialog is a Blazor dialog service for modal windows. Open any component with ITwDialogService.ShowAsync, return data, and set position, size and behaviour.
Last updated
Setup
The Dialog service shows arbitrary Blazor components as modal dialogs, wrapped in a themed
TwDialog chrome
(backdrop, header, title, close button). To use dialogs, add the TwDialogProvider component to your app and
inject the ITwDialogService.
1. Add TwDialogProvider to your layout
Place the <TwDialogProvider /> component in your main layout file (e.g., MainLayout.razor or App.razor):
HTML
<TwDialogProvider />2. Register the services
The dialog service is registered automatically when you call AddTwBlazor() with your configured theme
(see Get Started for the full theme setup):
CSHARP
builder.Services.AddTwBlazor(_ => { }, Theme.CreateDefaultTheme);3. Inject the service in your component
CSHARP
@inject ITwDialogService DialogServiceBasic Usage
Dialog content is a normal Blazor component. Show it with
ShowAsync<TComponent>(), passing a title and any
TwDialogParameters the content needs. Inside the content component, a cascaded TwDialogInstance
lets it close (or cancel) itself.
Returning Data
A dialog can return more than a boolean. Call
DialogInstance.Close(data) with any value, then read it back with
reference.GetReturnValueAsync<T>().
Position
Pass a
TwDialogOptions with a Position to control where the dialog appears on screen.
Sizing
Use
MaxWidth for a responsive width breakpoint, or FullScreen to fill the entire viewport.
Behavior Options
NoHeader hides the title bar entirely, and combining BackdropClick, CloseOnEscapeKey,
and CloseButton (all set to false) produces a dialog that can only be closed by its own content.
Theme Configuration
Styling is controlled by
TwBlazorTheme.Components (a TwDialogTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
Backdrop |
string | |
Surface |
string | |
Header |
string | |
Title |
string | |
CloseButton |
string | |
Content |
string | |
FullScreen |
string | |
FullWidth |
string | |
SmallWidth |
string | |
MediumWidth |
string | |
LargeWidth |
string |
For example, to darken the backdrop further and use fully rounded dialogs by default:
Full reference: TwDialogTheme on the API docs.