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): expose Popper.js modifiers #1054

Merged
merged 1 commit into from
Sep 11, 2019
Merged

Conversation

pa3
Copy link
Contributor

@pa3 pa3 commented Sep 10, 2019

Popper.js, which our Tooltip relies on, provides a powerful way of altering tooltip behaviour by using so called modifiers: https://popper.js.org/popper-documentation.html#modifiers

In some tricky cases they can really help properly place your tooltip. Instead of extending Tooltip's API case-by-case when facing them (at the moment I need a way to provide preventOverflow modifier to achieve proper positioning of a tooltip in MC), I suggest just expose all of them at once.

By doing this, we are paying a price of leaking internal implementation details of Tooltip component, but on the other hand leveraging lot of power of the underlying lib.

@pa3 pa3 requested a review from montezume September 10, 2019 15:28
@pa3 pa3 force-pushed the pa3-popper-modifiers branch from 20b156a to 71ad8b9 Compare September 10, 2019 15:30
Copy link
Contributor

@montezume montezume left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@tdeekens
Copy link
Contributor

Interesting. So we are are fine with "leaking" what our component library uses underneath to the consumers. As an alternative to wrapping that API in a minimal way to encapsulate it?

@montezume
Copy link
Contributor

@tdeekens yes that's exactly what @pa3 brought up, but I couldn't see a good way of getting around this...

@tdeekens
Copy link
Contributor

Ah okay cool so it was a concern before. Curious now (I trust your judgement) what is the exact case where we need more control over the positioning?

@pa3
Copy link
Contributor Author

pa3 commented Sep 11, 2019

@tdeekens I don't like this leaking as well, but as @montezume said, looks like it the least pain in the ass for everyone.

My specific use-case, why I need it is showing tooltip inside scrollable container, so that it will be shown outside of that container. Looks like the popper is smart enough to figure out that element with a tooltip is a child of scrollable container and tries to keep it inside of parent's boundaries.

I created a branch with a story reproducing my use-case: https://github.com/commercetools/ui-kit/blob/pa3-tooltip-issue/src/components/tooltip/tooltip-bug.story.js

Too save you some time with running this example on your machine, let me provide some screenshots, illustrating the intent. This is a simplified layout we have in one of the pages of MC:

Screenshot 2019-09-11 at 09 44 11

Right column is considered a scrollable container by Popper. What I want to see when hover on the button:

Screenshot 2019-09-11 at 09 44 48

And I didn't find a way to achieve this without providing way to set modifiers. Without specifying modifiers tooltip is show like that:

Screenshot 2019-09-11 at 09 44 03

@tdeekens
Copy link
Contributor

Thanks for the illustration. Was easy to grasp the issue with it!

Generally I agree that exposing poppers API through our Tooltip implementation is the least hassle. We just have to buy into the obvious trade-off that:

  1. Any breaking change to popper in that part of its API is a breaking release for UIKit
  2. If at any point in the future we decide to remove popper it will a) be painful and b) likely be breaking for UIKit

Accepting those drawbacks comes at the benefit of being less a pain of adding it now.

What I am generally wondering is:

  1. Do we need to expose the full modifiers API or can be expose just the subset we need right now
    • To reduce the surface area of breaking changes as we never know who and how the tooltip will be used
  2. I presume loads if messing with TooltipWrapperComponent and portals has happened to get the placement through a portal in another part of the document which was deemed to be even more nasty

@montezume
Copy link
Contributor

Yeah, I guess just exposing the required modification makes sense for now. Then if we make changes to the underlying implementation of Tooltip, it will be a lot easier to keep track of the breaking changes...

@kodiakhq kodiakhq bot merged commit 9ab8072 into master Sep 11, 2019
@kodiakhq kodiakhq bot deleted the pa3-popper-modifiers branch September 11, 2019 11:31
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.

3 participants