Skip to content

Commit 390194b

Browse files
chore(drawer): link sample for syncing selected item (#490)
* chore(drawer): link sample for syncing selected item * Update components/drawer/navigation.md Co-authored-by: Dimo Dimov <[email protected]> * Update knowledge-base/drawer-sync-selected-item.md Co-authored-by: Dimo Dimov <[email protected]> * Update knowledge-base/drawer-sync-selected-item.md Co-authored-by: Dimo Dimov <[email protected]> * Update knowledge-base/drawer-sync-selected-item.md Co-authored-by: Dimo Dimov <[email protected]> * Update knowledge-base/drawer-sync-selected-item.md Co-authored-by: Dimo Dimov <[email protected]> Co-authored-by: Dimo Dimov <[email protected]>
1 parent f94e4f8 commit 390194b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

components/drawer/navigation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ To use the Drawer for navigating between pages:
6464
@[template](/_contentTemplates/common/navigation-components.md#navman-used)
6565
@[template](/_contentTemplates/common/navigation-components.md#double-navigation)
6666

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

6869
## See Also
6970

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: How to select drawer item if menu page is opened by using its URL
3+
description: How to select the correct drawer item when you don't navigate with the drawer
4+
type: troubleshooting
5+
page_title: Sync Drawer item selection with external navigation
6+
slug: drawer-kb-sync-selected-item
7+
position:
8+
tags:
9+
ticketid: 1530772
10+
res_type: kb
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Drawer for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
24+
## Description
25+
I'm using the Drawer component for navigation purposes.
26+
27+
A click on a Drawer item calls the sub page as intended.
28+
29+
However if I call a sub page directly by URL, the corresponding Drawer item doesn't get selected.
30+
31+
It might be confusing for a user if they open a sub page directly and no Drawer item gets selected.
32+
33+
Is there a way to "fix" this issue?
34+
35+
## Cause\Possible Cause(s)
36+
The Drawer selects (highlights) the item based on interaction with its own markup (such as a click on the item the user wants to navigate to). If you navigate by other means in the application, the component cannot capture this action and it does not update the selected item.
37+
38+
## Solution
39+
In such cases you must update the selected item with the application logic when necessary. For example, you can hook to the [NavigationManager's LocationChanged event](https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0#uri-and-navigation-state-helpers-1) and get the current page, find a corresponding item (you can also add any relevant business logic) and set it to the `SelectedItem` of the Drawer.
40+
41+
You can find a sample project here: https://github.com/telerik/blazor-ui/tree/master/drawer/select-on-load

0 commit comments

Comments
 (0)