New to Telerik UI for Blazor? Start a free 30-day trial
Prevent Drawer from collapsing on item click
Updated on Apr 22, 2026
Environment
| Product | Drawer for Blazor |
Description
I would like to prevent the Drawer from collapsing when an item from the navigation is clicked and switch between the collapsed and expanded state by the click of a button.
Solution
- Add a Button and update the value of the
Expandedparameter in the Button's OnClick event handler. - Handle the
ExpandedChangedevent of the Drawer, but don't update theExpandedparameter value in the handler. This prevents the Drawer from collapsing on item selection.
Stop the Drawer from collapsing on item click
<TelerikDrawer Expanded="@DrawerExpanded"
ExpandedChanged="@DrawerExpandedChanged"
Data="Data"
Mode="@DrawerMode.Push"
MiniMode="true"
@bind-SelectedItem="@SelectedItem">
<DrawerContent>
<TelerikButton OnClick="@ToggleDrawer" Icon="@SvgIcon.Menu" />
<p>@SelectedItem?.Text</p>
</DrawerContent>
</TelerikDrawer>
@code {
public DrawerItem SelectedItem { get; set; }
public bool DrawerExpanded { get; set; } = true;
public IEnumerable<DrawerItem> Data { get; set; } =
new List<DrawerItem>
{
new DrawerItem { Text = "Inbox", Icon = SvgIcon.Inbox },
new DrawerItem { Text = "Notifications", Icon = SvgIcon.Bell },
new DrawerItem { Text = "Calendar", Icon = SvgIcon.Calendar },
new DrawerItem { Text = "Attachments", Icon = SvgIcon.EnvelopeLink },
new DrawerItem { Text = "Favourites", Icon = SvgIcon.StarOutline }
};
private void ToggleDrawer()
{
DrawerExpanded = !DrawerExpanded;
}
private void DrawerExpandedChanged(bool newExpanded)
{
// Do not modify the DrawerExpanded value here.
}
public class DrawerItem
{
public string Text { get; set; }
public ISvgIcon Icon { get; set; }
}
}