Is it possible to close the hamburger menu when we click outside the menu container? Currently, we can close it only when we click on the hamburger menu icon.
Hi Vangel,
We need to validate and ensure more cases for your requirement. So, we will update details within February 14th,2022.
Regards,
Gayathri K
|
@inject IJSRuntime JS
<SfMenu @ref="MenuObj" TValue="MenuItem" HamburgerMode="true" ShowItemOnClick="true">
<MenuItems>
<MenuItem Text="Appliances"></MenuItem>
<MenuItem Text="Mobile"></MenuItem>
<MenuItem Text="Entertainment" Url="https://www.google.com/search?q=home+theatres"></MenuItem>
<MenuItem Text="Fashion" Url="https://www.google.com/search?q=fashion"></MenuItem>
<MenuItem Text="Offers" Url="https://www.google.com/search?q=offers"></MenuItem>
</MenuItems>
</SfMenu>
@code{
SfMenu<MenuItem> MenuObj;
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
var lDotNetReference = DotNetObjectReference.Create(this);
JS.InvokeVoidAsync("GLOBAL.SetDotnetReference", lDotNetReference);
}
}
[JSInvokable("HamburgerMenu")]
public void documentClick()
{
if (MenuObj != null)
{
MenuObj.CloseAsync();
StateHasChanged();
}
}
}
|
|
<body onclick="bodyClick(event)">
<script>
var GLOBAL = {};
GLOBAL.DotNetReference = null;
GLOBAL.SetDotnetReference = function (pDotNetReference) {
GLOBAL.DotNetReference = pDotNetReference;
};
function bodyClick(e) {
if (!document.querySelectorAll('.e-menu-header').length || !document.querySelectorAll('.e-menu-parent').length) {
return;
}
if(!e.target.classList.contains("e-menu-container") && e.target.closest('.e-menu-container') == null) {
if (GLOBAL.DotNetReference) {
GLOBAL.DotNetReference.invokeMethodAsync("HamburgerMenu", "documentClick");
}
}
}
</script>
</body> |
Thank you Gayathri, it works like a charm. This is trivial behavior for such a menu and I suppose this functionality will be integrated into the control.
Hi Vangel,
We are happy to hear your requirement has been fulfilled. We have analyzed this feature while implementing and this is the basic functionality of hamburger mode, so that we have provided this approach. If you need any further customization, the same is achievable in sample level.
Regards,
YuvanShankar A