Skip to content

Commit 8f8a61c

Browse files
author
KB Bot
committed
Added new kb article dropdownbutton-add-separator-between-items
1 parent 5226e67 commit 8f8a61c

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Adding a Separator Between Items in a DropDownButton for Blazor
3+
description: Learn how to add a separator between the items in a DropDownButton by utilizing custom styling in a Blazor application.
4+
type: how-to
5+
page_title: How to Implement Item Separators in a Telerik Blazor DropDownButton
6+
slug: dropdownbutton-kb-add-separator-between-items
7+
tags: dropdownbutton, blazor, item separator, custom styling
8+
res_type: kb
9+
ticketid: 1680307
10+
---
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>DropDownButton for Blazor</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
I want to visually separate the items in a [DropDownButton](slug:dropdownbutton-overview) to enhance the UI and improve user experience. How to add a separator (divider) between the items?
25+
26+
## Solution
27+
28+
The DropDownButton does not have a concept for a "separator" item (similar to the [ContextMenu](slug:contextmenu-data-binding-overview), for example). However, the DropDownButton uses a declarative approach for its items, so you can add any desired item.
29+
30+
The specific is that the content you declare in the DropDownButtonItem will be rendered inside the <span class="k-menu-link-text"> which is narrower and thus your custom separator will not cover the whole width of the popup. This article demonstrates how to achieve a similar effect by utilizing custom styling.
31+
32+
To create a visual separator between items in a DropDownButton, apply a custom class to the item that precedes the separator and style its bottom border. This approach allows you to simulate a separator without the need for a dedicated separator item. The custom class can be applied directly in the item declarations in your Blazor component.
33+
34+
>caption Add separator between DropDownButton items
35+
36+
````RAZOR
37+
<style>
38+
.item-with-separator {
39+
border-bottom: 1px solid #e5e5e5;
40+
}
41+
</style>
42+
43+
<TelerikDropDownButton Icon="@SvgIcon.Share" OnClick="@(()=>OnItemClick("Primary"))">
44+
<DropDownButtonContent>Share</DropDownButtonContent>
45+
46+
<DropDownButtonItems>
47+
<DropDownButtonItem Icon="@SvgIcon.Facebook" OnClick="@(()=>OnItemClick("Facebook"))">Facebook</DropDownButtonItem>
48+
<DropDownButtonItem Icon="@SvgIcon.Twitter" OnClick="@(()=>OnItemClick("Twitter"))">Twitter</DropDownButtonItem>
49+
<DropDownButtonItem Icon="@SvgIcon.Linkedin" OnClick="@(()=>OnItemClick("Linkedin"))" Class="item-with-separator">Linkedin</DropDownButtonItem>
50+
<DropDownButtonItem OnClick="@(()=>OnItemClick("Reddit"))">Other</DropDownButtonItem>
51+
</DropDownButtonItems>
52+
53+
</TelerikDropDownButton>
54+
55+
@code {
56+
private void OnItemClick(string item)
57+
{
58+
Console.WriteLine($"User clicked {item} option.");
59+
}
60+
}
61+
````
62+
63+
## See Also
64+
65+
- [DropDownButton Overview](slug:dropdownbutton-overview)
66+
- [Customizing the Appearance of Telerik UI for Blazor Components](slug:themes-override)

0 commit comments

Comments
 (0)