Skip to content

Commit

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

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

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

/**
Expand Down
42 changes: 42 additions & 0 deletions packages/popover/test/timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ describe('timers', () => {
await nextUpdate(popover);
});

afterEach(() => {
Popover.setDefaultHoverDelay(0);
});

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

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

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

it('should open the overlay immediately on click', async () => {
popover.trigger = ['click'];
await nextUpdate(popover);
Expand Down Expand Up @@ -96,6 +109,10 @@ describe('timers', () => {
await nextUpdate(popover);
});

afterEach(() => {
Popover.setDefaultFocusDelay(0);
});

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

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

target.focus();
await nextUpdate(popover);
expect(overlay.opened).to.be.true;
});

it('should open the overlay immediately on click', async () => {
popover.trigger = ['click'];
await nextUpdate(popover);
Expand Down Expand Up @@ -141,6 +167,10 @@ describe('timers', () => {
await nextUpdate(popover);
});

afterEach(() => {
Popover.setDefaultHideDelay(0);
});

it('should close the overlay after a hide delay on mouseleave', async () => {
mouseenter(target);
await nextUpdate(popover);
Expand All @@ -162,6 +192,18 @@ describe('timers', () => {
expect(overlay.opened).to.be.false;
});

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

mouseenter(target);
await nextUpdate(popover);

mouseleave(target);
await nextUpdate(popover);
expect(overlay.opened).to.be.false;
});

it('should close the overlay immediately on Esc keydown', async () => {
target.focus();
await nextUpdate(popover);
Expand Down

0 comments on commit dae5efe

Please sign in to comment.