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
  • Loading branch information
web-padawan committed Apr 12, 2024
1 parent 97fce0a commit 5145c59
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-interactions-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const InteractionsMixin = (superClass) =>
constructor() {
super();
this.__boundOnContextMenuKeydown = this.__onContextMenuKeydown.bind(this);
this.__boundOnTooltipMouseLeave = this.__onTooltipOverlayMouseLeave.bind(this);
}

static get observers() {
Expand Down Expand Up @@ -114,6 +115,11 @@ export const InteractionsMixin = (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 @@ -135,6 +141,13 @@ export const InteractionsMixin = (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 5145c59

Please sign in to comment.