Skip to content
Snippets Groups Projects
Unverified Commit 364ecc6c authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3225241 by mherchel, andy-blum, Gauravmahlawat, shaal, jwitkowski79,...

Issue #3225241 by mherchel, andy-blum, Gauravmahlawat, shaal, jwitkowski79, nod_: Olivero primary menu JS completely breaks if site-builder specifies over 2 levels deep
parent 2c2da2b6
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,12 @@ olivero_test.child:
parent: olivero_test.front_page
menu_name: main
weight: 100
olivero_test.child_child:
title: Child link
route_name: <front>
parent: olivero_test.child
menu_name: main
weight: 100
olivero_test.button:
title: Button
route_name: <button>
......
const headerNavSelector = '#header-nav';
const linkSubMenuId = 'home-submenu-1';
const buttonSubMenuId = 'button-submenu-2';
const linkSubMenuId = 'primary-menu-item-1';
const buttonSubMenuId = 'primary-menu-item-12';
module.exports = {
'@tags': ['core', 'olivero'],
before(browser) {
browser.drupalInstall({
setupFile:
'core/tests/Drupal/TestSite/TestSiteOliveroInstallTestScript.php',
installProfile: 'minimal',
});
browser
.drupalInstall({
setupFile:
'core/tests/Drupal/TestSite/TestSiteOliveroInstallTestScript.php',
installProfile: 'minimal',
})
// Login and change max-nesting depth so we can verify that menu levels
// greater than 2 do not break the site.
.drupalLoginAsAdmin(() => {
browser
.drupalRelativeURL('/admin/structure/block/manage/olivero_main_menu')
.waitForElementVisible('[data-drupal-selector="edit-settings-depth"]')
.setValue('[data-drupal-selector="edit-settings-depth"]', 'Unlimited')
.click('[data-drupal-selector="edit-actions-submit"]')
.waitForElementVisible('body');
});
browser.resizeWindow(1600, 800);
},
after(browser) {
......@@ -32,7 +43,8 @@ module.exports = {
'aria-expanded',
'true',
)
// Verify tertiary menu item exists.
.assert.visible('#primary-menu-item-11 .primary-nav__menu-link--level-3')
// Test interactions for route:<button> menu links.
.assert.not.visible(`#${buttonSubMenuId}`)
.assert.attributeEquals(
......
const mobileNavButtonSelector = 'button.mobile-nav-button';
const headerNavSelector = '#header-nav';
const linkSubMenuId = 'home-submenu-1';
const buttonSubMenuId = 'button-submenu-2';
const linkSubMenuId = 'primary-menu-item-1';
const buttonSubMenuId = 'primary-menu-item-12';
/**
* Sends arbitrary number of tab keys, and then checks that the last focused
......
......@@ -314,6 +314,17 @@
}
}
/*
* Olivero doesn't officially support nested tertiary submenus, but this
* ensures that it doesn't break all the way.
*
* @see https://www.drupal.org/project/drupal/issues/3221399
*/
.primary-nav__menu--level-2 .primary-nav__menu-item--has-children {
display: block;
}
.primary-nav__menu-link--level-2 {
font-size: 1rem;
font-weight: normal;
......
......@@ -167,6 +167,16 @@
}
}
/*
* Olivero doesn't officially support nested tertiary submenus, but this
* ensures that it doesn't break all the way.
*
* @see https://www.drupal.org/project/drupal/issues/3221399
*/
.primary-nav__menu--level-2 .primary-nav__menu-item--has-children {
display: block;
}
.primary-nav__menu-link--level-2 {
font-size: 16px;
font-weight: normal;
......
......@@ -27,11 +27,12 @@
@see https://twig.symfony.com/doc/1.x/tags/macro.html
#}
{% set attributes = attributes.addClass('menu') %}
{{ menus.menu_links(items, attributes, 0) }}
{{ menus.menu_links(items, attributes, 0, 'primary-menu-item-') }}
{% macro menu_links(items, attributes, menu_level) %}
{% macro menu_links(items, attributes, menu_level, aria_id) %}
{% set primary_nav_level = 'primary-nav__menu--level-' ~ (menu_level + 1) %}
{% set drupal_selector_primary_nav_level = 'primary-nav-menu--level-' ~ (menu_level + 1) %}
{% set drupal_selector_primary_nav_level = menu_level <= 1 ? 'primary-nav-menu--level-' ~ (menu_level + 1) : false %}
{% set is_top_level_menu = menu_level == 0 %}
{% import _self as menus %}
{% if items %}
......@@ -73,21 +74,21 @@
]
%}
<li{{ item.attributes.addClass(item_classes).setAttribute('data-drupal-selector', item.below ? 'primary-nav-menu-item-has-children' : false) }}>
<li{{ item.attributes.addClass(item_classes).setAttribute('data-drupal-selector', is_top_level_menu and item.below ? 'primary-nav-menu-item-has-children': false) }}>
{#
A unique HTML ID should be used, but that isn't available through
Twig yet, so the |clean_id filter is used for now.
@see https://www.drupal.org/project/drupal/issues/3115445
#}
{% set aria_id = (item.title ~ '-submenu-' ~ loop.index )|clean_id %}
{% set aria_id = (aria_id ~ loop.index )|clean_id %}
{% set link_title %}
<span class="primary-nav__menu-link-inner">{{ item.title }}</span>
<span class="primary-nav__menu-link-inner primary-nav__menu-link-inner--level-{{ menu_level + 1 }}">{{ item.title }}</span>
{% endset %}
{% if menu_item_type == 'link' or menu_item_type == 'nolink' %}
{{ link(menu_item_type == 'link' ? link_title : item.title, item.url, {
'class': link_classes,
'data-drupal-selector': 'primary-nav-menu-link-has-children',
'data-drupal-selector': is_top_level_menu ? 'primary-nav-menu-link-has-children' : false,
})
}}
......@@ -97,36 +98,37 @@
but still visible in non-JS environments so that chevron can indicate presence of
drop menu).
#}
{%
set toggle_button_attributes = create_attribute({
{% if is_top_level_menu %}
{% set toggle_button_attributes = create_attribute({
'class': 'primary-nav__button-toggle',
'data-drupal-selector': 'primary-nav-submenu-toggle-button',
'aria-controls': aria_id,
'aria-expanded': 'false',
'aria-hidden': 'true',
'tabindex': '-1',
})
%}
<button{{ toggle_button_attributes }}>
<span class="visually-hidden">{{ '@title sub-navigation'|t({'@title': item.title}) }}</span>
<span class="icon--menu-toggle"></span>
</button>
}) %}
<button{{ toggle_button_attributes }}>
<span class="visually-hidden">{{ '@title sub-navigation'|t({'@title': item.title}) }}</span>
<span class="icon--menu-toggle"></span>
</button>
{% endif %}
{% set attributes = attributes.setAttribute('id', aria_id) %}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{{ menus.menu_links(item.below, attributes, menu_level + 1, aria_id) }}
{% endif %}
{% elseif menu_item_type == 'button' %}
{{ link(link_title, item.url, {
'class': link_classes,
'aria-controls': item.below ? aria_id : false,
'aria-expanded': item.below ? 'false' : false,
'data-drupal-selector': item.below ? 'primary-nav-submenu-toggle-button' : false,
})
}}
'aria-controls': is_top_level_menu and item.below ? aria_id : false,
'aria-expanded': is_top_level_menu and item.below ? 'false' : false,
'data-drupal-selector': is_top_level_menu and item.below ? 'primary-nav-submenu-toggle-button' : false,
}) }}
{% set attributes = attributes.setAttribute('id', aria_id) %}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{{ menus.menu_links(item.below, attributes, menu_level + 1, aria_id) }}
{% endif %}
</li>
{% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment