-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new kb article treeview-change-expand-collapse-icons #2618
Merged
ntacheva
merged 6 commits into
master
from
new-kb-treeview-change-expand-collapse-icons-76000854330444cbbc75b72f96077895
Dec 13, 2024
+135
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb4df7f
Added new kb article treeview-change-expand-collapse-icons
735bbc3
Update knowledge-base/treeview-change-expand-collapse-icons.md
ntacheva 90f21b3
Update knowledge-base/treeview-change-expand-collapse-icons.md
ntacheva cfee3eb
Update knowledge-base/treeview-change-expand-collapse-icons.md
ntacheva f0e943f
Update knowledge-base/treeview-change-expand-collapse-icons.md
ntacheva ebbcc33
chore(TreeView): address feedback
ntacheva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
knowledge-base/treeview-change-expand-collapse-icons.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
title: Change the Expand and Collapse Icons in TreeView | ||
description: Learn how to customize the expand and collapse icons in the Telerik TreeView component for Blazor. | ||
type: how-to | ||
page_title: How to Customize Expand and Collapse Icons in Blazor TreeView | ||
slug: treeview-kb-change-expand-collapse-icons | ||
tags: blazor, treeview, icons, expand, collapse | ||
res_type: kb | ||
ticketid: 1656109 | ||
--- | ||
|
||
## Environment | ||
|
||
<table> | ||
<tbody> | ||
<tr> | ||
<td>Product</td> | ||
<td>TreeView for Blazor</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
## Description | ||
I want to customize the icons used for expanding and collapsing items in the [TreeView for Blazor]({%slug treeview-overview%}). | ||
|
||
This knowledge base article answers the following questions: | ||
- How can I use custom icons for the TreeView expand and collapse functionality? | ||
- Is it possible to change the default expand and collapse icons in the TreeView for Blazor? | ||
|
||
## Solution | ||
|
||
You can change the expand/collapse icons in the TreeView by overriding the built-in icons with other icons using [custom CSS rules]({%slug themes-override%}). In addition, you can use the `Class` parameter of the TreeView to add a custom CSS Class and modify a specific instance of the TreeView, instead of all instances on the page. | ||
|
||
>caption Change the expand/collapse icons in TreeView | ||
|
||
````CSHTML | ||
@* In Telerik.UI.for.Blazor version 4.3.0 and later, the components use SVG icons by default. Use the following CSS for versions 4.3.0 and later. *@ | ||
@* Render the desired SVG icon and inspect it with your dev tools to get its path. *@ | ||
<style> | ||
.custom-icons .k-treeview-toggle .k-svg-icon.k-svg-i-caret-alt-down svg path { | ||
d: path("m382.059 158.059-126.06 126.06-126.061-126.06L96 192l159.999 160L416 192z"); | ||
} | ||
|
||
.custom-icons .k-treeview-toggle .k-svg-icon.k-svg-i-caret-alt-right svg path { | ||
d: path("m158.059 129.941 126.06 126.06-126.06 126.061L192 416l160-159.999L192 96z"); | ||
</style> | ||
|
||
@* In Telerik.UI.for.Blazor version below 4.3.0, the components use Font icons by default. Use this CSS for versions prior to 4.3.0. *@ | ||
@* Copy the unicode of your desired icon from the Progress Design System - https://www.telerik.com/design-system/docs/foundation/iconography/icon-list/ *@ | ||
|
||
@* <style> | ||
.custom-icons .k-treeview-toggle .k-icon.k-i-caret-alt-down::before { | ||
content: "\e015"; | ||
} | ||
|
||
.custom-icons .k-treeview-toggle .k-icon.k-i-caret-alt-right::before { | ||
content: "\e014"; | ||
} | ||
</style> *@ | ||
|
||
<TelerikTreeView Class="custom-icons" | ||
Data="@FlatData" | ||
@bind-ExpandedItems="@ExpandedItems" /> | ||
|
||
@code { | ||
private IEnumerable<TreeItem> FlatData { get; set; } | ||
|
||
private IEnumerable<object> ExpandedItems { get; set; } = new List<TreeItem>(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
FlatData = GetFlatData(); | ||
|
||
ExpandedItems = FlatData.Where(x => x.HasChildren == true && x.Id != 3).ToList(); | ||
} | ||
|
||
List<TreeItem> GetFlatData() | ||
{ | ||
List<TreeItem> items = new List<TreeItem>(); | ||
|
||
items.Add(new TreeItem() | ||
{ | ||
Id = 1, | ||
Text = "wwwroot", | ||
ParentId = null, | ||
HasChildren = true, | ||
Icon = SvgIcon.Folder | ||
}); | ||
items.Add(new TreeItem() | ||
{ | ||
Id = 2, | ||
Text = "css", | ||
ParentId = 1, | ||
HasChildren = true, | ||
Icon = SvgIcon.Folder | ||
}); | ||
items.Add(new TreeItem() | ||
{ | ||
Id = 3, | ||
Text = "js", | ||
ParentId = 1, | ||
HasChildren = true, | ||
Icon = SvgIcon.Folder | ||
}); | ||
items.Add(new TreeItem() | ||
{ | ||
Id = 4, | ||
Text = "site.css", | ||
ParentId = 2, | ||
Icon = SvgIcon.Css | ||
}); | ||
items.Add(new TreeItem() | ||
{ | ||
Id = 5, | ||
Text = "scripts.js", | ||
ParentId = 3, | ||
Icon = SvgIcon.Js | ||
}); | ||
|
||
return items; | ||
} | ||
|
||
public class TreeItem | ||
{ | ||
public int Id { get; set; } | ||
public string Text { get; set; } | ||
public int? ParentId { get; set; } | ||
public bool HasChildren { get; set; } | ||
public ISvgIcon Icon { get; set; } | ||
} | ||
} | ||
```` | ||
## See Also | ||
- [TreeView Overview]({%slug treeview-overview%}) | ||
- [Telerik Icons List](https://www.telerik.com/design-system/docs/foundation/iconography/icon-list/) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can mention / show what to do to if one wants to use non-Telerik font icons. They will also have to override the
font-family
styles.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add that on later stage if there is a demand/questions.