The DropDown Menu component does not have a property to programmatically close.

In my application I put a DropDown Menu as a column of an sfGrid, my problem happens when I drag the grid with the mouse scroll and the DropDown Menu is open it follows the grid visually breaking my application, I thought as a solution to close programmatically using the event @onwhell on the div but the component doesn't offer a property to be programmatically closed, how can I do that?

My code:



3 Replies

YA YuvanShankar Arunagiri Syncfusion Team July 5, 2023 02:04 PM UTC

Hi Leonardo,


Using the Toggle method of Dropdown Menu component, we can close the popup of dropdown menu component.


API link: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SplitButtons.SfDropDownButton.html#Syncfusion_Blazor_SplitButtons_SfDropDownButton_Toggle


Get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A



LS Leonardo Saraiva July 7, 2023 12:40 PM UTC

I used the toggle method to try to programmatically close the popup, I added it in a click event on the test button that I created. It turned out like this:




But instead of the click event closing the popup when it was open, what I left attached happened.




Is there another way to close it programmatically?



YA YuvanShankar Arunagiri Syncfusion Team July 10, 2023 01:36 PM UTC

Leonardo,


We have checked your reported query and the Toggle method is Opens/closes a Dropdown Button popup based on current state of the Dropdown Button. To resolve this issue, kindly refer to the below code snippet.


<SfDropDownButton @ref="DropdownBtn" Content="Profile">

    <DropDownButtonEvents OnOpen="OnOpen" OnClose="OnClose">

    </DropDownButtonEvents>

    <DropDownMenuItems>

        <DropDownMenuItem Text="Dashboard" Id="Dashboard"></DropDownMenuItem>

        <DropDownMenuItem Text="Notifications" Id="Notifications"></DropDownMenuItem>

        <DropDownMenuItem Text="User Settings" Id="UserSettings"></DropDownMenuItem>

        <DropDownMenuItem Text="Log Out" Id="LogOut"></DropDownMenuItem>

    </DropDownMenuItems>

</SfDropDownButton>

 

<SfButton OnClick="onClick">Close</SfButton>

 

@code {

    private bool canClose = false;

    SfDropDownButton DropdownBtn;

    private void OnOpen(BeforeOpenCloseMenuEventArgs args)

    {

        canClose = true;

    }

 

    private void OnClose(BeforeOpenCloseMenuEventArgs args)

    {

        canClose = false;

    }

 

    private void onClick()

    {

        if (canClose)

        {

            DropdownBtn.Toggle();

            canClose = false;

        }

    }

}



Get back to us if you need any further assistance on this. 


Loader.
Up arrow icon