Skip to content

Commit afc3ef9

Browse files
github-actions[bot]KB Botntachevadimodiyordan-mitev
authored
Added new kb article dropdownlist-change-icon-when-popup-opened (#1833)
* Added new kb article dropdownlist-change-icon-when-popup-opened * Update knowledge-base/dropdownlist-change-icon-when-popup-opened.md * Update knowledge-base/dropdownlist-change-icon-when-popup-opened.md * Update knowledge-base/dropdownlist-change-icon-when-popup-opened.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> * Update knowledge-base/dropdownlist-change-icon-when-popup-opened.md Co-authored-by: Yordan <60105689+yordan-mitev@users.noreply.github.com> * chore(dropdown): enhance example and title --------- Co-authored-by: KB Bot <kb-bot@telerik.com> Co-authored-by: Nadezhda Tacheva <73842592+ntacheva@users.noreply.github.com> Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> Co-authored-by: Yordan <60105689+yordan-mitev@users.noreply.github.com> Co-authored-by: Nadezhda Tacheva <Nadezhda.Tacheva@progress.com>
1 parent 4ec7618 commit afc3ef9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Change the DropDownList Icon When the Popup is Opened
3+
description: Learn how to change the icon of the DropDownList when the popup is opened.
4+
type: how-to
5+
page_title: How to Change the Icon of the DropDownList When the Popup is Opened
6+
slug: dropdownlist-kb-change-icon-when-popup-opened
7+
tags: dropdownlist, icon
8+
ticketid: 1636055
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>DropDownList for Blazor, ComboBox for Blazor, MultiColumnComboBox for Blazor, MultiSelect for Blazor</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
I want to change the icon of the DropDownList when the popup is opened.
25+
26+
Specifically, I want the icon to point up when the dropdown is expanded and to point down when the dropdown is collapsed. How to achieve this?
27+
28+
## Solution
29+
30+
To change the DropDownList icon when the popup is opened, follow these steps:
31+
32+
1. Handle the [`OnOpen`]({%slug components/dropdownlist/events%}#onopen) and [`OnClose`]({%slug components/dropdownlist/events%}#onclose) events of the DropDownList component.
33+
2. Declare a flag to save the opened or closed state of the popup.
34+
3. Toggle the flag value in the `OnOpen` and `OnClose` event handlers.
35+
4. Use CSS to change the icon based on the flag value. Conditionally add a `<style>` tag to achieve this.
36+
- All components, including the DropDownList, use SVG icons. To change the icon, you can alter the `path` of the `<svg>` element.
37+
- To get the path of the [desired icon](https://www.telerik.com/design-system/docs/foundation/iconography/icon-list), render an [`SvgIcon`]({%slug common-features-icons%}#svgicon-component) component, inspect it, and copy its path.
38+
39+
>caption Change the DropDownList icon when expanded
40+
41+
````CSHTML
42+
@if (isPopupOpen)
43+
{
44+
<style>
45+
.custom-dropdown-icon .k-input-button .k-svg-icon svg path {
46+
d: path("m256 160 128 192H128l128-192z");
47+
}
48+
</style>
49+
}
50+
51+
Desired icon to include conditionally: <TelerikSvgIcon Icon="@SvgIcon.CaretAltDown"></TelerikSvgIcon>
52+
53+
<br />
54+
55+
<TelerikDropDownList Class="custom-dropdown-icon"
56+
Data="@DropDownListData"
57+
OnOpen="OnDropDownListPopupOpen"
58+
OnClose="@OnDropDownListPopupClose"
59+
@bind-Value="@DropDownListValue"
60+
Width="300px">
61+
</TelerikDropDownList>
62+
63+
@code {
64+
private string DropDownListValue { get; set; }
65+
66+
private List<string> DropDownListData { get; set; } = new List<string>() { "first", "second", "third" };
67+
68+
private bool isPopupOpen { get; set; }
69+
70+
private void OnDropDownListPopupOpen(DropDownListOpenEventArgs args)
71+
{
72+
isPopupOpen = true;
73+
}
74+
75+
private void OnDropDownListPopupClose(DropDownListCloseEventArgs args)
76+
{
77+
isPopupOpen = false;
78+
}
79+
}
80+
````

0 commit comments

Comments
 (0)