Skip to content

Commit

Permalink
fix: hide menu-bar tooltip on overlay mouseleave to outside (#7322) (#…
Browse files Browse the repository at this point in the history
…7326)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Apr 12, 2024
1 parent 0ed023e commit fa01489
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion integration/tests/menu-bar-tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import sinon from 'sinon';
import '@vaadin/menu-bar';
import { Tooltip } from '@vaadin/tooltip';
import { mouseleave } from '@vaadin/tooltip/test/helpers.js';
import { mouseenter, mouseleave } from '@vaadin/tooltip/test/helpers.js';

export function mouseover(target) {
fire(target, 'mouseover');
Expand Down Expand Up @@ -129,6 +129,14 @@ describe('menu-bar with tooltip', () => {
expect(tooltip.opened).to.be.false;
});

it('should hide tooltip on mouseleave from overlay to outside', () => {
const overlay = tooltip._overlayElement;
mouseover(buttons[0]);
mouseenter(overlay);
mouseleave(overlay);
expect(overlay.opened).to.be.false;
});

it('should not show tooltip on focus without keyboard interaction', async () => {
buttons[0].focus();
await nextRender();
Expand Down
13 changes: 13 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const MenuBarMixin = (superClass) =>
constructor() {
super();
this.__boundOnContextMenuKeydown = this.__onContextMenuKeydown.bind(this);
this.__boundOnTooltipMouseLeave = this.__onTooltipOverlayMouseLeave.bind(this);
}

/**
Expand Down Expand Up @@ -592,6 +593,11 @@ export const MenuBarMixin = (superClass) =>
tooltip.generator = ({ item }) => item && item.tooltip;
}

if (!tooltip._mouseLeaveListenerAdded) {
tooltip._overlayElement.addEventListener('mouseleave', this.__boundOnTooltipMouseLeave);
tooltip._mouseLeaveListenerAdded = true;
}

if (!this._subMenu.opened) {
this._tooltipController.setTarget(button);
this._tooltipController.setContext({ item: button.item });
Expand All @@ -613,6 +619,13 @@ export const MenuBarMixin = (superClass) =>
}
}

/** @private */
__onTooltipOverlayMouseLeave(event) {
if (event.relatedTarget !== this._tooltipController.target) {
this._hideTooltip();
}
}

/** @protected */
_setExpanded(button, expanded) {
button.toggleAttribute('expanded', expanded);
Expand Down

0 comments on commit fa01489

Please sign in to comment.