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

refactor: tooltips using CSS solution to JS solution #639

Merged
merged 64 commits into from Nov 30, 2021

Conversation

sshanzel
Copy link
Member

@sshanzel sshanzel commented Oct 8, 2021

DD-229 #done

After so many trials and errors, I have finally found a workaround in making the tests not fail while using the tooltip libraries that we have listed as our option on our confluence page.

When you literally implement a sample code utilizing the tooltip library, the tests would suddenly fail relating to just rendering some components that weren't even touched by the sample code (kindly check the wip commits).

But we were persistent, we want to switch from CSS to JS solution for tooltips. Thankfully we have the dynamicParent to load packages conditionally. In this case, I had to switch off the loading of the actual tooltip library since by just literally loading it, rendering tests would fail.

Would switching the tooltip library off on test env affect the desired result for existing tests cases? No, since the important part in finding the actual element in test cases, is the aria-label attribute, which we automatically apply on every element wrapped by our dynamic Tooltip component, regardless of whether we load the actual tooltip library or not.

Note: it can be noticed that there are two ways to implement the tooltip, one is using the actual wrapper that has dynamicParent. The second one uses a ref object to identify the trigger element.

The reason for the second one is due to next/link has an existing issue when wrapping a custom component, so when we use the tooltip as a child and wrap the actual content of the next/link, it will not work. We have to use its reference to identify the trigger of the actual tooltip. Thankfully, the library we are using supports it out of the box.

vercel/next.js#7915

Happy reviewing!

@sshanzel sshanzel marked this pull request as draft October 8, 2021 07:14
@sshanzel
Copy link
Member Author

@idoshamun I have now created another component to abstract the complexity of working with next/link. I have also minimized the required parameters for the tooltips to make it very simple and approachable (left with 3 parameters: children, content, and placement itself).

@rebelchris I have applied the necessary optimizations, thank you so much for the info.

Thank you both for the kinds words and the awesomest of reviews! This should be ready for another round now.

Copy link
Member Author

@sshanzel sshanzel left a comment

Choose a reason for hiding this comment

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

Just ran a personal review and pushed commits to make things more uniform, this should be ready for review 🚀

Copy link
Contributor

@rebelchris rebelchris left a comment

Choose a reason for hiding this comment

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

Wow nice work @sshanzel I have one question open.
But should not be a blocker, it's more a "wishlist" item.

@@ -91,17 +93,14 @@ export default function MainLayout({
: 'non-responsive-header'
}`}
>
<Link
<LinkWithTooltip
Copy link
Contributor

Choose a reason for hiding this comment

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

Just throwing this one out here:
Is there no way to have the SimpleTooltip determine if the direct child is a <Link> and then do something else?

Think it would be super cool if we could just have 1 sole component for the tooltip usage.

If it's not possible, this seems like a good first step!

Copy link
Member Author

@sshanzel sshanzel Nov 26, 2021

Choose a reason for hiding this comment

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

Thank you for the review! 🚢

That's a cool idea. Though the part where it got me separating the two is the way we will be handling the trigger element itself. The other one, we will be wrapping the children, and the other one will be utilizing the ref of the actual element since next/link has problems with accepting custom components.

Combining them in a single component might provide quite a bit of complexity (as having multiple conditions whether to apply a ref or not). To keep things simple and easier to understand for each scenario, I had separated them.

Copy link
Member

@idoshamun idoshamun left a comment

Choose a reason for hiding this comment

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

Wow! A few more comments and we can finally merge this one :)


return (
<TippyTooltip
shouldLoad={getShouldLoadTooltip()}
Copy link
Member

Choose a reason for hiding this comment

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

I think that instead of shouldLoad, we can add an if statement at the beginning and if should load is false we can return an empty element.
Something like:

if (!shouldLoad) {
  return <></>;
}

What do you think?

Copy link
Member Author

@sshanzel sshanzel Nov 30, 2021

Choose a reason for hiding this comment

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

That is a good idea. With that, I tried rendering the children only if shouldLoad is false (since it is necessary to be displayed), but tests started failing again even though it still has the aria-label. I also implemented a dynamic rendering since it is optional but it seems to crash again on tests.

@idoshamun
Copy link
Member

Doing some manual QA I found an issue with the new tooltip when hovering on the menu button
image

@sshanzel
Copy link
Member Author

@idoshamun I have now fixed the clash between the classes of arrows in the tooltip popup. This should be ready for a round of review. I am super excited about the profile tooltip! 🚢

@sshanzel
Copy link
Member Author

sshanzel commented Nov 30, 2021

Different placements of the actual tooltips:

Screen Shot 2021-11-30 at 3 33 37 PM
Screen Shot 2021-11-30 at 3 32 23 PM
Screen Shot 2021-11-30 at 3 32 20 PM
)
Screen Shot 2021-11-30 at 3 32 17 PM

@sshanzel
Copy link
Member Author

Light mode:
Screen Shot 2021-11-30 at 3 35 05 PM
Screen Shot 2021-11-30 at 3 34 57 PM
Screen Shot 2021-11-30 at 3 34 50 PM
Screen Shot 2021-11-30 at 3 34 47 PM

Copy link
Member

@idoshamun idoshamun left a comment

Choose a reason for hiding this comment

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

Ship it! 🚢

@sshanzel
Copy link
Member Author

WOOOO! I didn't enable the auto-merge so I can feel the green button on this! 🚀

Thank you for the awesome reviews to you both! 🚢

@sshanzel sshanzel merged commit 91280fc into master Nov 30, 2021
@sshanzel sshanzel deleted the DD-229-refactor-tooltips branch November 30, 2021 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants