2

I am trying to use this dropdown menu code from tailwindcss. I can hide the dropdown and show it on button press using the following code.

@if (menuOpen)
{
    ....
}

@code {
    bool menuOpen;

    void ToggleMenu()
    {
        menuOpen = !menuOpen;
        StateHasChanged();
    }
}

How to close the dropdown menu when the user clicks on something else on the site?

I tried to use onblur event but that prevents me from clicking on the menu items in the first place.

M. Azyoksul
  • 1,580
  • 2
  • 16
  • 43
  • https://stackoverflow.com/questions/70156540/it-possible-to-click-outside-an-element-to-close-it-on-blazor/70161538#70161538 – Mayur Ekbote Aug 12 '22 at 07:31
  • I'm trying to implement a working drop down menu in Blazor, and onblur is about the only thing that currently works for me. I've been following this answer to another question. https://stackoverflow.com/a/72165072/142914 – Bryan Aug 14 '22 at 09:36

0 Answers0