Skip to content

Commit

Permalink
Merge kb-drawer-tooltip-1930 into production (#1933)
Browse files Browse the repository at this point in the history
* docs(drawer|tooltip): Update KB

* docs(drawer): Add explanations for navlinks and navigation

---------

Co-authored-by: Dimo Dimov <[email protected]>
  • Loading branch information
github-actions[bot] and dimodi authored Feb 16, 2024
1 parent 8918064 commit 36b098d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 43 deletions.
26 changes: 12 additions & 14 deletions components/drawer/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ To use the Drawer for navigating between pages:
* Put the `@Body` tag in the `<DrawerContent>` tag of the drawer.
* Provide a collection of models that describe the pages you want the user to navigate to.

>tip You can find a runnable sample that showcases this in the [Drawer as Side Navigation](https://github.com/telerik/blazor-ui/tree/master/drawer/sidenav) sample project.
@[template](/_contentTemplates/common/navigation-components.md#navman-used)
@[template](/_contentTemplates/common/navigation-components.md#double-navigation)

>caption Use the Drawer for Navigation in `MainLayout.razor`
Expand All @@ -41,14 +42,13 @@ To use the Drawer for navigating between pages:
</TelerikRootComponent>
@code{
List<DrawerItem> NavigablePages { get; set; } =
new List<DrawerItem>
{
new DrawerItem { Text = "Home", Url = "/", Icon = SvgIcon.Home },
new DrawerItem { Separator = true },
new DrawerItem { Text = "Counter", Url = "counter", Icon = SvgIcon.PlusOutline },
new DrawerItem { Text = "FetchData", Url = "fetchdata", Icon = SvgIcon.Grid }
};
List<DrawerItem> NavigablePages { get; set; } = new List<DrawerItem>
{
new DrawerItem { Text = "Home", Url = "/", Icon = SvgIcon.Home },
new DrawerItem { Separator = true },
new DrawerItem { Text = "Counter", Url = "counter", Icon = SvgIcon.PlusOutline },
new DrawerItem { Text = "FetchData", Url = "fetchdata", Icon = SvgIcon.Grid }
};
public class DrawerItem
{
Expand All @@ -60,13 +60,11 @@ To use the Drawer for navigating between pages:
}
````

## Additional Examples

## Notes

@[template](/_contentTemplates/common/navigation-components.md#navman-used)
@[template](/_contentTemplates/common/navigation-components.md#double-navigation)
* A GitHub sample project that showcases [Drawer as side navigation](https://github.com/telerik/blazor-ui/tree/master/drawer/sidenav).
* KB article on [how to select a Drawer item when the page loads]({%slug drawer-kb-sync-selected-item%}).

* You may also find useful [this article on selecting a Drawer item when a page loads]({%slug drawer-kb-sync-selected-item%}).

## See Also

Expand Down
2 changes: 2 additions & 0 deletions components/drawer/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The `<ItemTemplate>` controls the rendering of the [data bound items]({%slug dra

This template receives a `context` argument that is of the data model type and represents the current item.

When using an `ItemTemplate`, the Drawer can still [navigate automatically if the `UrlField` parameter is set, or if the Drawer data items have a popuplated `Url` property]({%slug drawer-navigation%}).

>caption Use ItemTemplate to control the rendering of the items in the Drawer.
````CSHTML
Expand Down
84 changes: 55 additions & 29 deletions knowledge-base/drawer-add-tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,96 @@ page_title: Drawer tooltips
slug: drawer-kb-tooltips
position:
tags:
ticketid: 1640720
res_type: kb
---

## Environment

<table>
<tbody>
<tr>
<td>Product</td>
<td>Drawer for Blazor</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Product</td>
<td>Drawer for Blazor</td>
</tr>
</tbody>
</table>


## Description

I would like to add [Tooltips]({%slug tooltip-overview%}) to the [Drawer's]({%slug drawer-overview%}) navigation icons.


## Solution

To add a tooltip to the drawer navigation icons you have to use the [ItemTemplate]({%slug drawer-templates%}#itemtemplate) to set a `title` attribute to the desired element (like the `span` that contains the icon).

If using a [TelerikTooltip](https://demos.telerik.com/blazor-ui/tooltip/overview), add a suitable CSS selector, which targets the span with the icon, to the `TargetSelector` parameter of the component.

When using an `ItemTemplate`, the Drawer can still [navigate automatically if the `UrlField` parameter is set, or if the Drawer data items have a popuplated `Url` property]({%slug drawer-navigation%}).

>caption Add a tooltip to the Drawer navigation icons
````CSHTML
@* Add a Telerik Tooltip to the Drawer *@
<TelerikTooltip TargetSelector=".k-drawer-items span.k-icon[title]" />
<TelerikTooltip TargetSelector=".k-drawer-items span.icon-container[title]" />
<p>
<TelerikButton OnClick="@(() => DrawerRef.ToggleAsync())" Icon="@SvgIcon.Menu">Toggle drawer</TelerikButton>
<TelerikButton OnClick="@ToggleDrawer" Icon="@SvgIcon.Menu">Toggle Drawer</TelerikButton>
</p>
<TelerikDrawer Data="@Data"
<TelerikDrawer @ref="@DrawerRef"
Data="@DrawerData"
MiniMode="true"
Mode="@DrawerMode.Push"
@ref="@DrawerRef">
Mode="@DrawerMode.Push">
<ItemTemplate Context="item">
<span class="k-icon [email protected]" title="@item.Title"></span>
@* When UrlField is set or there is Url property, the Drawer will navigate automatically. *@
<span class="icon-container" title="@item.Title">
<TelerikSvgIcon Icon="@item.Icon" />
</span>
<span class="k-item-text">@item.Text</span>
@* *** *@
@* When UrlField is not set and there is no Url property, navigate manually with NavLink or NavigationManager. *@
@*<NavLink>
<TelerikSvgIcon Icon="@item.Icon" />
</NavLink>
<NavLink class="k-item-text drawer-navlink">
<span>@item.Text</span>
</NavLink>*@
</ItemTemplate>
</TelerikDrawer>
<style>
.drawer-navlink {
color: inherit;
text-decoration: none;
}
</style>
@code {
public TelerikDrawer<DrawerItem> DrawerRef { get; set; }
public IEnumerable<DrawerItem> Data { get; set; } =
new List<DrawerItem>
{
new DrawerItem { Title="Counter Title", Text = "Counter", Icon = SvgIcon.Plus, Url = "counter" },
new DrawerItem { Title="FetchData Title", Text = "FetchData", Icon = SvgIcon.GridLayout, Url = "fetchdata" },
};
private TelerikDrawer<DrawerItem>? DrawerRef { get; set; }
private IEnumerable<DrawerItem> DrawerData { get; set; } = new List<DrawerItem>
{
new DrawerItem { Title="Counter Title", Text = "Counter", Icon = SvgIcon.Plus, Url = "counter" },
new DrawerItem { Title="FetchData Title", Text = "FetchData", Icon = SvgIcon.GridLayout, Url = "fetchdata" },
};
private async Task ToggleDrawer()
{
await DrawerRef?.ToggleAsync();
}
public class DrawerItem
{
public string Title { get; set; }
public string Text { get; set; }
public ISvgIcon Icon { get; set; }
public string Url { get; set; }
public string Title { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
public ISvgIcon? Icon { get; set; }
public string Url { get; set; } = string.Empty;
}
}
````

0 comments on commit 36b098d

Please sign in to comment.