Display of Hierarchical Taxonomy Menu child terms differs in Layout Builder and Block layout

Created on 30 March 2024, about 1 year ago
Updated 16 April 2024, 12 months ago

Problem/Motivation

Adding a Hierarchical Taxonomy Menu via Block layout enables the user to click on a parent term to reveal child terms.

Adding a Hierarchical Taxonomy Menu with the same settings via Layout Builder does not. When added via Layout Builder, clicking on the parent term goes directly to the taxonomy term page and does not reveal child terms.

Steps to reproduce

I'm using Drupal 10.2.4 and Hierarchical Taxonomy Menu 2.0.0.

Setup

1. Create a Vocabulary with two levels of taxonomy terms such as:

Vocabulary name: Colors

Terms:

  • Blue
    • Light blue
    • Dark blue
  • Green
    • Light green
    • Dark green

2. Edit the Basic page content type and on Manage display > Default > Layout options, select "Use Layout Builder" and "Allow each content item to have its layout customized."

3. Create a node using the Basic page content type.

Test 1 - Hierarchical Taxonomy Menu via Block layout:

Go to Structure > Block layout and place a Hierarchical Taxonomy Menu in the Content region for the new Basic page node and use the following settings (in "Basic settings"):

  • Use taxonomy terms from this vocabulary to create a menu: Colors
  • Number of sublevels to display: 1
  • Make the menu collapsed by default: Yes
  • Hide block if the output is empty: Yes

Save the block and view the node.

Test 1 Result:

The menu displays:

  • Blue
  • Green

Click on Blue. The menu displays:

  • Blue
    • Light blue
    • Dark blue
  • Green

Similarly, clicking on Green expands the menu and displays those child terms.

Perfect, that's exactly what I'm looking for.

Test 2 - Hierarchical Taxonomy Menu via Layout Builder:

Go to Structure > Block layout and remove the Hierarchical Taxonomy Menu in the Content region.

Go to the Basic page node and click on the "Layout" tab.

Click on "Add section" and add a section.

Click on "Add block." From the "Choose a block" menu, select "Hierarchical Taxonomy Menu."

In "Basic settings" use the same options as in Test 1:

  • Use taxonomy terms from this vocabulary to create a menu: Colors
  • Number of sublevels to display: 1
  • Make the menu collapsed be default: Yes
  • Hide block if the output is empty: Yes

Add the block, save the layout, and view the node.

Test 2 Result:

The menu displays:

  • Blue
  • Green

Clicking on either Blue or Green does not expand the menu. It goes directly to the taxonomy term page for each term. There's no indication that any child terms exist.

This is not the expected behavior.

Why do the same settings for Hierarchical Taxonomy Menu work differently in a block added via Block layout and a block added via Layout Builder?

I know I can add "Allow parent items to be collapsible and selectable" to the menu's basic settings to display a small arrow next to each term that has child terms, but the arrows are too small. I want people to be able to click on the term itself to expand the menu to show child terms, as it works using Block layout.

Proposed resolution

Enable the user to click on a parent term to reveal child terms when a Hierarchical Taxonomy Menu is added via Layout Builder, without using "Allow parent items to be collapsible and selectable," so it works as it does when added via Block layout.

Is there a way to do this?

πŸ› Bug report
Status

Fixed

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States camhoward New Hampshire, USA

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

Comments & Activities

  • Issue created by @camhoward
  • πŸ‡·πŸ‡ΈSerbia gnikolovski Subotica, Serbia
  • Assigned to gnikolovski
  • Status changed to Fixed about 1 year ago
  • πŸ‡·πŸ‡ΈSerbia gnikolovski Subotica, Serbia

    For some reason, when we use a block in the layout builder, the block configuration comes without the applied config scheme, so the values passed to JavaScript are not boolean but integer.

    I'm not sure if this is a problem with Drupal core/layout builder or something else, but for now, I have set the values going into JavaScript to be cast to boolean.

    @camhoward
    Can you try the dev version on your side to see if the issue has been resolved?
    You might need to clear the cache in Drupal and do a hard refresh (Ctrl + Shift + R in Chrome) in the browser you are using.

  • πŸ‡ΊπŸ‡ΈUnited States camhoward New Hampshire, USA

    @gnikolovski -- Thanks for the quick response, explanation, and fix.

    Yes, hierarchical_taxonomy_menu 2.0.x-dev, as updated on April 1, 2024, resolves the issue. The Hierarchical Taxonomy Menu now works the same way using the settings in my original post when added via Layout Builder and via Block layout.

    Thanks very much!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024