Skip to content

Commit 77a2bf9

Browse files
authored
kb(Common): Add custom event and RenderFragment parameter to example (#3180)
1 parent 69cd30f commit 77a2bf9

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

knowledge-base/common-extend-inherit-wrap-reuse-telerik-blazor-components.md

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ On the other hand, neither option allows changing the internal HTML rendering of
4949
5050
### Wrap Telerik Components
5151

52-
This approach allows you to add additional markup or other components next to the Telerik component.
52+
This approach allows you to add additional markup or other components next to the Telerik component. You can also define custom events for the component, which wraps the Telerik component.
5353

5454
1. Add the Telerik component to a separate `.razor` file, for example, `MyReusableComponent.razor`.
5555
1. Implement the desired `MyReusableComponent` parameters and set the required parameters of the Telerik component.
@@ -89,28 +89,53 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
8989
Class="my-combobox"
9090
Filterable="true"
9191
FilterOperator="@StringFilterOperator.Contains"
92-
Width="200px" />
93-
94-
<p style="margin-top:2em"><strong>Inherited ComboBox</strong> with additional API and default property values</p>
92+
Width="240px">
93+
<ComboBoxPrefixTemplate>
94+
<TelerikSvgIcon Icon="@SvgIcon.Sparkles" />
95+
</ComboBoxPrefixTemplate>
96+
<ComboBoxSuffixTemplate>
97+
<TelerikButton Icon="@SvgIcon.QuestionCircle"
98+
Title="Click Me"
99+
OnClick="@OnComboBoxSuffixClick" />
100+
</ComboBoxSuffixTemplate>
101+
</TelerikComboBox>
102+
103+
<p style="margin-top:2em"><strong>Inherited ComboBox</strong> with additional parameters and default property values</p>
95104
96105
<InheritedComboBox @ref="@InheritedComboBoxRef"
97106
Data="@ListItems"
98107
@bind-Value="@SelectedValue"
99108
GroupField="@nameof(ListItem.Category)"
100109
TextField="@nameof(ListItem.Text)"
101110
ValueField="@nameof(ListItem.Id)"
102-
CustomParameter="foo" />
111+
CustomParameter="inherited foo">
112+
<ComboBoxPrefixTemplate>
113+
<TelerikSvgIcon Icon="@SvgIcon.Sparkles" />
114+
</ComboBoxPrefixTemplate>
115+
<ComboBoxSuffixTemplate>
116+
<TelerikButton Icon="@SvgIcon.QuestionCircle"
117+
Title="Click Me"
118+
OnClick="@OnComboBoxSuffixClick" />
119+
</ComboBoxSuffixTemplate>
120+
</InheritedComboBox>
103121
104122
<TelerikButton OnClick="@OnInheritedButtonClick">@InheritedComboBoxCustomProperty</TelerikButton>
105123
106-
<p style="margin-top:2em"><strong>Reusable ComboBox</strong> with additional rendering, API and default parameter values</p>
124+
<p style="margin-top:2em"><strong>Reusable ComboBox</strong> with additional rendering and parameters, custom event, and default parameter values</p>
107125
108126
<ReusableComboBox @ref="@ReusableComboBoxRef"
109127
Data="@ListItems"
110128
@bind-Value="@SelectedValue"
111129
GroupField="@nameof(ListItem.Category)"
112130
TextField="@nameof(ListItem.Text)"
113-
ValueField="@nameof(ListItem.Id)" />
131+
ValueField="@nameof(ListItem.Id)"
132+
OnSuffixTemplateClick="@OnComboBoxSuffixClick"
133+
Label="Select Item"
134+
CustomParameter="reusable foo">
135+
<PrefixTemplate>
136+
<TelerikSvgIcon Icon="@SvgIcon.Sparkles" />
137+
</PrefixTemplate>
138+
</ReusableComboBox>
114139
115140
<TelerikButton OnClick="@OnReusableButtonClick">@ReusableComboBoxCustomProperty</TelerikButton>
116141
@@ -131,6 +156,9 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
131156
private string InheritedComboBoxCustomProperty { get; set; } = "Get Custom ComboBox Property";
132157
private string ReusableComboBoxCustomProperty { get; set; } = "Get Custom ComboBox Property";
133158
159+
[CascadingParameter]
160+
public DialogFactory? TelerikDialogs { get; set; }
161+
134162
private void OnInheritedButtonClick()
135163
{
136164
InheritedComboBoxCustomProperty = InheritedComboBoxRef?.CustomProperty ?? "Error";
@@ -141,6 +169,11 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
141169
ReusableComboBoxCustomProperty = ReusableComboBoxRef?.CustomProperty ?? "Error";
142170
}
143171
172+
private async Task OnComboBoxSuffixClick()
173+
{
174+
await TelerikDialogs!.AlertAsync("SuffixTemplate Button Click fired");
175+
}
176+
144177
protected override void OnInitialized()
145178
{
146179
ListItems = new List<ListItem>();
@@ -172,7 +205,7 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
172205
@typeparam TItem
173206
@typeparam TValue
174207
175-
<span style="display: flex; gap: 1em; align-items: center;">
208+
<span style="display: inline-flex; gap: 1em; align-items: center;">
176209
<label for="@Id" style="font-size: var(--kendo-font-size)">@Label</label>
177210
<TelerikComboBox Data="@Data"
178211
Value="@Value"
@@ -185,7 +218,14 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
185218
FilterOperator="@StringFilterOperator.Contains"
186219
Class="my-combobox"
187220
Id="@Id"
188-
Width="200px" />
221+
Width="240px"
222+
ComboBoxPrefixTemplate="@PrefixTemplate">
223+
<ComboBoxSuffixTemplate>
224+
<TelerikButton Icon="@SvgIcon.QuestionCircle"
225+
Title="Click Me"
226+
OnClick="@OnSuffixButtonClick" />
227+
</ComboBoxSuffixTemplate>
228+
</TelerikComboBox>
189229
</span>
190230
191231
@code {
@@ -213,13 +253,22 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
213253
[Parameter]
214254
public string Label { get; set; } = "Select Value";
215255
256+
[Parameter]
257+
public string CustomParameter { get; set; } = string.Empty;
258+
259+
[Parameter]
260+
public RenderFragment? PrefixTemplate { get; set; }
261+
262+
[Parameter]
263+
public EventCallback OnSuffixTemplateClick { get; set; }
264+
216265
private readonly string Id = $"id-{Guid.NewGuid()}";
217266
218267
public string CustomProperty
219268
{
220269
get
221270
{
222-
return $"Custom Reusable Property {DateTime.Now.Millisecond}";
271+
return $"{CustomParameter} {DateTime.Now.Millisecond}";
223272
}
224273
}
225274
@@ -232,6 +281,14 @@ Adjust the `YourAppName.BaseComponents` namespace in `Home.razor` and `Inherited
232281
await ValueChanged.InvokeAsync(Value);
233282
}
234283
}
284+
285+
private async Task OnSuffixButtonClick()
286+
{
287+
if (OnSuffixTemplateClick.HasDelegate)
288+
{
289+
await OnSuffixTemplateClick.InvokeAsync();
290+
}
291+
}
235292
}
236293
````
237294
````C# InheritedComboBox.cs
@@ -257,7 +314,7 @@ namespace YourAppName.BaseComponents
257314
{
258315
get
259316
{
260-
return $"Custom Inherited Property {DateTime.Now.Millisecond}";
317+
return $"{CustomParameter} {DateTime.Now.Millisecond}";
261318
}
262319
}
263320

0 commit comments

Comments
 (0)