I have some code for a BlazorSidebar:
But what I want is that when one of the URLs in the sidebar is clicked, the sidebar toggles closed. I want the sidebar to close when I click a link, to reveal the full content of that clicked link's page. I have tried to do a
@code {
SfSidebar Sidebar;
public Orientation Orientation = Orientation.Horizontal;
public Orientation VerOrientation = Orientation.Vertical;
DictionaryHtmlAttribute = new Dictionary ()
{
{"class", "sidebar-menu" }
};
DictionaryTooltip = new Dictionary ()
{
{"title", "sidebar-menu" }
};
public List
new MenuItem {
Text = "Home",
IconCss ="oi oi-home",
Url = "/"
},
new MenuItem {
Text = "Customers",
IconCss = "oi oi-people",
Url = "PagePaths.CUSTOMERS"
},
new MenuItem {
Text = "Products",
IconCss = "oi oi-briefcase",
Url = "/products"
},
new MenuItem {
Text = "Discounts",
IconCss = "icon-tag icon",
Url = "/discount-setup"
},
new MenuItem {
Text = "Data Management",
IconCss = "oi oi-calculator",
Url = "/data",
Items = new List{
new MenuItem{ Text = "Daily Routes", Url = "/data?tab=daily-routes" },
new MenuItem{ Text = "Invoices", Url = "/data?tab=invoices" },
new MenuItem{ Text = "Acct Payments", Url = "/data?tab=acct-payments" },
new MenuItem{ Text = "Discrepancies", Url = "/data?tab=discrepancies" },
new MenuItem{ Text = "Customer Sales", Url = "/data?tab=customer-sales" }
}
},
new MenuItem {
Text = "Administration",
IconCss = "oi oi-graph",
Url = "/administration",
Items = new List{
new MenuItem{ Text = "Web Users", Url = "/administration?tab=web-users" },
new MenuItem { Separator = true },
new MenuItem{ Text = "Devices", Url = "/administration?tab=devices" },
new MenuItem{ Text = "Device Users", Url = "/administration?tab=device-users" },
new MenuItem { Separator = true },
new MenuItem{ Text = "Trucks", Url = "/administration?tab=trucks" },
new MenuItem{ Text = "Truck Routes", Url = "/administration?tab=truck-routes" },
new MenuItem { Separator = true },
new MenuItem{ Text = "Company Settings", Url = "/administration?tab=company-settings" },
new MenuItem{ Text = "Audit Log", Url = "/administration?tab=audit-log" }
}
}
};
public bool SidebarToggle = false;
public void Toggle()
{
SidebarToggle = !SidebarToggle;
}
private void onSelect(MenuEventArgsargs)
{
SidebarToggle = !SidebarToggle;
}
}
In your code example, line 64 of MainLayout.Razor:
<SfButton ID="toggle" @onclick="@Toggle" IsToggle="true" CssClass="e-btn e-info">Toggle Sidebar</SfButton>
This is the function I want for each MenuItem. When a MenuItem is clicked in the sidebar, I want the sidebar to close. For example, if I click "Administration" in the sidebar above, I want the sidebar to automatically slide closed because while the sidebar is open, it is hiding some of the Administration page content as shown in the picture above. I would like the sidebar to slide closed if I click any of the MenuItems in the sidebar. Thanks
Hello, this does not meet my requirement. From that link you provided:
"When that property is set as true, Sidebar will close, when clicking outside the sidebar region( any element in the document excluding Sidebar element and its inner content elements)."
However, to the contrary, I need the Sidebar to close when I click the MenuItem, which is an inner content element of the Sidebar. The CloseOnDocumentClick works to close the sidebar if I click somewhere outside of the Sidebar. What I want is to click a MenuItem
<SfSidebar @ref="sidebarObj" @bind-IsOpen="SidebarToggle">
<ChildContent>
<div id="listcontainer">
<SfMenu TValue="MenuItem" CssClass="custom_class" Orientation="Syncfusion.Blazor.Navigations.Orientation.Vertical">
<MenuEvents TValue="MenuItem" ItemSelected="ItemSelected" ></MenuEvents>
. . . </SfMenu>
</div>
</ChildContent>
</SfSidebar>
@code {
public void ItemSelected(Syncfusion.Blazor.Navigations.MenuEventArgs<MenuItem> args)
{
this.sidebarObj.Toggle();
}
} |
Thank you very much for your time and professionalism. I really appreciate it.
Hello again, I find that Toggle is not working, it says the method is deprecated and I should use IsOpen instead. But that does not work either. Just to remind you, this is how my code is now, and I want the sidebar to close (still showing dock though) when one of these MainMenuItems is clicked.