|
| 1 | +--- |
| 2 | +title: Adding Tooltips for Chips in a ChipList |
| 3 | +description: Learn how to display tooltips for chips in the Telerik Blazor ChipList component. |
| 4 | +type: how-to |
| 5 | +page_title: How to Display Tooltips for Chips in Telerik Blazor ChipList |
| 6 | +meta_title: How to Display Tooltips for Chips in Telerik Blazor ChipList |
| 7 | +slug: add-tooltips-chips-chiplist |
| 8 | +tags: blazor, chiplist, tooltip, itemtemplate |
| 9 | +res_type: kb |
| 10 | +ticketid: 1691888 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +<table> |
| 16 | + <tbody> |
| 17 | + <tr> |
| 18 | + <td>Product</td> |
| 19 | + <td>Telerik UI for Blazor ChipList</td> |
| 20 | + </tr> |
| 21 | + </tbody> |
| 22 | +</table> |
| 23 | + |
| 24 | +## Description |
| 25 | + |
| 26 | +You can display additional information for each chip in the [ChipList](slug:chiplist-overview) by showing a tooltip. This approach helps you keep the chip text concise while providing more details on hover. |
| 27 | + |
| 28 | +This article answers the following questions: |
| 29 | +- How do you show extra details for chips in a ChipList? |
| 30 | +- Can you display a TelerikTooltip for each chip in the ChipList? |
| 31 | +- How do you use `ItemTemplate` in Telerik Blazor ChipList? |
| 32 | + |
| 33 | +## Solution |
| 34 | + |
| 35 | +To add tooltips to chips in the ChipList, use the `ItemTemplate` to customize chip rendering and set a tooltip for each chip. Follow these steps: |
| 36 | + |
| 37 | +1. Add a `Description` property to the model used for the ChipList. |
| 38 | +2. Use the `ItemTemplate` to render each chip and set the `title` attribute for a native tooltip. |
| 39 | +3. Optionally, use the `TelerikTooltip` component for enhanced tooltip appearance and behavior. |
| 40 | + |
| 41 | +**Example: Displaying Tooltips for Chips** |
| 42 | + |
| 43 | +```razor |
| 44 | +<TelerikChipList Data="@ChipListSource"> |
| 45 | + <ItemTemplate> |
| 46 | + <div title="@context.Description" class="chip-description"> |
| 47 | + <TelerikSvgIcon Icon="@context.Icon"></TelerikSvgIcon> |
| 48 | + @context.Text |
| 49 | + </div> |
| 50 | + </ItemTemplate> |
| 51 | +</TelerikChipList> |
| 52 | +
|
| 53 | +<TelerikTooltip TargetSelector=".chip-description" /> |
| 54 | +
|
| 55 | +@code { |
| 56 | + private List<ChipModel> ChipListSource { get; set; } = new List<ChipModel> |
| 57 | + { |
| 58 | + new ChipModel |
| 59 | + { |
| 60 | + Text = "Audio", |
| 61 | + Icon = SvgIcon.FileAudio, |
| 62 | + Description = "Audio file chip." |
| 63 | + }, |
| 64 | + new ChipModel |
| 65 | + { |
| 66 | + Text = "Video", |
| 67 | + Icon = SvgIcon.FileVideo, |
| 68 | + Description = "Video file chip." |
| 69 | + } |
| 70 | + }; |
| 71 | +
|
| 72 | + public class ChipModel |
| 73 | + { |
| 74 | + public string Text { get; set; } |
| 75 | + public ISvgIcon Icon { get; set; } |
| 76 | + public string Description { get; set; } |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +## See Also |
| 82 | +- [ChipList Overview](slug:chiplist-overview) |
| 83 | +- [ChipList Templates](slug:chiplist-templates#item-template) |
| 84 | +- [Tooltip Overview](slug:tooltip-overview) |
0 commit comments