Unplanned
Last Updated: 06 Feb 2025 11:18 by ADMIN
Isaac
Created on: 30 Jan 2025 12:41
Category: Drawer
Type: Feature Request
1
Trigger Drawer Animation When Toggling Expanded

You can trigger the animation for the Drawer component by calling ToggleAsync() on the reference to the Drawer component:

<TelerikButton OnClick="@(async Task () => await DrawerRef!.ToggleAsync())" />

However, when you toggle the Expanded parameter instead, it still toggles the Drawer but does not trigger the animation:

<TelerikButton OnClick="@(() => Expanded = !Expanded)" />

As a result, if I want the Drawer component to be expanded by default, but I still want the user to be able to toggle it, I have to call ToggleAsync() on the reference to the component and bind the Expanded parameter, which is unnecessary verbose for such a common scenario:

<TelerikDrawer TItem="int" @ref="@DrawerRef" @bind-Expanded="@DrawerExpanded" Mode="@DrawerMode.Push">
	<Template>
		<NavMenu/>
	</Template>
	<DrawerContent>
		@Body
	</DrawerContent>
</TelerikDrawer>

@code
{
    private TelerikDrawer<int>? DrawerRef { get; set; }
    private bool DrawerExpanded { get; set; } = true;

    /// <remarks>
    /// We can't toggle DrawerExpanded because that won't trigger the animation.
    /// Only DrawerRef.ToggleAsync() triggers the animation.
    /// </remarks>
    private async Task ToggleDrawer() => await DrawerRef!.ToggleAsync();
}

I would like to trigger the animation for the Drawer component by toggling the Expanded parameter and not calling ToggleAsync() on the reference to the Drawer component. Toggling the Expanded parameter instead of calling a function on a reference to a component is a cleaner, simpler approach that better aligns with the philosophy of Blazor (using parameters rather than properties or functions on reference to components). Furthermore, this approach is used by various other Blazor component libraries such as MudBlazor, SyncFusion, and DevExpress. See:

1 comment
ADMIN
Nadezhda Tacheva
Posted on: 06 Feb 2025 11:18

Hi Isaac,

Your request is generally valid and I have updated its status. However, I will list some details on the current implementation.

Based on how the Blazor operates, a change in a parameter triggers a change in the server rendering. The animation, however, requires JavaScript to be performed. So, in order to achieve the behavior you are requesting, we have to ensure that a change in the Expanded parameter also changes the client rendering and invokes the JavaScript for the animation.

Our concern is that this contradicts to the Blazor principle. In fact, this is why we have exposed the ToggleAsync() method, so one can programmatically open and close the Drawer with the animation.

We will keep the request as "unplanned" for now as we want to track the community interest for such an approach. I must mention, though, that having the above mind it is likely that it will be with low priority also considering the not so major value that it may potentially bring to the product.

Regards,
Nadezhda Tacheva
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.