Skip to content

Commit 7c1f0c1

Browse files
authored
fix: add support for delay properties to menu-bar tooltip (#4679)
1 parent 9590974 commit 7c1f0c1

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

‎dev/menu-bar.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
<body>
4040
<vaadin-menu-bar>
41-
<vaadin-tooltip slot="tooltip"></vaadin-tooltip>
41+
<vaadin-tooltip slot="tooltip" hover-delay="500" hide-delay="500"></vaadin-tooltip>
4242
</vaadin-menu-bar>
4343
</body>
4444
</html>

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from '@esm-bundle/chai';
22
import {
33
arrowDown,
44
arrowRight,
5+
aTimeout,
56
escKeyDown,
67
fire,
78
fixtureSync,
@@ -62,6 +63,14 @@ describe('menu-bar with tooltip', () => {
6263
expect(tooltip.opened).to.be.true;
6364
});
6465

66+
it('should use hover delay on menu button mouseover', async () => {
67+
tooltip.hoverDelay = 10;
68+
mouseover(buttons[0]);
69+
expect(tooltip.opened).to.be.false;
70+
await aTimeout(10);
71+
expect(tooltip.opened).to.be.true;
72+
});
73+
6574
it('should use the tooltip property of an item as tooltip', () => {
6675
mouseover(buttons[0]);
6776
expect(getTooltipText()).to.equal('Edit tooltip');
@@ -87,6 +96,15 @@ describe('menu-bar with tooltip', () => {
8796
expect(tooltip.opened).to.be.false;
8897
});
8998

99+
it('should use hide delay on menu button mouseleave', async () => {
100+
tooltip.hideDelay = 10;
101+
mouseover(buttons[0]);
102+
mouseleave(menuBar);
103+
expect(tooltip.opened).to.be.true;
104+
await aTimeout(10);
105+
expect(tooltip.opened).to.be.false;
106+
});
107+
90108
it('should hide tooltip on menu bar container mouseover', () => {
91109
mouseover(buttons[0]);
92110
mouseover(menuBar._container);
@@ -123,6 +141,13 @@ describe('menu-bar with tooltip', () => {
123141
expect(tooltip.opened).to.be.false;
124142
});
125143

144+
it('should not use hide delay on menu button mousedown', () => {
145+
tooltip.hideDelay = 10;
146+
mouseover(buttons[0]);
147+
mousedown(buttons[0]);
148+
expect(tooltip.opened).to.be.false;
149+
});
150+
126151
it('should not show tooltip on focus without keyboard interaction', async () => {
127152
buttons[0].focus();
128153
await nextRender();
@@ -135,6 +160,15 @@ describe('menu-bar with tooltip', () => {
135160
expect(tooltip.opened).to.be.true;
136161
});
137162

163+
it('should use focus delay on menu button keyboard focus', async () => {
164+
tooltip.focusDelay = 10;
165+
tabKeyDown(document.body);
166+
focusin(buttons[0]);
167+
expect(tooltip.opened).to.be.false;
168+
await aTimeout(10);
169+
expect(tooltip.opened).to.be.true;
170+
});
171+
138172
it('should not show tooltip on another parent menu button focus when open', async () => {
139173
buttons[0].focus();
140174
arrowRight(buttons[0]);
@@ -171,6 +205,14 @@ describe('menu-bar with tooltip', () => {
171205
expect(tooltip.opened).to.be.false;
172206
});
173207

208+
it('should not use hide delay on menu button Esc', () => {
209+
tooltip.hideDelay = 10;
210+
tabKeyDown(document.body);
211+
focusin(buttons[0]);
212+
escKeyDown(buttons[0]);
213+
expect(tooltip.opened).to.be.false;
214+
});
215+
174216
it('should set tooltip opened to false when the menuBar is removed', () => {
175217
mouseover(buttons[0]);
176218

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ export const InteractionsMixin = (superClass) =>
9797
/** @protected */
9898
disconnectedCallback() {
9999
super.disconnectedCallback();
100-
this._hideTooltip();
100+
this._hideTooltip(true);
101101
}
102102

103103
/**
104104
* @param {HTMLElement} button
105105
* @protected
106106
*/
107-
_showTooltip(button) {
107+
_showTooltip(button, isHover) {
108108
// Check if there is a slotted vaadin-tooltip element.
109109
const tooltip = this._tooltipController.node;
110110
if (tooltip && tooltip.isConnected) {
@@ -117,14 +117,22 @@ export const InteractionsMixin = (superClass) =>
117117
if (!this._subMenu.opened) {
118118
this._tooltipController.setTarget(button);
119119
this._tooltipController.setContext({ item: button.item });
120-
this._tooltipController.setOpened(true);
120+
121+
// Trigger opening using the corresponding delay.
122+
tooltip._stateController.open({
123+
hover: isHover,
124+
focus: !isHover,
125+
});
121126
}
122127
}
123128
}
124129

125130
/** @protected */
126-
_hideTooltip() {
127-
this._tooltipController.setOpened(false);
131+
_hideTooltip(immediate) {
132+
const tooltip = this._tooltipController.node;
133+
if (tooltip) {
134+
tooltip._stateController.close(immediate);
135+
}
128136
}
129137

130138
/** @protected */
@@ -246,7 +254,7 @@ export const InteractionsMixin = (superClass) =>
246254
this._close(true);
247255
}
248256

249-
this._hideTooltip();
257+
this._hideTooltip(true);
250258
}
251259

252260
/**
@@ -303,7 +311,7 @@ export const InteractionsMixin = (superClass) =>
303311
if (button === this._overflow || (this.openOnHover && button.item.children)) {
304312
this._hideTooltip();
305313
} else {
306-
this._showTooltip(button);
314+
this._showTooltip(button, true);
307315
}
308316
}
309317
}
@@ -373,7 +381,7 @@ export const InteractionsMixin = (superClass) =>
373381
},
374382
}),
375383
);
376-
this._hideTooltip();
384+
this._hideTooltip(true);
377385

378386
this._setExpanded(button, true);
379387
});

0 commit comments

Comments
 (0)