Skip to content

Commit cc9bc83

Browse files
dimodidimodi
authored andcommitted
kb(Dialog): Add KB for predefined dialog's width
1 parent 4288e76 commit cc9bc83

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

components/dialog/predefined.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ position: 2
1010

1111
# Predefined Dialogs - Alert, Confirm, Prompt
1212

13-
Telerik UI for Blazor provides styled substitutes to the standard alert, confirm, and prompt dialogs of the browser. These Blazor popup messages match the Theme of the components to make it obvious to the user that the modal dialog is coming from your application.
13+
Telerik UI for Blazor provides styled substitutes to the standard alert, confirm, and prompt dialogs of the browser. These Blazor popup messages match the theme of the components to make it obvious to the user that the modal dialog is coming from your application.
1414

1515

1616
## Using Predefined Dialogs
@@ -195,3 +195,4 @@ The prompt dialog returns a `string` that the user enters when they press `OK`,
195195

196196
* [Live Demo: Predefined Dialogs](https://demos.telerik.com/blazor-ui/dialog/predefined-dialogs)
197197
* [Using the `<TelerikDialog>` Component Declaratively]({%slug dialog-overview%})
198+
* [Setting Width to Predefined Dialogs]({%slug dialog-kb-dialogfactory-alert-confirm-prompt-width%})
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: Set Width to Predefined Telerik Dialogs
3+
description: Learn how to set width to predefined Telerik Dialogs such as alert, confirm and prompt modal popups. The width can be fixed or a percentage of the browser window's viewport.
4+
type: how-to
5+
page_title: How to Set Width to Predefined Telerik Dialogs
6+
slug: dialog-kb-dialogfactory-alert-confirm-prompt-width
7+
tags: telerik, blazor, dialog, css, styling
8+
ticketid: 1667334
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Dialog for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
This KB answers the following questions:
26+
27+
* How to specify a `width` style to the predefined Telerik Blazor Dialogs, such as `AlertAsync()`?
28+
* How to apply dimensions to modal popups that are used through the Telerik `DialogFactory` cascading parameter?
29+
* How to define a width of predefined dialogs that are a percentage of the browser window viewport?
30+
31+
## Solution
32+
33+
All [Telerik Blazor Dialogs]({%slug dialog-overview%}) render a `k-dialog` CSS class. In addition, the [predefined dialogs]({%slug dialog-predefined%}) render a `k-alert` CSS class. Use this distinguishing CSS class to target popups that are generated by the Telerik `DialogFactory` and apply CSS styles.
34+
35+
>caption Set width to Telerik Blazor DialogFactory modal popups
36+
37+
````CSHTML
38+
<TelerikButton OnClick="@( () => DialogVisible = true )">Show Dialog</TelerikButton>
39+
40+
<TelerikButton OnClick="@ShowDialogFactoryPopup">Show DialogFactory Alert</TelerikButton>
41+
42+
<TelerikDialog @bind-Visible="@DialogVisible"
43+
Width="33vw"
44+
ButtonsLayout="@DialogButtonsLayout.End">
45+
<DialogTitle>
46+
Dialog Component
47+
</DialogTitle>
48+
<DialogContent>
49+
<p>This Dialog is 33vw wide at all times.</p>
50+
</DialogContent>
51+
<DialogButtons>
52+
<TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
53+
OnClick="@( () => DialogVisible = false )">OK</TelerikButton>
54+
</DialogButtons>
55+
</TelerikDialog>
56+
57+
<style>
58+
/* This CSS rule will affect only DialogFactory popups */
59+
.k-dialog.k-alert {
60+
min-width: 300px !important; /* overrides an inline style */
61+
width: 33vw;
62+
max-width: 500px;
63+
}
64+
</style>
65+
66+
@code {
67+
[CascadingParameter]
68+
public DialogFactory? TelerikDialogs { get; set; }
69+
70+
private bool DialogVisible { get; set; }
71+
72+
private async Task ShowDialogFactoryPopup()
73+
{
74+
if (TelerikDialogs != null)
75+
{
76+
await TelerikDialogs.AlertAsync(@"This Dialog is 33vw wide, but with min/max restrictions.
77+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ultricies congue dolor vel aliquet.
78+
Nunc ac enim neque. Suspendisse facilisis porta laoreet.
79+
Sed suscipit mauris lectus, ut porttitor velit porta vitae.
80+
Suspendisse potenti. Quisque auctor ac ante at egestas.", "Alert Dialog");
81+
}
82+
}
83+
}
84+
````
85+
86+
## See Also
87+
88+
* [Predefined Telerik Dialogs]({%slug dialog-predefined%})
89+
* [Dialog Component Overview]({%slug dialog-overview%})

0 commit comments

Comments
 (0)