Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide menu-bar tooltip on overlay mouseleave to outside #7322

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -179,6 +179,7 @@ export const MenuBarMixin = (superClass) =>
constructor() {
super();
this.__boundOnContextMenuKeydown = this.__onContextMenuKeydown.bind(this);
this.__boundOnTooltipMouseLeave = this.__onTooltipOverlayMouseLeave.bind(this);
}

/**
Expand Down Expand Up @@ -624,6 +625,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 @@ -645,6 +651,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
Loading