Menu item checkbox "Show as expanded" not working properly

Created on 17 May 2019, about 6 years ago
Updated 9 March 2023, about 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 1 day 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 about 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 about 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.

Production build 0.71.5 2024