Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/drawer/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ To use the Drawer for navigating between pages:
@[template](/_contentTemplates/common/navigation-components.md#navman-used)
@[template](/_contentTemplates/common/navigation-components.md#double-navigation)

* 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
41 changes: 41 additions & 0 deletions knowledge-base/drawer-sync-selected-item.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: How to select drawer item if menu page is opened by using its URL
description: How to select the correct drawer item when you don't navigate with the drawer
type: troubleshooting
page_title: Sync Drawer item selection with external navigation
slug: drawer-kb-sync-selected-item
position:
tags:
ticketid: 1530772
res_type: kb
---

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


## Description
I'm using the Drawer component for navigation purposes.

A click on a Drawer item calls the sub page as intended.

However if I call a sub page directly by URL, the corresponding Drawer item doesn't get selected.

It might be confusing for a user if they open a sub page directly and no Drawer item gets selected.

Is there a way to "fix" this issue?

## Cause\Possible Cause(s)
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.

## Solution
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.

You can find a sample project here: https://github.com/telerik/blazor-ui/tree/master/drawer/select-on-load