How to toggle drawer OnClick from another razor file?

1 Answer 43 Views
Drawer
Otemu
Top achievements
Rank 1
Otemu asked on 14 Feb 2024, 05:23 PM

Hello,

Am trying to toggle the drawer component from a separate razor file.

I have two razor files in the following directories:

\Components\Layout\SiteHeader\SiteHeader.razor

\Components\Pages\Home.razor

If Home.razor contains the default Drawer code:

@* This example shows the basic configuration of the Drawer and how to expand or collapse a Drawer with a click of a button. *@

<TelerikButton OnClick="@(() => DrawerRef.ToggleAsync())"
               Icon="@SvgIcon.Menu">
    Toggle drawer
</TelerikButton>

<TelerikDrawer Data="@Data" Mode="@DrawerMode.Push"
               @ref="@DrawerRef">
    <DrawerContent>lorem ipsum</DrawerContent>
</TelerikDrawer>

@code {
    Telerik.Blazor.Components.TelerikDrawer<DrawerItem> DrawerRef { get; set; }

    IEnumerable<DrawerItem> Data { get; set; } =
        new List<DrawerItem>
            {
            new DrawerItem { Text = "Counter", Icon = SvgIcon.Plus },
            new DrawerItem { Text = "FetchData", Icon = SvgIcon.GridLayout },
            };

    public class DrawerItem
    {
        public string Text { get; set; }
        public ISvgIcon Icon { get; set; }
    }
}

If however I waned to move only the button portion to the SiteHeader.razor file

<TelerikButton OnClick="@(() => DrawerRef.ToggleAsync())"
               Icon="@SvgIcon.Menu">
    Toggle drawer
</TelerikButton>

How can I get access to the 

DrawerRef

So that I can toggle from  SiteHeader.razor 

Is this possible?

Thanks

Any help be appreciated

Thanks

1 Answer, 1 is accepted

Sort by
0
Hristian Stefanov
Telerik team
answered on 19 Feb 2024, 04:04 PM

Hi Otemu,

Here is an example I have prepared for you that demonstrates how to access the Drawer's reference within another separate razor file: REPL link.

Let me know if this is what you are looking for.

Regards,
Hristian Stefanov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Otemu
Top achievements
Rank 1
commented on 20 Feb 2024, 09:49 AM

Hi Hristian,

Great this is perfect 

Tags
Drawer
Asked by
Otemu
Top achievements
Rank 1
Answers by
Hristian Stefanov
Telerik team
Share this question
or