Skip to content

Commit

Permalink
feat(OnyxTooltip): auto align tooltip (#1821)
Browse files Browse the repository at this point in the history
- add auto alingment to the tooltip component
- add screenshot-tests
- add a demo on the homeView

Removed Tooltip-Error-Logic (hide tooltip before user interaction) in:
- OnyxCheckbox
- OnyxRadioButton
- OnyxSwitch

// hide error tooltip before a user interaction happened
.onyx-error-tooltip:has(&__input):not(:has(&__input:user-invalid))
.onyx-tooltip {
      display: none;
    }

---------

Co-authored-by: Chrisiboiii <[email protected]>
Co-authored-by: Maja Zarkova <[email protected]>
Co-authored-by: Chrisiboiii <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: ChristianBusshoff <[email protected]>
  • Loading branch information
6 people authored Oct 25, 2024
1 parent c2f8c11 commit e42ca5e
Show file tree
Hide file tree
Showing 65 changed files with 270 additions and 179 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-carrots-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sit-onyx": patch
---

Implement autoalignment feature for OnyxTooltip
32 changes: 29 additions & 3 deletions apps/demo-app/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,30 @@ const currentPage = ref(1);
label="Show toast"
@click="toast.show({ headline: 'Example toast', color: 'success' })"
/>
<OnyxHeadline is="h2">Tooltip (auto alignment)</OnyxHeadline>

<OnyxTooltip v-if="show('OnyxTooltip')" text="Example tooltip text">
Hover me to show tooltip
</OnyxTooltip>
<div v-if="show('OnyxTooltip')" class="tooltip-container">
<OnyxTooltip text="Example tooltip text">
<template #default="{ trigger }">
<OnyxButton label="Left" v-bind="trigger" />
</template>
</OnyxTooltip>
<OnyxTooltip text="Example tooltip text">
<template #default="{ trigger }">
<OnyxButton label="Center" v-bind="trigger" />
</template>
</OnyxTooltip>
<OnyxTooltip text="Example tooltip text">
<template #default="{ trigger }">
<OnyxButton label="Center" v-bind="trigger" />
</template>
</OnyxTooltip>
<OnyxTooltip text="Example tooltip text">
<template #default="{ trigger }">
<OnyxButton label="Right" v-bind="trigger" />
</template>
</OnyxTooltip>
</div>

<!-- Add new components alphabetically. -->
</div>
Expand Down Expand Up @@ -311,4 +331,10 @@ const currentPage = ref(1);
.state-info {
color: var(--onyx-color-text-icons-neutral-soft);
}
.tooltip-container {
display: flex;
justify-content: space-between;
width: 101%;
margin-top: 2rem;
}
</style>
1 change: 1 addition & 0 deletions packages/headless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./composables/comboBox/createComboBox";
export * from "./composables/helpers/useGlobalListener";
export * from "./composables/listbox/createListbox";
export * from "./composables/menuButton/createMenuButton";
export * from "./composables/navigationMenu/createMenu";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ test.describe("Screenshot tests", () => {
: "Test error";
return (
<OnyxCheckbox
style={row !== "default" ? "padding-top: 3rem;" : ""}
style={{
...(row !== "default" && { paddingBottom: "3rem" }),
...(column === "hideLabel" && { paddingRight: "3rem" }),
}}
label="Test label"
modelValue={column === "checked"}
indeterminate={column === "indeterminate"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ export const Required = {
...Default.args,
required: true,
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding: 2rem 0 0 2.5rem;">
<story />
</div>`,
}),
],
} satisfies Story;

/**
Expand Down Expand Up @@ -108,13 +99,4 @@ export const CustomError = {
longMessage: "Further explanation.",
},
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding: 2rem 0 0 5rem;">
<story />
</div>`,
}),
],
} satisfies Story;
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ const title = computed(() => {
max-width: var(--onyx-checkbox-input-size);
height: var(--onyx-checkbox-input-size);
}
// hide error tooltip before a user interaction happened
.onyx-error-tooltip:has(&__input):not(:has(&__input:user-invalid)) .onyx-tooltip {
display: none;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ test.describe("Screenshot tests", () => {
name: "CheckboxGroup",
columns: ["default", "checked", "indeterminate"],
rows: ["default", "interacted"],
component: (column) => {
component: (column, row) => {
const options = [...mockOptions, { label: "Invalid", value: 4, customError: "Invalid" }];
const modelValue: number[] = [];
if (column === "checked") {
Expand All @@ -128,7 +128,10 @@ test.describe("Screenshot tests", () => {
label="Checkbox group headline"
withCheckAll
modelValue={modelValue}
style={{ maxWidth: "16rem" }}
style={{
maxWidth: "16rem",
...(row === "interacted" && { paddingBottom: "3rem" }),
}}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ const meta: Meta<typeof OnyxCheckboxGroup> = {
argTypes: {
withCheckAll: { control: { type: "boolean" } },
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding-left: 1rem;">
<story />
</div>`,
}),
],
};

export default meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import OnyxFormElement from "./OnyxFormElement.vue";
*/
const meta: Meta<typeof OnyxFormElement> = {
title: "Support/FormElement",

component: OnyxFormElement,
argTypes: {
default: { control: { disable: true } },
},
decorators: [
(story) => ({
components: { story },
template: `<div style="max-width: 12rem; padding: 2rem 1rem">
template: `<div style="max-width: 12rem">
<story />
</div>`,
}),
Expand Down
18 changes: 0 additions & 18 deletions packages/sit-onyx/src/components/OnyxInput/OnyxInput.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ export const Maxlength: Story = {
minlength: 5,
withCounter: true,
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding: 0 0 4rem 4rem"> <story /> </div>`,
}),
],
};

/**
Expand Down Expand Up @@ -160,12 +154,6 @@ export const CustomError: Story = {
},
placeholder: "Interact with me to show error",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-bottom: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand All @@ -176,12 +164,6 @@ export const WithLabelTooltip: Story = {
label: "Label",
labelTooltip: "More information",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-top: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ test.describe("Screenshot tests", () => {
component.getByRole("tooltip"),
`should show error tooltip for ${row} and ${column}`,
).toBeVisible();

const tooltipSize = await component
.getByRole("tooltip")
.evaluate((element) => [element.clientHeight, element.clientWidth]);

// set paddings to fit the full tooltip in the screenshot
await component.evaluate(
(element, { tooltipSize: [height] }) => {
const verticalPadding = `${height + 12}px`;
element.style.paddingBottom = verticalPadding;
},
{ tooltipSize },
);
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,4 @@ export const Required = {
name: "radio-required",
required: true,
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding: 2rem 0 0 2.5rem;">
<story />
</div>`,
}),
],
} satisfies Story;
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ const skeleton = useSkeletonContext(props);
--onyx-radio-button-selector-background-color: var(--onyx-color-base-primary-400);
}
/**
* hide error tooltip if the radio button is valid.
* this happens when a radio group is required and one of the radio buttons is
* checked, the other ones will not update their validityState but will be
* recognized as "valid" by CSS
*/
.onyx-error-tooltip:has(&__selector:valid) .onyx-tooltip {
display: none;
}
&:has(&__selector:invalid) {
--onyx-radio-button-selector-border-color: var(--onyx-color-base-danger-500);
--onyx-radio-button-selector-outline-color: var(--onyx-color-base-danger-200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ export const Required = {
modelValue: undefined,
required: true,
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding-left: 2rem;">
<story />
</div>`,
}),
],
} satisfies Story;

/**
Expand All @@ -119,13 +110,4 @@ export const CustomError = {
longMessage: "Further explanation.",
},
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding-left: 2rem;">
<story />
</div>`,
}),
],
} satisfies Story;
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ export const WithMessage: Story = {
message: "Example message",
messageTooltip: "Additional info message",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-bottom: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand All @@ -134,12 +128,6 @@ export const WithLabelTooltip: Story = {
...Default.args,
labelTooltip: "More information",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-top: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test.describe("Screenshot tests", () => {
: "Test error";
return (
<OnyxSwitch
style={row !== "default" ? "padding-top: 3rem;" : ""}
style={row !== "default" ? "padding-bottom: 3rem;" : ""}
label="Test label"
modelValue={column === "checked"}
customError={customError}
Expand Down
18 changes: 0 additions & 18 deletions packages/sit-onyx/src/components/OnyxSwitch/OnyxSwitch.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ export const Required = {
...Default.args,
required: true,
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding: 2rem 0 0 1rem;">
<story />
</div>`,
}),
],
} satisfies Story;

/**
Expand Down Expand Up @@ -107,13 +98,4 @@ export const CustomError = {
longMessage: "Further explanation.",
},
},
decorators: [
(story) => ({
components: { story },
template: `
<div style="padding: 2rem 0 0 4rem;">
<story />
</div>`,
}),
],
} satisfies Story;
5 changes: 0 additions & 5 deletions packages/sit-onyx/src/components/OnyxSwitch/OnyxSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ $input-width: calc(2 * var(--onyx-switch-icon-size) - 2 * var(--onyx-switch-cont
color: var(--onyx-color-text-icons-neutral-soft);
}
}
// hide error tooltip before a user interaction happened
.onyx-error-tooltip:has(&__input):not(:has(&__input:user-invalid)) .onyx-tooltip {
display: none;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ export const CustomError: Story = {
},
placeholder: "Interact with me to show error",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-bottom: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand All @@ -156,12 +150,6 @@ export const WithLabelTooltip: Story = {
label: "Label",
labelTooltip: "More Information",
},
decorators: [
(story) => ({
components: { story },
template: `<div style="padding-top: 2rem"> <story /> </div>`,
}),
],
};

/**
Expand Down
Loading

0 comments on commit e42ca5e

Please sign in to comment.