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: show tooltips when target is partially visible #5932

Merged
merged 1 commit into from
Jun 2, 2023
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
18 changes: 18 additions & 0 deletions packages/avatar/test/avatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fixtureSync, focusin, focusout, mousedown, nextFrame, oneEvent, tabKeyD
import sinon from 'sinon';
import '@vaadin/tooltip/vaadin-tooltip.js';
import '../vaadin-avatar.js';
import { Tooltip } from '@vaadin/tooltip';

describe('vaadin-avatar', () => {
let avatar, imgElement, iconElement, abbrElement;
Expand Down Expand Up @@ -192,6 +193,12 @@ describe('vaadin-avatar', () => {
describe('tooltip', () => {
let tooltip;

before(() => {
Tooltip.setDefaultFocusDelay(0);
Tooltip.setDefaultHoverDelay(0);
Tooltip.setDefaultHideDelay(0);
});

beforeEach(async () => {
avatar.withTooltip = true;
await nextFrame();
Expand Down Expand Up @@ -247,6 +254,17 @@ describe('vaadin-avatar', () => {
avatar.withTooltip = false;
expect(tooltip.parentNode).to.be.null;
});

it('should show tooltip when avatar is at the edge of a scroll container', () => {
const container = fixtureSync('<div></div>');
container.setAttribute('style', 'width: 100px; height: 100px; overflow: auto;');
container.appendChild(avatar);

const overlay = tooltip.shadowRoot.querySelector('vaadin-tooltip-overlay');
tabKeyDown(avatar);
avatar.focus();
expect(overlay.opened).to.be.true;
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/tooltip/src/vaadin-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
(entries) => {
entries.forEach((entry) => this.__onTargetVisibilityChange(entry.isIntersecting));
},
{ threshold: 1 },
{ threshold: 0 },
);

this._stateController = new TooltipStateController(this);
Expand Down
70 changes: 29 additions & 41 deletions packages/tooltip/test/tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,54 +480,42 @@ describe('vaadin-tooltip', () => {
await nextFrame();
});

describe('target is partially visible', () => {
beforeEach(async () => {
container.scrollTop = 220;
await waitForIntersectionObserver();
});

it('should open overlay when focused target is fully visible and hide otherwise', async () => {
tabKeyDown(target);
target.focus();
expect(overlay.opened).to.be.not.ok;

target.scrollIntoView({ block: 'center' });
await waitForIntersectionObserver();
expect(overlay.opened).to.be.true;

container.scrollTop = 0;
await waitForIntersectionObserver();
expect(overlay.opened).to.be.false;
});
beforeEach(async () => {
container.scrollTop = 220;
await waitForIntersectionObserver();
});

it('should open overlay when hovered target is fully visible and hide otherwise', async () => {
mouseenter(target);
expect(overlay.opened).to.be.not.ok;
it('should open overlay when focused target is partially visible and hide otherwise', async () => {
// Partially visible
tabKeyDown(target);
target.focus();
expect(overlay.opened).to.be.true;

target.scrollIntoView({ block: 'center' });
await waitForIntersectionObserver();
expect(overlay.opened).to.be.true;
// Fully visible
target.scrollIntoView({ block: 'center' });
await waitForIntersectionObserver();
expect(overlay.opened).to.be.true;

container.scrollTop = 0;
await waitForIntersectionObserver();
expect(overlay.opened).to.be.false;
});
// Fully hidden
container.scrollTop = 0;
await waitForIntersectionObserver();
expect(overlay.opened).to.be.false;
});

describe('target is fully visible', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this suite / test, as the test case should already be covered by the two previous tests.

beforeEach(async () => {
target.scrollIntoView({ block: 'center' });
await waitForIntersectionObserver();
});
it('should open overlay when hovered target is fully visible and hide otherwise', async () => {
// Partially visible
mouseenter(target);
expect(overlay.opened).to.be.true;

it('should hide overlay once the target is no longer visible', async () => {
mouseenter(target);
expect(overlay.opened).to.be.true;
// Fully visible
target.scrollIntoView({ block: 'center' });
await waitForIntersectionObserver();
expect(overlay.opened).to.be.true;

container.scrollTop = 0;
await waitForIntersectionObserver();
expect(overlay.opened).to.be.false;
});
// Fully hidden
container.scrollTop = 0;
await waitForIntersectionObserver();
expect(overlay.opened).to.be.false;
});
});

Expand Down