Menu item checkbox "Show as expanded" not working properly

Created on 17 May 2019, about 6 years ago
Updated 9 March 2023, over 2 years ago

I have a main menu with 2 levels. If menu item on the first level doesn't have "Show as expanded" checkbox checked submenu items shouldn't be shown. This works fine only when this menu item parent is not active.
Let say that I have a menu structure like this:
- menu1
-- submenu1
-menu2
-- submenu2

If menu1 has "Show as expanded" unchecked and we are on the menu2 page, then submenu1 menu item will not be shown. But if we open the menu1 menu item, the submenu1 menu item is also shown, but it shouldn't be.

โœจ Feature request
Status

Active

Version

9.5

Component
Menu systemย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ธ๐Ÿ‡ฎSlovenia icurk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aaronpinero

    I'd like to see this issue reopened. I don't believe the original issue was solved in that, while the system may work as designed, it does not work as desired. The problem is that, the way it works now, menu option appears expanded when it is the currently selected item even if you have unchecked the "show as expanded" option in the menu link configuration. This is true even if in your menu block configuration you have unchecked the "expand all menu options" option. The only way to keep the selected menu option from showing as expanded is to restrict the menu levels. This makes it impossible to have a menu where you want one option to expand but another option to not expand.

    Here is my specific case:

    I have a main menu. Two of the options in the main menu have child menu options. I want one to expand and the other to not expand. In the menu configuration, I checked "show as expanded" for the first menu option and left this unchecked for the second menu option.

    For my menu block, I have configured it to show 2 levels to display and I have left the expand all menu links unchecked.

    The result is that everything works fine except when the second menu option is the select menu option. In that case, even though I have not configured the option to show as expanded, it shows as expanded anyway because it's the selected option.

    What I want is for this option to never show as expanded in this block, even if it's selected.

    This could be done by respecting the existing "show as expanded" configuration. Or, perhaps there could be a menu setting that determines if selected menu options appear expanded.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aaronpinero

    The original patch posted by @icurk didn't apply cleanly for me (I'm using Drupal 9.5.3) but I was able to update the patch to work. I will try to add this to the issue. The patch appears to resolve the issue for me in that the menu respects the unchecked "show as expanded" option even when the option is the currently selected option.

  • Status changed to Needs review over 2 years ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia BhumikaVarshney Delhi

    As per comment #13, I followed the same steps added for the specific case to reproduce the same.

    Created 2 menus

    Home
    -- home 1
    Home 3
    --home 4

    Home menu -> Checked Show as expanded
    Home 3 -> unchecked Show as expanded

    For my menu block, I have configured it to show 2 levels to display and I have left the expand all menu links unchecked.

    So after all this configuration, Second Menu is not expanded as expected in the feature request without applying any patch.
    I have attached the screenshot for all the configurations.

    Thank You!

  • Status changed to Needs work over 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    When the issue was reopened should of have been tagged with an issue summary update with why this should remain open and proposed solution.

    Also will need test coverage.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Nishant2312

    In accordance with Comment #13, I meticulously followed the provided steps to reproduce the issue.

    Here's a summary of the steps I took:

    1. I created two menus:
    - Menu 1:
    - Home
    - test
    - Menu 2:
    - Home 1
    - Home 1

    2. Within "Menu 1," I marked "Show as expanded," and in contrast, I unchecked "Show as expanded" for "Home 1" within "Menu 2."

    3. For my menu block configuration, I opted to display up to 2 levels and intentionally left the "Expand all menu links" option unchecked.

    Despite meticulously configuring the menus and the menu block, the behavior of the second menu did not expand as expected, aligning with the feature request. Your prompt assistance in resolving this matter is greatly appreciated. Thank you!

    As of now, it is working as designed and there is no need to apply the patch.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aaronpinero

    @Nishant2312 based on your description, I do not think you configured your menu correctly to illustrate the problem. Perhaps this could be better explained over a screen sharing session on Slack. I would be happy to schedule something if you feel it would be helpful.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    5 years ago this was closed as working as designed then re-opened as a feature. The reason for this feature should be added to the issue summary to help everyone who works on this issue.

    I tested this on Drupal 11.x today, standard install, using the steps in the issue summary. I was not able to reproduce the problem. Tagging this for steps to reproduce, and before and after screenshots.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada AaronChristian Kelowna, BC

    Tested the patch on Drupal 10.4.2. It applied cleanly, and it fixed the frontend. However when trying to edit any menus i received the following error:

    Drupal\Core\Database\InvalidQueryException: Query condition 'parent IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 108 of core/lib/Drupal/Core/Database/Query/Condition.php).
    

    I tried the other patch and got things to work along with a bit of extra twig logic.

    https://www.drupal.org/project/drupal/issues/3456536#comment-16000668 ๐Ÿ› show as expanded is forced to true if menu item has children and you are on child trail Active

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia anjalibarad

    Problem/Motivation

    Menu items in a two-level menu structure are expected to show or hide their submenus based on the "Show as expanded" checkbox in Drupal's menu settings.

    Expected behavior:

    If "Show as expanded" is unchecked for a first-level menu item, its submenus should not be visible at any time.

    Current behavior:

    If "Show as expanded" is unchecked, submenus are correctly hidden when their parent is not the active page.

    However, when the user navigates to the parent menu item, its submenus are still visible, even though "Show as expanded" is unchecked.

    This behavior is inconsistent with what the setting implies and leads to confusion in menu display control.

    Steps to reproduce

    • Create a menu with the following structure:
    • menu1
    • submenu1
    • menu2
    • submenu2

    I

    • n the menu settings, uncheck "Show as expanded" for both Menu 1 and Menu 2.
    • Visit a page linked to Menu 2 โ€” submenu 2 is correctly hidden.
    • Visit the page linked to Menu 1 โ€” submenu 1 is incorrectly shown, even though "Show as expanded" is unchecked.
    • Repeat for Menu 2 โ€” same behavior occurs.

    Proposed resolution

    Update the menu rendering logic to respect the "Show as expanded" setting regardless of whether the parent menu item is active or not.

    Suggested fix:
    Modify the logic that builds the visible menu tree so it does not automatically expand the submenus of an active parent unless "Show as expanded" is explicitly checked.

    This will align the behavior with user expectations and setting descriptions.

    Remaining tasks

    1. Identify the source of the logic that auto-expands submenus of active parents.
    2. Modify the logic to check if โ€œShow as expandedโ€ is enabled, and only then include submenus.
    3. Add unit or functional tests to confirm correct visibility behavior.
    4. Confirm that changes do not break other menu functionalities.
    5. Test multilingual and theme-based rendering overrides for compatibility.

    User interface changes

    None directly, unless admin UI is updated to clarify the behavior of the "Show as expanded" setting.

    Introduced terminology

    None

    API changes

    None expected unless the menu rendering APIs are modified to expose submenu visibility flags.

    Data model changes

    None.

    Release notes snippet

    In previous versions, submenus were shown even if "Show as expanded" was unchecked, provided their parent menu item was the active path. This has been fixed. Now, submenus only display if "Show as expanded" is checked, aligning with expected configuration behavior. Site builders should review their menu settings after this change.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States rgracia

    We are experiencing this bug with Drupal 11 and Site Studio. In our case, we have the menu item with children with the "show as expanded" unchecked as we don't want children to render in the menu for this item.

    We see the correct functionality until we navigate to the menu item url or any of its children (in the same active trail), where the parent item (the current url) is shown as expanded. This also is the case for any pages that are its children. Somehow the active trail ignored the unchecked "show as expanded" selection.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mortona2k Seattle

    Unchecking "Show item as expanded" does not prevent it from expanding. It just means that it's not expanded by default. Clicking on the menu item or it's active trail will still expand it.

    People are confusing this as a toggle for enabling/disabling expanding, when it is actually a toggle for whether or not to display when you're not in the active trail.

    It says that when checked it will always expand. It does not say that it will never expand when not checked.

    If selected and this menu link has children, the menu will always appear expanded. This option may be overridden for the entire menu tree when placing a menu block.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aaronpinero

    If this is going to be considered "works as designed", then the description should be updated so that it does not confuse users as to the purpose of the toggle.

    And also, if this is going to be considered "works as designed", then the feature request (as mentioned above) is to add a menu setting that determines if selected menu options appear expanded.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mortona2k Seattle

    And also, if this is going to be considered "works as designed", then the feature request (as mentioned above) is to add a menu setting that determines if selected menu options appear expanded.

    Agree the resolution here should be to clarify the setting.

    It's a bit tricky since people will see the menu item option separately from the menu block configuration.

    Can you clarify your suggestion? I'm not sure where you're saying it should go.

    Would it be an option to never expand the item, even if in the active trail?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States aaronpinero

    Yes, the feature request is to have an option, in the "Display Settings" of the menu link configuration, that would allow the site builder to set the menu option to never expand, even if the menu option is selected.

    I can see an argument for recommending that this be a feature added to Drupal with a contributed module rather than as a core Drupal function.

    Good point about the menu block configuration. And I have not given that part of it much thought. My first take is that the menu block configuration be allowed to override the proposed setting, just as it can override the existing "Show as Expanded" option.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mortona2k Seattle

    There is also the Menu Block module, which extends the SystemMenuBlock plugin and adds extra functionality. Not saying these features should not be in core, just pointing out the convention that's been around for a while.

    I like the idea of setting a "don't expand menu item" property on the menu link item, and allowing overriding in the block settings. However, there currently is no UI for adjusting settings for individual menu links within the block config. Would it just be for all links?

    Presumably the use case for this is when you have a main menu that you want some items to expand, but others will be shown differently, like a sidebar menu that renders the links that are hidden from the main menu. Alternatively, you could just make another menu.

    I encountered this debate on where to configure complex menu settings before. When using Menu Item Extras to make a mega menu, we add fields to menu items and configure the display of the top level links to be a dropdown panel with content and the sublinks.

    My UX/DX complaint with this is that making adjustments is clunky. To change content on a panel, you would edit the menu, then edit the menu link, then click the layout tab. Changing any menu display settings has to happen in the block config.

    What I would prefer is a way to jump from the front end straight to an interface where I can adjust all aspects of the menu structure and display.

    The disconnect is that we adjust the menu hierarchy in the menu settings, but the display of that hierarchy is split between the menu link checkbox and the menu block config.

    What if the menu did not dictate display settings at all, and that's handled entirely in the block display? This gets tricky. If a menu link is added or removed, the block config has to get updated to account for it.

    One in-between approach is to use a custom block with layout builder to create the menu. If there is a layout section for the menu container, the menu links and sub trees could be blocks placed in the layout, with additional settings on each one. We can't adjust the menu structure or create/delete links from within layout builder, but it would expose a ton of display options at different levels. For example, one top level link could be configured to display 2 levels, and another could display 5.

    Sorry for the long rant, I've been thinking about this for a while.

Production build 0.71.5 2024