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(OnyxTooltip): auto align tooltip #1821

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ChristianBusshoff
Copy link

  • add auto alingment to the tooltip component
  • add screenshot-tests
  • add a demo on the homeView

@ChristianBusshoff ChristianBusshoff requested a review from a team as a code owner September 2, 2024 13:41
Copy link

changeset-bot bot commented Sep 2, 2024

⚠️ No Changeset found

Latest commit: dff028c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@BoppLi
Copy link
Contributor

BoppLi commented Sep 3, 2024

please adjust the PR title to the convention :)
feat(OnyxTooltip): auto align tooltip

the pattern is

  • feat/fix/chore
  • optional scope/component name in brackets
  • a short sentence describing the change, starting with an imperative verb :)

@MajaZarkova MajaZarkova self-assigned this Sep 3, 2024
@ChristianBusshoff ChristianBusshoff changed the title Feat/730 auto alignment tooltip feat(OnyxTooltip): auto align tooltip Sep 3, 2024
@@ -31,7 +30,7 @@ export const useOpenDirection = (element: MaybeRef<Element | undefined>) => {
if (!element) return undefined;

const style = getComputedStyle(element);
if (style.overflow === "hidden") {
if (style.overflow === "hidden" || style.overflow === "hidden auto") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (style.overflow === "hidden" || style.overflow === "hidden auto") {
if (style.overflow.includes(hidden)) {

/**
* How to align the tooltip relative to the parent element.
*/
align?: TooltipAlignment;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
align?: TooltipAlignment;
alignment?: TooltipAlignment;

In the OnyxSelect we currently call it alignment, would be great if we can keep it identical

Comment on lines +116 to +132
onMounted(() => {
const updateOnResize = () => {
updateOpenDirection();
updateWedgePosition();
};

window.addEventListener("resize", updateOnResize);

// initial update
updateOpenDirection();
updateWedgePosition();
});

onBeforeUnmount(() => {
window.removeEventListener("resize", updateOpenDirection);
window.removeEventListener("resize", updateWedgePosition);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
onMounted(() => {
const updateOnResize = () => {
updateOpenDirection();
updateWedgePosition();
};
window.addEventListener("resize", updateOnResize);
// initial update
updateOpenDirection();
updateWedgePosition();
});
onBeforeUnmount(() => {
window.removeEventListener("resize", updateOpenDirection);
window.removeEventListener("resize", updateWedgePosition);
});
const updateDirections = () => {
updateOpenDirection();
updateWedgePosition();
};
useGlobalEventListener({
type: "resize",
listener: () => updateDirections(),
});
// initial update
onMounted(() => updateDirections());

We have a utility from other @sit-onyx/headless package for this which already covers the unMounted / unmount part :)

Comment on lines +94 to +95
[`onyx-tooltip--align--${wedgePosition.value}`]: props.align === "auto",
[`onyx-tooltip--align--${props.align}`]: props.align !== "auto",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[`onyx-tooltip--align--${wedgePosition.value}`]: props.align === "auto",
[`onyx-tooltip--align--${props.align}`]: props.align !== "auto",
[`onyx-tooltip--${wedgePosition.value}`]: props.align === "auto",
[`onyx-tooltip--${props.align}`]: props.align !== "auto",

in BEM there is only 1 -- allowed, so we need to rename it e.g. like this

/**
* Recursively finds the first parent element with hidden overflow.
*/
const findParentWithHiddenOverflow = (element?: Element): Element | undefined => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is copied from the useOpenDirection composable, right? So we could export it there to not duplicate code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants