Dimension in Predefined Dialogs in Blazor

11 Aug 20227 minutes to read

Customize the predefined dialogs dimensions using the DialogOptions.Height and DialogOptions.Width properties.

By default, the predefined dialogs Width and Height property value is set as auto. Depends on the dialog content the width and height values are automatically adjust. You can specify the dimension values in both pixels and percentage format to change the default dialog width and height values.

Use the following code snippet for alert.razor, confirm.razor and prompt.razor to customize the dialog dimensions.

@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
@inject SfDialogService DialogService
    <div>
        <SfButton @onclick="@AlertBtn">Alert</SfButton>
    </div>
@code {
    private async Task AlertBtn()
    {
        await DialogService.AlertAsync("Delete certain files to free up space to store more items.", "Not enough space", new DialogOptions()
            {
                Width = "300px",
                Height = "200px",
            });
    }    
}
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
@inject SfDialogService DialogService
    <div>
        <SfButton @onclick="@ConfirmBtn">Confirm</SfButton>
    </div>
@code {
        private async Task ConfirmBtn()
        {
            bool isConfirm = await DialogService.ConfirmAsync("Are you sure you want to permanently delete these items?", "Delete Multiple Items", new DialogOptions()
            {
                Width = "400px",
                Height = "200px",
            });
    }
}
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
@inject SfDialogService DialogService
    <div>
        <SfButton @onclick="@PromptBtn">Prompt</SfButton>
    </div>
@code {
    private async Task PromptBtn()
    {
        string promptText = await DialogService.PromptAsync(null, "Join Wi-Fi network", new DialogOptions()
        {
            Width = "350px",
            Height = "210px",
            ChildContent = @<table class="Table">
                    <tbody>
                        <tr>
                            <td>SSID:</td>
                        </tr>
                        <tr>
                            <td><b>AndroidAP</b></td>
                        </tr>
                        <tr>
                            <td>Password:</td>
                            <td>
                                <span class="e-input-group">
                                    <input type="password" id="password" name="Required" class="e-input">
                                </span>
                            </td>
                        </tr>
                    </tbody>
                </table>
        });
    }
}

Results from the code snippet

Alert

Alert dimension Dialog

Confirm

confirm dimension Dialog

Prompt

prompt dimension Dialog

Max-width and max-height

To have a restricted max-width and max-height dialog dimension, you need to specify the max-width, max-height CSS properties for the component’s container element by using the CssClass property. The max-height value is calculated in source level and set to the dialog. so, need to override the max-height property.

Use the following code to customize the max-width and max-height for alert dialog:

@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Popups
@inject SfDialogService DialogService
    <div>
        <SfButton @onclick="@AlertBtn">Alert</SfButton>
    </div>
    <style>
        .e-dialog.customClass {
            max-width: 350px;
            max-height: 250px !important;
        }
    </style>
@code {
    private async Task AlertBtn()
    {
        await DialogService.AlertAsync(" In the Succinctly series, Syncfusion created a robust, free library of more than 130 technical e-books formatted for PDF, Kindle, and EPUB.Each title in the Succinctly series is written by a carefully chosen expert and provides essential content in about 100 pages. The Succinctly series was born in 2012 out of a desire to provide concise technical e-books for software developers.", "About SYNCFUSION Succinctly Serires", new DialogOptions()
            {
               CssClass ="customClass ",
            });
    }   
}

Max width and height

Min-width and min-height

To have a restricted min-width and min-height dialog dimension, you need to specify the min-width, min-height CSS properties for the component’s container element by using the CssClass property.

Use the following code to customize the min-width and min-height for alert dialog:

@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Popups
@inject SfDialogService DialogService
    <div>
        <SfButton @onclick="@AlertBtn">Alert</SfButton>
    </div>
    <style>
        .e-dialog.customClass {
            min-width: 300px;
            min-height: 200px;
        }
    </style>
@code {
    private async Task AlertBtn()
    {
        await DialogService.AlertAsync("The Succinctly series was born in 2012.", "About SYNCFUSION Succinctly Serires", new DialogOptions()
            {
               CssClass ="customClass ",
            });
    }   
}

Min width and height