Skip to content

Commit 9c862fa

Browse files
authored
fix: hide menu-bar tooltip on overlay mouseleave to outside (#7322) (#7330)
1 parent 5ebe76e commit 9c862fa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

integration/tests/menu-bar-tooltip.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import sinon from 'sinon';
1515
import '@vaadin/menu-bar';
1616
import { Tooltip } from '@vaadin/tooltip';
17-
import { mouseleave } from '@vaadin/tooltip/test/helpers.js';
17+
import { mouseenter, mouseleave } from '@vaadin/tooltip/test/helpers.js';
1818

1919
export function mouseover(target) {
2020
fire(target, 'mouseover');
@@ -129,6 +129,14 @@ describe('menu-bar with tooltip', () => {
129129
expect(tooltip.opened).to.be.false;
130130
});
131131

132+
it('should hide tooltip on mouseleave from overlay to outside', () => {
133+
const overlay = tooltip._overlayElement;
134+
mouseover(buttons[0]);
135+
mouseenter(overlay);
136+
mouseleave(overlay);
137+
expect(overlay.opened).to.be.false;
138+
});
139+
132140
it('should not show tooltip on focus without keyboard interaction', async () => {
133141
buttons[0].focus();
134142
await nextRender();

packages/menu-bar/src/vaadin-menu-bar-interactions-mixin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const InteractionsMixin = (superClass) =>
3434
constructor() {
3535
super();
3636
this.__boundOnContextMenuKeydown = this.__onContextMenuKeydown.bind(this);
37+
this.__boundOnTooltipMouseLeave = this.__onTooltipOverlayMouseLeave.bind(this);
3738
}
3839

3940
static get observers() {
@@ -119,6 +120,11 @@ export const InteractionsMixin = (superClass) =>
119120
tooltip.generator = ({ item }) => item && item.tooltip;
120121
}
121122

123+
if (!tooltip._mouseLeaveListenerAdded) {
124+
tooltip._overlayElement.addEventListener('mouseleave', this.__boundOnTooltipMouseLeave);
125+
tooltip._mouseLeaveListenerAdded = true;
126+
}
127+
122128
if (!this._subMenu.opened) {
123129
this._tooltipController.setTarget(button);
124130
this._tooltipController.setContext({ item: button.item });
@@ -140,6 +146,13 @@ export const InteractionsMixin = (superClass) =>
140146
}
141147
}
142148

149+
/** @private */
150+
__onTooltipOverlayMouseLeave(event) {
151+
if (event.relatedTarget !== this._tooltipController.target) {
152+
this._hideTooltip();
153+
}
154+
}
155+
143156
/** @protected */
144157
_setExpanded(button, expanded) {
145158
button.toggleAttribute('expanded', expanded);

0 commit comments

Comments
 (0)