Commit 2bfeadd1 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'fly-out-nav-hiding-fix' into 'master'

Fixes the fly-out navigation flashing in & out

Closes #37022

See merge request !13929
parents dceb2112 465813a2
...@@ -12,6 +12,7 @@ let sidebar; ...@@ -12,6 +12,7 @@ let sidebar;
export const mousePos = []; export const mousePos = [];
export const setSidebar = (el) => { sidebar = el; }; export const setSidebar = (el) => { sidebar = el; };
export const getOpenMenu = () => currentOpenMenu;
export const setOpenMenu = (menu = null) => { currentOpenMenu = menu; }; export const setOpenMenu = (menu = null) => { currentOpenMenu = menu; };
export const slope = (a, b) => (b.y - a.y) / (b.x - a.x); export const slope = (a, b) => (b.y - a.y) / (b.x - a.x);
...@@ -141,6 +142,14 @@ export const documentMouseMove = (e) => { ...@@ -141,6 +142,14 @@ export const documentMouseMove = (e) => {
if (mousePos.length > 6) mousePos.shift(); if (mousePos.length > 6) mousePos.shift();
}; };
export const subItemsMouseLeave = (relatedTarget) => {
clearTimeout(timeoutId);
if (!relatedTarget.closest(`.${IS_OVER_CLASS}`)) {
hideMenu(currentOpenMenu);
}
};
export default () => { export default () => {
sidebar = document.querySelector('.nav-sidebar'); sidebar = document.querySelector('.nav-sidebar');
...@@ -162,10 +171,7 @@ export default () => { ...@@ -162,10 +171,7 @@ export default () => {
const subItems = el.querySelector('.sidebar-sub-level-items'); const subItems = el.querySelector('.sidebar-sub-level-items');
if (subItems) { if (subItems) {
subItems.addEventListener('mouseleave', () => { subItems.addEventListener('mouseleave', e => subItemsMouseLeave(e.relatedTarget));
clearTimeout(timeoutId);
hideMenu(currentOpenMenu);
});
} }
el.addEventListener('mouseenter', e => mouseEnterTopItems(e.currentTarget)); el.addEventListener('mouseenter', e => mouseEnterTopItems(e.currentTarget));
......
---
title: Fixed fly-out nav flashing in & out
merge_request:
author:
type: fixed
...@@ -5,12 +5,14 @@ import { ...@@ -5,12 +5,14 @@ import {
canShowActiveSubItems, canShowActiveSubItems,
mouseEnterTopItems, mouseEnterTopItems,
mouseLeaveTopItem, mouseLeaveTopItem,
getOpenMenu,
setOpenMenu, setOpenMenu,
mousePos, mousePos,
getHideSubItemsInterval, getHideSubItemsInterval,
documentMouseMove, documentMouseMove,
getHeaderHeight, getHeaderHeight,
setSidebar, setSidebar,
subItemsMouseLeave,
} from '~/fly_out_nav'; } from '~/fly_out_nav';
import bp from '~/breakpoints'; import bp from '~/breakpoints';
...@@ -314,4 +316,29 @@ describe('Fly out sidebar navigation', () => { ...@@ -314,4 +316,29 @@ describe('Fly out sidebar navigation', () => {
).toBeTruthy(); ).toBeTruthy();
}); });
}); });
describe('subItemsMouseLeave', () => {
beforeEach(() => {
el.innerHTML = '<div class="sidebar-sub-level-items" style="position: absolute;"></div>';
setOpenMenu(el.querySelector('.sidebar-sub-level-items'));
});
it('hides subMenu if element is not hovered', () => {
subItemsMouseLeave(el);
expect(
getOpenMenu(),
).toBeNull();
});
it('does not hide subMenu if element is hovered', () => {
el.classList.add('is-over');
subItemsMouseLeave(el);
expect(
getOpenMenu(),
).not.toBeNull();
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment