Hide sidebar dock on mobile

I would like to hide a sidebar dock on smaller screens but have it still visible on desktop. Is this possible? Thank you.


1 Reply 1 reply marked as answer

LD LeoLavanya Dhanaraj Syncfusion Team April 4, 2024 02:15 PM UTC

Hi Jan,


Greetings from Syncfusion support.


Based on the details you shared, we understand that you would like to hide the Dock Sidebar on mobile resolutions. Based on your requirement, we have prepared and shared the Blazor Dock Sidebar sample with the latest version.


In this sample, we have used a JSinterop call to determine whether it is in desktop or mobile mode and have set the value to false for the EnableDock and IsOpen properties within the Sidebar Created event.


KB link : https://www.syncfusion.com/faq/blazor/tips-and-tricks/how-do-you-detect-whether-a-page-is-loaded-in-mobile-or-on-desktop


Check out the below code snippets for reference.


[MainLayout.razor]

@inject IJSRuntime jsRuntime

<SfSidebar @ref="sidebarObj" ID="sidebar" @bind-IsOpen="SidebarToggle" EnableDock=@sidebarDock Created="onCreated">

</SfSidebar>

 

private bool mobile { get; set; }

private bool sidebarDock= true;

public async Task onCreated()

{

    mobile = await jsRuntime.InvokeAsync<bool>("isDevice");

    if (mobile)

    {

        sidebarDock = false;

        SidebarToggle = false;

    }

}

 

[_Layout.cshtml]

function isDevice() {

    var isMobile = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile/i.test(navigator.userAgent);

    return isMobile;

}


Refer to the attached sample and get back to us if you need any further assistance.


Regards,

Leo Lavanya Dhanaraj


Attachment: BlazorApp1_1d76cd2c.zip

Marked as answer
Loader.
Up arrow icon