diff --git a/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.ct.tsx b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.ct.tsx new file mode 100644 index 000000000..ba180b3b7 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.ct.tsx @@ -0,0 +1,78 @@ +import { expect, test } from "../../playwright/a11y"; +import type { Locator } from "@playwright/test"; +import { executeMatrixScreenshotTest } from "../../playwright/screenshots"; +import OnyxInfoTooltip from "./OnyxInfoTooltip.vue"; + +test("should trigger with hover", async ({ mount, page }) => { + // ARRANGE + let component = await mount(OnyxInfoTooltip, { + props: { + text: "Test tooltip", + }, + }); + + let tooltip = component.getByRole("tooltip"); + + // ASSERT + await expect(tooltip).toBeHidden(); + + // ACT + await component.hover(); + + // ASSERT + await expect(tooltip).toBeHidden(); // should use debounce to show tooltip only after a short delay + await expect(tooltip).toBeVisible(); + + await page.mouse.move(0, 0); + await expect(tooltip).toBeVisible(); // should use debounce to hide tooltip only after a short delay + await expect(tooltip).toBeHidden(); + + // ACT + await component.unmount(); + component = await mount(); + tooltip = component.getByRole("tooltip"); + + await page.keyboard.press("Tab"); + + // ASSERT + await expect(tooltip).toBeVisible(); + + // ACT + await page.keyboard.press("Escape"); + + // ASSERT + await expect(tooltip).toBeHidden(); +}); + +test.describe("Screenshot tests", () => { + const isTooltipVisible = async (tooltip: Locator) => { + await expect(tooltip).toBeVisible(); + }; + + executeMatrixScreenshotTest({ + name: "Info Tooltip", + columns: ["default", "long-text"], + rows: ["default", "bottom"], + component: (column, row) => { + return ( + + ); + }, + // set component size to fully include the tooltip + beforeScreenshot: async (component, page, _column, _row) => { + const tooltip = page.getByRole("tooltip"); + + // set paddings to fit the full tooltip in the screenshot + await component.evaluate((element) => { + element.style.padding = `3rem 5rem`; + }); + + await component.hover(); + + await isTooltipVisible(tooltip); + }, + }); +}); diff --git a/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.stories.ts b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.stories.ts new file mode 100644 index 000000000..d0ef5f536 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.stories.ts @@ -0,0 +1,35 @@ +import { defineStorybookActionsAndVModels } from "@sit-onyx/storybook-utils"; +import type { Meta, StoryObj } from "@storybook/vue3"; +import OnyxInfoTooltip from "./OnyxInfoTooltip.vue"; + +/** + * Info tooltips offer contextual information or additional details while hovering an info icon. + */ +const meta: Meta = { + title: "support/InfoTooltip", + ...defineStorybookActionsAndVModels({ + component: OnyxInfoTooltip, + events: [], + decorators: [ + (story) => ({ + components: { story }, + template: ` +
+ +
`, + }), + ], + }), +}; + +export default meta; +type Story = StoryObj; + +/** + * This example shows a default tooltip. + */ +export const Default = { + args: { + text: "Info tooltip text", + }, +} satisfies Story; diff --git a/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.vue b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.vue new file mode 100644 index 000000000..351c00030 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.vue @@ -0,0 +1,38 @@ + + + + + diff --git a/packages/sit-onyx/src/components/OnyxInfoTooltip/types.ts b/packages/sit-onyx/src/components/OnyxInfoTooltip/types.ts new file mode 100644 index 000000000..b0f374d4d --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxInfoTooltip/types.ts @@ -0,0 +1,3 @@ +import type { OnyxTooltipProps } from "../OnyxTooltip/types"; + +export type OnyxInfoTooltipProps = Pick; diff --git a/packages/sit-onyx/src/components/OnyxTextarea/OnyxTextarea.vue b/packages/sit-onyx/src/components/OnyxTextarea/OnyxTextarea.vue index 68dce5877..528ac415e 100644 --- a/packages/sit-onyx/src/components/OnyxTextarea/OnyxTextarea.vue +++ b/packages/sit-onyx/src/components/OnyxTextarea/OnyxTextarea.vue @@ -4,9 +4,7 @@ import { useDensity } from "../../composables/density"; import { useRequired } from "../../composables/required"; import { useCustomValidity } from "../../composables/useCustomValidity"; import OnyxSkeleton from "../OnyxSkeleton/OnyxSkeleton.vue"; -import OnyxTooltip from "../OnyxTooltip/OnyxTooltip.vue"; -import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; -import circleInformation from "@sit-onyx/icons/circle-information.svg?raw"; +import OnyxInfoTooltip from "../OnyxInfoTooltip/OnyxInfoTooltip.vue"; import type { OnyxTextareaProps } from "./types"; import { injectI18n } from "../../i18n"; @@ -108,11 +106,7 @@ const handleInput = (event: Event) => {
{{ props.label }} - - - + {{ t("optional") }}
@@ -149,16 +143,12 @@ const handleInput = (event: Event) => {