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

feat(tooltip): allow focusing and clicking on interactive elements within a tooltip #9914

Merged
merged 6 commits into from
Aug 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export default class TooltipManager {
const composedPath = event.composedPath();
const tooltip = this.queryTooltip(composedPath);

if (this.pathHasOpenTooltip(tooltip, composedPath)) {
this.clearHoverTimeout();
return;
}

this.closeTooltipIfNotActive(tooltip);

if (!tooltip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ describe("calcite-tooltip", () => {

describe("allows clicking on an open tooltip", () => {
const pageContent = html`
<calcite-tooltip placement="auto" reference-element="ref">content</calcite-tooltip>
<calcite-tooltip placement="auto" reference-element="ref">content <button>test</button></calcite-tooltip>
<button id="ref">referenceElement</button>
<button id="other">other</button>
`;
Expand All @@ -1147,6 +1147,11 @@ describe("calcite-tooltip", () => {
await page.waitForChanges();
expect(await tooltip.getProperty("open")).toBe(true);

const button = await page.find("button");
await button.click();
await page.waitForChanges();
expect(await tooltip.getProperty("open")).toBe(true);

await dispatchClickEvent(page, "#other");
expect(await tooltip.getProperty("open")).toBe(false);
});
Expand All @@ -1166,6 +1171,11 @@ describe("calcite-tooltip", () => {
await page.waitForChanges();
expect(await tooltip.getProperty("open")).toBe(true);

const button = await page.find("button");
await button.focus();
await page.waitForChanges();
expect(await tooltip.getProperty("open")).toBe(true);

const other = await page.find("#other");
await other.focus();
await page.waitForChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html } from "../../../support/formatting";
import { placements } from "../../utils/floating-ui";
import { boolean, modesDarkDefault } from "../../../.storybook/utils";
import { placeholderImage } from "../../../.storybook/placeholderImage";
import { Tooltip } from "./tooltip";

const contentHTML = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua`;
Expand Down Expand Up @@ -93,3 +94,11 @@ export const transparentBG_TestOnly = (): string => html`
<calcite-tooltip reference-element="reference-element" placement="auto" open> ${contentHTML} </calcite-tooltip>
</div>
`;

export const withInteractiveContent = (): string =>
html`<div style="width: 400px;">
${referenceElementHTML}
<calcite-tooltip reference-element="reference-element" placement="auto" open
><img width="100%" src="${placeholderImage({ width: 360, height: 90 })}" /> <p>${contentHTML}</p> <calcite-button>Click me</calcite-button
</calcite-tooltip>
</div>`;
Loading