I'm using a custom drawer item to handle toggling the drawer open and close. Every time I click on my custom toggle item I call Drawer.ToggleAsync() (which I trigger on the SelectedItemChanged event handler). If the drawer is expanded to begin with, it is correctly collapsed to the mini view. However, if I click the toggle item again, the drawer expands and then immediately re-collapses itself. I put a breakpoint on the code that calls Drawer.ToggleAsync(), and it's only getting hit once for each click. This is very strange behavior. Please help me work out what's going on.
P.S If there is a better way to handle the click on my custom toggle drawer item (rather than using SelectedItemChanged), please let me know.
Code
@inherits LayoutComponentBase
<TelerikRootComponent>
<div class="page">
<div class="drawer-container">
<TelerikDrawer
@ref="@Drawer"
Data="Data"
MiniMode="true"
Expanded="true"
Mode="@DrawerMode.Push"
SelectedItemChanged="((DrawerItem item) => SelectedItemChangedHandler(item))">
<Content>
<div class="main">
<div class="content px-4">
@Body
</div>
</div>
</Content>
</TelerikDrawer>
</div>
</div>
</TelerikRootComponent>
@code {
public TelerikDrawer<DrawerItem> Drawer { get; set; }
public DrawerItem SelectedItem { get; set; }
public IEnumerable<DrawerItem> Data { get; set; } =
new List<DrawerItem>
{
new DrawerItem { Text = "Item1", Icon = IconName.Inbox },
new DrawerItem { Text = "Item2", Icon = IconName.Information },
new DrawerItem { Text = "Item3", Icon = IconName.MarkerPin },
new DrawerItem { IsSeparator = true },
new DrawerItem { Text = "Item4", Icon = IconName.Inbox },
new DrawerItem { Text = "Item5", Icon = IconName.Inbox },
new DrawerItem { Text = "Toggle", Icon = IconName.ArrowChevronLeft, IsToggle = true },
};
protected override Task OnInitializedAsync()
{
SelectedItem = Data.First();
return base.OnInitializedAsync();
}
public class DrawerItem
{
public string Text { get; set; }
public string Icon { get; set; }
public bool IsSeparator { get; set; }
public bool IsToggle { get; set; }
}
private async Task SelectedItemChangedHandler(DrawerItem item)
{
SelectedItem = item;
if (item.IsToggle)
{
await Drawer.ToggleAsync();
if (Drawer.Expanded)
{
item.Icon = IconName.ArrowChevronRight;
}
else
{
item.Icon = IconName.ArrowChevronLeft;
}
}
}
}