Split off from #3221399: Olivero: Support more than two levels of menu in primary menu. .
We don't support more than two levels of nested menus in the primary menu, however if a site-builder does configure this, it should not break the menus.
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | 3225241-39-tests-only-FAIL.patch | 2.4 KB | mherchel |
| #39 | 3225241-39.patch | 9.66 KB | mherchel |
| #33 | interdiff-31-33.txt | 633 bytes | mherchel |
| #33 | 3225241-33.patch | 7.7 KB | mherchel |
| #31 | 3225241-31.patch | 7.08 KB | mherchel |
Comments
Comment #2
andy-blumPatch attached:
Screenshot:

Comment #3
mherchelHuh. That actually doesn't look 100% horrible! Review incoming!
Comment #4
mherchelThank you for working on this! I like the approach to remove the selectors from the list item. However, we should also remove the following:
data-drupal-selectorelector from the nested submenu's<ul>data-drupal-selectorselector from the<li>(the value of that is removed in this patch, but the attribute name remains)data-drupal-selectorselector from the<a>tagIDattribute from the nested<ul>Comment #5
mherchelComment #6
andy-blumNew patch here going the javascript route.
This will leave all the menu-level-based classes and selectors in place for any future subtheming efforts. Most of the patch is setting up optional chaining on HTMLElement methods & properties (getAttribute, setAttribute, classList, etc). There's also some styling changes so deeper menu levels look a bit more consistent.
Please test extensively on desktop & mobile menus, and make note of any javascript errors originating from second-level-navigation.js or styles that look off, but on my machine this seems pretty clean.
Comment #7
mherchelLooks like there's a lot of unrelated stuff in this patch. I'm seeing composer changes, and some php changes.
Comment #8
andy-blumWeird. new patch attached. Interdiff seems good though.
Comment #9
andy-blumComment #10
mherchelThis is looking so good! Here are some requested changes.
Lets use a BEM selector instead of nested
ul. You can also domargin-block: 0as a shortcut. I would also like us to be explicit about the left margin. Currently that margin is being added by the UA stylesheet.One other thing that we should handle is remove any aria attributes (and data-drupal-selector) if
menu_item_type == 'button'as seen on https://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/themes/olive...Comment #11
andy-blumNew patch with requested changes
Comment #12
gauravvvv commentedFixed custom command failed, Re-rolled patch #11.
Attached interdiff for same.
Comment #13
gauravvvv commentedComment #14
mherchelMade some significant changes, but here is some basic functionality for multi-level menus. I worked with @jwitkowski79 on the designs

Comment #15
andy-blumYour patch file is blank, mate.
Comment #16
mherchelBlah. New patch attached.
Tugboat link for the above at https://3225241-multi-level-submenus-rittwzvrxundmgcg5mck1uzo0q0rthwe.tu...
Comment #17
jwitkowski79 commented@mherchel Thanks for the preview link! Just a couple of small design updates please:
Comment #18
mherchelComment #19
mherchelI keep going down rabbit holes here. There's a number of styling issues (some regressions) that I've noticed.
Lets use this issue to fix the complete breaking of the menu, and then use #3221399: Olivero: Support more than two levels of menu in primary menu. to do some initial styling.
Comment #20
mherchelThis patch fixes the JavaScript, template (same as the patches above), but only makes one small change to the styling (which we will tackle in #3221399: Olivero: Support more than two levels of menu in primary menu. )
Comment #21
mherchelComment #22
andy-blumPatch works and moving to RTBC.
There is a slight issue I'm seeing but I'm pretty sure it's not something we want to address in this issue: menu items with the same link text lead to duplicate IDs in the markup.
Marking as RTBC unless @mherchel thinks this is something we need to fix in this issue
Comment #23
mherchelGood catch! Yeah, we totally need to fix the duplicate IDs before committing.
Comment #24
andy-blumAh, I see the source. This is coming from the line:
{% set aria_id = (item.title ~ '-submenu-' ~ loop.index )|clean_id %}This works fine when we don't support more than 1 submenu, but now we need to rethink this. We'll probably want to add a variable into the menu macro that we can append the value of loop.index onto. I'll work on this in the morning.
Comment #25
andy-blumNew patch builds the `aria_id` variable iteratively over menu levels ensuring items each have a unique id within the scope of the menu.
Comment #26
mherchelThe ID issue is resolved! Thanks for working on this!
However the Drupal.org tests aren't able to compile the resulting output with the optional chaining operator (even though it works locally). We'll need to convert those into
ifstatementsComment #27
andy-blumAdding related core issue about updates to .eslintrc
Comment #28
nod_haven't done a indepth review but the use of ?. feel like code-smell to me, i might be wrong but there is an opportunity for some refactor to avoid having to use ?.
This whole part seems like a delegated event listener would be a better solution instead of binding things individually like this.
here el is checked, but not above in the el.querySelector().
this whole function might be refactorable with something like this maybe.
Comment #29
mherchelI'm not opposed to refactoring, but I'd like to do it out of the scope of this issue (so we can move forward).
The twig changes alone solve the problem. I'm attaching an updated patch without the JavaScript changes. I opened up #3227592: Opportunity to refactor parts of Olivero's second-level-navigation JS as a followup to refactor.
Comment #30
mherchelComment #31
mherchelThis update fixes the nightwatch tests. The IDs have changed, so we need to fix the tests.
Comment #32
mherchelComment #33
mherchelMore nightwatch ID changes to fix tests.
Comment #34
shaalLGTM.
I tested on desktop and mobile, I created 3 levels menu.
There are no duplicate ids, and menu works well.
Thank you for creating the additional issues that will solve problems that are out of the scope of this issue.
Comment #35
shaalI updated
/admin/structure/block/manage/olivero_main_menu-> Menu Levels -> Number of levels to displayand set it to "Unlimited".
I was able to see all menu levels displayed. There's only 1 show/hide button that is added to the first level menu.
Comment #36
lauriiiWould it be possible to add tests for this on top of the pre-existing test coverage?
Comment #37
mherchelYep.
Comment #38
mherchelComment #39
mherchelTests!
Note that the only changes are adding of the tests.
Comment #40
andy-blum#39 works perfectly, and we have the right pass/fail combo in the patches. Moving to RTBC!
Comment #42
lauriiiCommitted 364ecc6 and pushed to 9.3.x. Thanks!