# Menu collapse/auto hide after select

**URL:** <https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587>\
**Category:** Radzen Blazor Studio\
**Created:** [March 27, 2023, 4:13pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587 "2023-03-27T16:13:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad](https://forum.radzen.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://forum.radzen.com/u/Chad)\
**Post date:** [March 27, 2023, 4:13pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/1 "2023-03-27T16:13:00Z")

</div>

Is there a way to have the menu collapse after select at a certain width and below? (or some may want it to always collapse?)

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 28, 2023, 2:28am UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/2 "2023-03-28T02:28:13Z")

</div>

Hi @Chad,

You can handle the Click event of the RadzenPanelMenu in the MainLyout of your app and set the `sidebarExpanded` field to `false`. This should collapse the sidebar whenever the user clicks on a panel menu item.

 ![image](https://forum.radzen.com/uploads/default/original/2X/3/3e475cf52bd16ec4414ee53af2ecc5bb8a43e52d.png)

---

<div class="post-metadata">

**Author:** ![Chad](https://forum.radzen.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://forum.radzen.com/u/Chad)\
**Post date:** [March 28, 2023, 3:26pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/3 "2023-03-28T15:26:55Z")

</div>

New method isn't firing...

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 28, 2023, 3:29pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/4 "2023-03-28T15:29:01Z")

</div>

I am not sure what this means.

---

<div class="post-metadata">

**Author:** ![Chad](https://forum.radzen.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://forum.radzen.com/u/Chad)\
**Post date:** [March 28, 2023, 3:31pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/5 "2023-03-28T15:31:28Z")

</div>

I added a new method as you suggested.

It doesn't work, when I set a breakpoint inside the method, it does not hit that breakpoint in debug mode.

It does not seem to be recognizing the click event.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [March 28, 2023, 3:32pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/6 "2023-03-28T15:32:58Z")

</div>

Did you handle the Click event of RadzenPanelMenu? Adding the method won't do anything on its own.

---

<div class="post-metadata">

**Author:** ![Chad](https://forum.radzen.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://forum.radzen.com/u/Chad)\
**Post date:** [March 28, 2023, 3:40pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/7 "2023-03-28T15:40:39Z")

</div>

Have it working now, thank you.

Is it possible to have the behavior be different based on width or device?

Hide on mobile, but not on desktop

---

<div class="post-metadata">

**Author:** ![Chad](https://forum.radzen.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://forum.radzen.com/u/Chad)\
**Post date:** [December 8, 2023, 5:52pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/8 "2023-12-08T17:52:39Z")

</div>

Is it possible to have the behavior be different based on width or device?

Hide on mobile, but not on desktop

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [December 8, 2023, 5:54pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/9 "2023-12-08T17:54:59Z")

</div>

I don't know of such a way.

---

<div class="post-metadata">

**Author:** ![jfmt](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfmt](https://forum.radzen.com/u/jfmt)\
**Post date:** [November 12, 2024, 10:09pm UTC](https://forum.radzen.com/t/menu-collapse-auto-hide-after-select/13587/10 "2024-11-12T22:09:38Z")

</div>

The only way to resolve this at the moment is to add a script to main layout to return the window width, then add a method like "PanelMenuItemClick" to the Razor page's code (and assign every RadzenPanelMenuItem's Click event to this method), get that method to call the JS runtime and if the window width is equal to or less than 768 (I think?) then collapse the sidebar.

Along these lines but without the BrowserDimension object, just get the JS to return an int for window width \>\> [How to get the window width in blazor - Stack Overflow](https://stackoverflow.com/a/65378381)
