Skip to content

Commit b71c274

Browse files
committed
menu: Always align the flyout caret with the menu item
1 parent c2abbb8 commit b71c274

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

public/css/icinga/menu.less

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
width: 14em;
260260
position: fixed;
261261
z-index: 1;
262+
margin-top: -1px; // Align content with the menu item, not its border
262263

263264
&::after {
264265
.transform(rotate(45deg));
@@ -271,14 +272,18 @@
271272
height: 1.1em;
272273
width: 1.1em;
273274
position: absolute;
274-
top: 1em;
275+
top: ~"calc((@{nav-item-height} / 2) - (1.1em / 2))";
275276
left: -.6em;
276277
z-index: -1;
277278
}
278279

279-
&.bottom-up::after {
280-
top: unset;
281-
bottom: 1em;
280+
&.bottom-up {
281+
--caretY: 100%;
282+
margin-top: 1px;
283+
284+
&::after {
285+
top: ~"calc(var(--caretY) - (@{nav-item-height} / 2) - (1.1em / 2))";
286+
}
282287
}
283288

284289
> .nav-item {
@@ -325,17 +330,13 @@
325330

326331
#layout:not(.minimal-layout) #menu .nav-level-1 > .nav-item:not(.active).hover {
327332
> .nav-level-2 {
328-
// Position relative to parent
329333
margin-left: 16em;
330-
margin-top: -3.167em;
331334
}
332335
}
333336

334337
#layout:not(.minimal-layout).sidebar-collapsed #menu .nav-level-1 > .nav-item.hover {
335338
> .nav-level-2 {
336-
// Position relative to parent
337339
margin-left: 4em;
338-
margin-top: -3.333em;
339340

340341
> .badge-nav-item {
341342
display: flex;

public/js/icinga/behavior/navigation.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,25 @@
319319
$target.siblings().not($target).removeClass('hover');
320320
$target.addClass('hover');
321321

322-
var targetHeight = $target.offset().top + $target.outerHeight();
323-
$flyout.css({
324-
bottom: 'auto',
325-
top: targetHeight
326-
});
327-
328-
var rect = $flyout[0].getBoundingClientRect();
322+
const targetRect = $target[0].getBoundingClientRect();
323+
const flyoutRect = $flyout[0].getBoundingClientRect();
324+
325+
const css = { "--caretY": "" };
326+
if (flyoutRect.bottom > window.innerHeight) {
327+
css.top = targetRect.bottom - flyoutRect.height;
328+
if (css.top < 10) {
329+
css.top = 10;
330+
// Not sure why -2, but it aligns the caret perfectly with the menu item
331+
css["--caretY"] = `${targetRect.bottom - 10 - 2}px`;
332+
}
329333

330-
if (rect.bottom > window.innerHeight) {
331334
$flyout.addClass('bottom-up');
332-
$flyout.css({
333-
bottom: window.innerHeight - targetHeight,
334-
top: 'auto'
335-
});
336335
} else {
337336
$flyout.removeClass('bottom-up');
337+
css.top = targetRect.top;
338338
}
339+
340+
$flyout.css(css);
339341
}, delay);
340342
};
341343

0 commit comments

Comments
 (0)