Comments

mherchel created an issue. See original summary.

andy-blum’s picture

Status: Active » Needs review
StatusFileSize
new3.04 KB
new356.95 KB

Patch attached:

  • removes 'primary-nav__menu-item--has-children' class from items that aren't menu_level 0
  • removes data-drupal-selector="primary-nav-menu-item-has-children" from items that aren't menu_level 0
  • prevents rendering dropdown arrow button from menu items that aren't menu_level 0

Screenshot:
screenshot showing menu links in 3rd and 4th levels rendering without breaking dropdown function

mherchel’s picture

Huh. That actually doesn't look 100% horrible! Review incoming!

mherchel’s picture

StatusFileSize
new158.12 KB

Thank 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-selector elector from the nested submenu's <ul>
  • Null data-drupal-selector selector from the <li> (the value of that is removed in this patch, but the attribute name remains)
  • The data-drupal-selector selector from the <a> tag
  • The ID attribute from the nested <ul>

mherchel’s picture

Status: Needs review » Needs work
andy-blum’s picture

Status: Needs work » Needs review
StatusFileSize
new17.98 KB
new112.68 KB

New 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.

mherchel’s picture

Status: Needs review » Needs work

Looks like there's a lot of unrelated stuff in this patch. I'm seeing composer changes, and some php changes.

andy-blum’s picture

StatusFileSize
new16.48 KB

Weird. new patch attached. Interdiff seems good though.

andy-blum’s picture

Status: Needs work » Needs review
mherchel’s picture

Status: Needs review » Needs work

This is looking so good! Here are some requested changes.

+++ b/core/themes/olivero/css/components/navigation/nav-primary.pcss.css
@@ -164,6 +167,11 @@
+  & ul {

Lets use a BEM selector instead of nested ul. You can also do margin-block: 0 as 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...

andy-blum’s picture

Status: Needs work » Needs review
StatusFileSize
new17.55 KB
new1.93 KB

New patch with requested changes

gauravvvv’s picture

StatusFileSize
new17.01 KB
new2.36 KB

Fixed custom command failed, Re-rolled patch #11.
Attached interdiff for same.

gauravvvv’s picture

StatusFileSize
new2.36 KB
mherchel’s picture

StatusFileSize
new0 bytes
new8.44 KB
new209.91 KB
new280.01 KB

Made some significant changes, but here is some basic functionality for multi-level menus. I worked with @jwitkowski79 on the designs

andy-blum’s picture

Status: Needs review » Needs work

Your patch file is blank, mate.

mherchel’s picture

Status: Needs work » Needs review
StatusFileSize
new21.03 KB

Blah. New patch attached.

Tugboat link for the above at https://3225241-multi-level-submenus-rittwzvrxundmgcg5mck1uzo0q0rthwe.tu...

jwitkowski79’s picture

@mherchel Thanks for the preview link! Just a couple of small design updates please:

  1. Can we change the line-height of the 14px text in the subnav to 18px? I think 27px is too much...I'm reading it like another nav item, instead of a word wrap. When I change it in dev tools, it messes up some of the spacing though and I'd like to try to keep that intact.
  2. The height of the blue underline is inconsistent. Can we keep this the same? Let's use the taller one.
  3. Can we remove the vertical gray line after the 1st level? So it would appear for "Style Guide" but not appear for "Grid View" and "Comments".
  4. Can we change the children items to Black 2? I have that as #313637 but may have changed with the color updates you did in the front-end. I think this will help create more hierarchy
mherchel’s picture

Assigned: Unassigned » mherchel
Status: Needs review » Needs work
mherchel’s picture

I 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.

mherchel’s picture

StatusFileSize
new219.39 KB
new15.89 KB

This 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. )

mherchel’s picture

Status: Needs work » Needs review
andy-blum’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new63.65 KB
new104.68 KB

Patch 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

mherchel’s picture

Status: Reviewed & tested by the community » Needs work

Good catch! Yeah, we totally need to fix the duplicate IDs before committing.

andy-blum’s picture

Assigned: mherchel » andy-blum

Ah, 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.

andy-blum’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB
new16.54 KB

New patch builds the `aria_id` variable iteratively over menu levels ensuring items each have a unique id within the scope of the menu.

mherchel’s picture

Status: Needs review » Needs work
Issue tags: +JavaScript

The 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 if statements

Checking core/themes/olivero/js/second-level-navigation.es6.js

yarn run v1.22.5
$ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-build.js --check --file /var/www/html/core/themes/olivero/js/second-level-navigation.es6.js
[13:41:43] '/var/www/html/core/themes/olivero/js/second-level-navigation.es6.js' is being checked.
Done in 0.78s.

/var/www/html/core/themes/olivero/js/second-level-navigation.es6.js
  27:18  error  Parsing error: Unexpected token .

✖ 1 problem (1 error, 0 warnings)
andy-blum’s picture

Adding related core issue about updates to .eslintrc

nod_’s picture

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 ?.

  1. +++ b/core/themes/olivero/js/second-level-navigation.es6.js
    @@ -89,11 +89,11 @@
    +    button?.removeAttribute('aria-hidden');
    +    button?.removeAttribute('tabindex');
    

    This whole part seems like a delegated event listener would be a better solution instead of binding things individually like this.

  2. +++ b/core/themes/olivero/js/second-level-navigation.es6.js
    @@ -89,11 +89,11 @@
    +    el?.addEventListener(
    

    here el is checked, but not above in the el.querySelector().

  3. +++ b/core/themes/olivero/js/second-level-navigation.es6.js
    @@ -166,7 +166,7 @@
           const button = el.querySelector(
             '[data-drupal-selector="primary-nav-submenu-toggle-button"]',
           );
    -      const state = button.getAttribute('aria-expanded') === 'true';
    +      const state = button?.getAttribute('aria-expanded') === 'true';
     
           if (state) {
             subNavsAreOpen = true;
    

    this whole function might be refactorable with something like this maybe.

      function areAnySubNavsOpen() {
        return document.querySelector('[data-drupal-selector="primary-nav-menu-item-has-children"] [data-drupal-selector="primary-nav-submenu-toggle-button"][aria-expanded="true"]').length > 0;
      }
    
mherchel’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript
StatusFileSize
new6.37 KB

I'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.

mherchel’s picture

Status: Needs review » Needs work
mherchel’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB

This update fixes the nightwatch tests. The IDs have changed, so we need to fix the tests.

mherchel’s picture

Status: Needs review » Needs work
mherchel’s picture

Status: Needs work » Needs review
StatusFileSize
new7.7 KB
new633 bytes

More nightwatch ID changes to fix tests.

shaal’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

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.

shaal’s picture

I updated /admin/structure/block/manage/olivero_main_menu -> Menu Levels -> Number of levels to display
and 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.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Would it be possible to add tests for this on top of the pre-existing test coverage?

mherchel’s picture

Status: Needs review » Needs work

Yep.

mherchel’s picture

mherchel’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new9.66 KB
new2.4 KB

Tests!

Note that the only changes are adding of the tests.

andy-blum’s picture

Status: Needs review » Reviewed & tested by the community

#39 works perfectly, and we have the right pass/fail combo in the patches. Moving to RTBC!

  • lauriii committed 364ecc6 on 9.3.x
    Issue #3225241 by mherchel, andy-blum, Gauravmahlawat, shaal,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 364ecc6 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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