Skip to content

Commit

Permalink
fix: allow setting individual tooltip delays to 0 (#7707)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Aug 29, 2024
1 parent e35ae49 commit 62999e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/tooltip/src/vaadin-tooltip-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ class TooltipStateController {
/** @private */
get focusDelay() {
const tooltip = this.host;
return tooltip.focusDelay != null && tooltip.focusDelay > 0 ? tooltip.focusDelay : defaultFocusDelay;
return tooltip.focusDelay != null && tooltip.focusDelay >= 0 ? tooltip.focusDelay : defaultFocusDelay;
}

/** @private */
get hoverDelay() {
const tooltip = this.host;
return tooltip.hoverDelay != null && tooltip.hoverDelay > 0 ? tooltip.hoverDelay : defaultHoverDelay;
return tooltip.hoverDelay != null && tooltip.hoverDelay >= 0 ? tooltip.hoverDelay : defaultHoverDelay;
}

/** @private */
get hideDelay() {
const tooltip = this.host;
return tooltip.hideDelay != null && tooltip.hideDelay > 0 ? tooltip.hideDelay : defaultHideDelay;
return tooltip.hideDelay != null && tooltip.hideDelay >= 0 ? tooltip.hideDelay : defaultHideDelay;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions packages/tooltip/test/tooltip-timers.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('timers', () => {

afterEach(() => {
resetGlobalTooltipState();
Tooltip.setDefaultHoverDelay(0);
});

it('should open the overlay after a delay on mouseenter', async () => {
Expand All @@ -71,6 +72,14 @@ describe('timers', () => {
target.focus();
expect(overlay.opened).to.be.true;
});

it('should use the hover delay set to 0 and not the global delay', () => {
Tooltip.setDefaultHoverDelay(50);
tooltip.hoverDelay = 0;

mouseenter(target);
expect(overlay.opened).to.be.true;
});
});

describe('focusDelay', () => {
Expand All @@ -86,6 +95,7 @@ describe('timers', () => {

afterEach(() => {
resetGlobalTooltipState();
Tooltip.setDefaultFocusDelay(0);
});

it('should open the overlay after a delay on keyboard focus', async () => {
Expand All @@ -101,6 +111,15 @@ describe('timers', () => {
mouseenter(target);
expect(overlay.opened).to.be.true;
});

it('should use the focus delay set to 0 and not the global delay', () => {
Tooltip.setDefaultFocusDelay(50);
tooltip.focusDelay = 0;

tabKeyDown(document.body);
target.focus();
expect(overlay.opened).to.be.true;
});
});

describe('hideDelay', () => {
Expand All @@ -116,6 +135,7 @@ describe('timers', () => {

afterEach(() => {
resetGlobalTooltipState();
Tooltip.setDefaultHideDelay(0);
});

it('should close the overlay after a hide delay on mouseleave', async () => {
Expand All @@ -135,6 +155,15 @@ describe('timers', () => {
expect(overlay.opened).to.be.false;
});

it('should use the hide delay set to 0 and not the global delay', () => {
Tooltip.setDefaultHideDelay(50);
tooltip.hideDelay = 0;

mouseenter(target);
mouseleave(target);
expect(overlay.opened).to.be.false;
});

it('should close the overlay immediately on mousedown', () => {
tabKeyDown(document.body);
target.focus();
Expand Down

0 comments on commit 62999e5

Please sign in to comment.