Skip to content

Commit 5141a25

Browse files
chore(drawer): improve readme and code comments on Template sample
1 parent 1db2a5e commit 5141a25

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

drawer/template/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Drawer as Side Navigation
1+
# Custom Template Drawer as Side Navigation
22

3-
This sample project shows one way to use the [Telerik Drawer](https://demos.telerik.com/blazor-ui/drawer/overview) as a side navigation in your project.
3+
This sample project shows one way to use the [Telerik Drawer](https://demos.telerik.com/blazor-ui/drawer/overview) as a side navigation in your project - this sample uses the [Template](https://docs.telerik.com/blazor-ui/components/drawer/templates#template) of the component to implement its out-of-the-box functionality with custom application code (such as item selection, navigation) and to add the expand/collapse button inside the side panel, while still keeping the `@Body` in the `<Content>` so navigation does not affect the drawer.
44

55
Key points of interest:
66

@@ -17,6 +17,6 @@ Key points of interest:
1717

1818
* The current page is denoted by the selected item in the drawer:
1919
* On initial load it is taken from the Data collection with the help of the `NavigationManager`.
20-
* On SPA navigation, the navigation happens in the `@Body` so the click selects the item and it does not dispose
20+
* On SPA navigation, the navigation happens in the `@Body` so the click selects the item and it does not dispose it.
2121

2222
* In this sample, the list of links is hardcoded for brevity. You can populate it later based on user roles and privileges or any other applicable business logic.

drawer/template/template/Shared/MainLayout.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138

139139
protected override void OnInitialized()
140140
{
141+
// pre-select the initial page the user requests
141142
string currPage = _navMan.Uri;
142143
DrawerItem ActivePage = NavigablePages.Where(p => p.Url.ToLowerInvariant() == GetCurrentPage().ToLowerInvariant()).FirstOrDefault();
143144
if (ActivePage != null)
@@ -148,19 +149,22 @@
148149
base.OnInitialized();
149150
}
150151

152+
// sample custom navigation
151153
public void NavigateToPage(DrawerItem item)
152154
{
153155
SelectedItem = item;
154156
_navMan.NavigateTo(SelectedItem.Url);
155157
}
156158

159+
// helper method to get the current page
157160
public string GetCurrentPage()
158161
{
159162
string uriWithoutQueryString = _navMan.Uri.Split("?")[0];
160163
string currPage = uriWithoutQueryString.Substring(Math.Min(_navMan.Uri.Length, _navMan.BaseUri.Length));
161164
return string.IsNullOrWhiteSpace(currPage) ? "/" : currPage;
162165
}
163166

167+
// helper method to highlight the currently selected item
164168
public string GetSelectedItemClass(DrawerItem item)
165169
{
166170
if (SelectedItem == null)

0 commit comments

Comments
 (0)