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

Issue #3246755 by mherchel, yogeshmpawar, Libbna, cindytwilliams, zenimagine:...

Issue #3246755 by mherchel, yogeshmpawar, Libbna, cindytwilliams, zenimagine: Olivero main/user account menu layout struggles with long menus
parent afd7bc29
Branches
Tags
37 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7471uncessary 5 files are moved from media-library folder to misc folder,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2719Issue #3110137: Remove Classy from core.,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -32,3 +32,13 @@ olivero_test.anchor_link:
url: "internal:#footer"
menu_name: main
weight: 200
olivero_test.long_item_1:
title: Long long long long
route_name: <front>
menu_name: main
weight: 200
olivero_test.long_item_2:
title: Long long long long
route_name: <front>
menu_name: main
weight: 200
......@@ -66,7 +66,7 @@ module.exports = {
.waitForElementVisible(headerNavSelector)
.assert.visible(headerNavSelector)
.assert.not.visible(`#${linkSubMenuId}`)
.moveToElement(`[aria-controls="${linkSubMenuId}"]`, 0, 0)
.moveToElement(`[aria-controls="${linkSubMenuId}"]`, 1, 1)
.assert.visible(`#${linkSubMenuId}`)
.assert.attributeEquals(
`[aria-controls="${linkSubMenuId}"]`,
......@@ -74,7 +74,7 @@ module.exports = {
'true',
)
.assert.not.visible(`#${buttonSubMenuId}`)
.moveToElement(`[aria-controls="${buttonSubMenuId}"]`, 0, 0)
.moveToElement(`[aria-controls="${buttonSubMenuId}"]`, 1, 1)
.assert.visible(`#${buttonSubMenuId}`)
.assert.attributeEquals(
`[aria-controls="${buttonSubMenuId}"]`,
......@@ -82,4 +82,17 @@ module.exports = {
'true',
);
},
'Verify desktop menu converts to mobile if it gets too long': (browser) => {
browser
.drupalRelativeURL('/node')
.waitForElementVisible('body')
.assert.not.elementPresent('body.is-always-mobile-nav')
.setWindowSize(1220, 800)
.execute(() => {
// Directly modify the width of the site branding name so that it causes
// the primary navigation to be too long, and switch into mobile mode.
document.querySelector('.site-branding__name').style.width = '350px';
}, [])
.assert.elementPresent('body.is-always-mobile-nav');
},
};
/**
* @file
* This script watches the desktop version of the primary navigation. If it
* wraps to two lines, it will automatically transition to a mobile navigation
* and remember where it wrapped so it can transition back.
*/
((Drupal, once) => {
/**
* Handles the transition from mobile navigation to desktop navigation.
*
* @param {Element} navWrapper - The primary navigation's top-level <ul> element.
* @param {Element} navItem - The first item within the primary navigation.
*/
function transitionToDesktopNavigation(navWrapper, navItem) {
document.body.classList.remove('is-always-mobile-nav');
// Double check to see if the navigation is wrapping, and if so, re-enable
// mobile navigation. This solves an edge cases where if the amount of
// navigation items always causes the primary navigation to wrap, and the
// page is loaded at a narrower viewport and then widened, the mobile nav
// may not be enabled.
if (navWrapper.clientHeight > navItem.clientHeight) {
document.body.classList.add('is-always-mobile-nav');
}
}
/**
* Callback from Resize Observer. This checks if the primary navigation is
* wrapping, and if so, transitions to the mobile navigation.
*
* @param {ResizeObserverEntry} entries - Object passed from ResizeObserver.
*/
function checkIfDesktopNavigationWraps(entries) {
const navItem = document.querySelector('.primary-nav__menu-item');
if (
Drupal.olivero.isDesktopNav() &&
entries[0].contentRect.height > navItem.clientHeight
) {
const navMediaQuery = window.matchMedia(
`(max-width: ${window.innerWidth + 15}px)`, // 5px adds a small buffer before switching back.
);
document.body.classList.add('is-always-mobile-nav');
// In the event that the viewport was resized, we remember the viewport
// width with a one-time event listener ,so we can attempt to transition
// from mobile navigation to desktop navigation.
navMediaQuery.addEventListener(
'change',
() => {
transitionToDesktopNavigation(entries[0].target, navItem);
},
{ once: true },
);
}
}
/**
* Set up Resize Observer to listen for changes to the size of the primary
* navigation.
*
* @param {Element} primaryNav - The primary navigation's top-level <ul> element.
*/
function init(primaryNav) {
const resizeObserver = new ResizeObserver(checkIfDesktopNavigationWraps);
resizeObserver.observe(primaryNav);
}
/**
* Initialize the automatic navigation transition.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attach context and settings for navigation.
*/
Drupal.behaviors.automaticMobileNav = {
attach(context) {
once(
'olivero-automatic-mobile-nav',
'[data-drupal-selector="primary-nav-menu--level-1"]',
context,
).forEach(init);
},
};
})(Drupal, once);
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
((Drupal, once) => {
function transitionToDesktopNavigation(navWrapper, navItem) {
document.body.classList.remove('is-always-mobile-nav');
if (navWrapper.clientHeight > navItem.clientHeight) {
document.body.classList.add('is-always-mobile-nav');
}
}
function checkIfDesktopNavigationWraps(entries) {
const navItem = document.querySelector('.primary-nav__menu-item');
if (Drupal.olivero.isDesktopNav() && entries[0].contentRect.height > navItem.clientHeight) {
const navMediaQuery = window.matchMedia(`(max-width: ${window.innerWidth + 15}px)`);
document.body.classList.add('is-always-mobile-nav');
navMediaQuery.addEventListener('change', () => {
transitionToDesktopNavigation(entries[0].target, navItem);
}, {
once: true
});
}
}
function init(primaryNav) {
const resizeObserver = new ResizeObserver(checkIfDesktopNavigationWraps);
resizeObserver.observe(primaryNav);
}
Drupal.behaviors.automaticMobileNav = {
attach(context) {
once('olivero-automatic-mobile-nav', '[data-drupal-selector="primary-nav-menu--level-1"]', context).forEach(init);
}
};
})(Drupal, once);
\ No newline at end of file
......@@ -214,6 +214,10 @@ navigation-primary:
js:
js/navigation.js: {}
js/second-level-navigation.js: {}
js/nav-resize.js: {}
dependencies:
- core/drupal
- core/once
navigation-secondary:
version: VERSION
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment