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): add option for tooltip wrapper #560

Merged
merged 5 commits into from
Feb 21, 2019

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Feb 21, 2019

Summary

Adds another component prop to the Tooltip component, TooltipWrapperComponent. This can be used along with ReactDOM.renderPortal to render the Tooltip to another place inside of the document. This is useful when dealing with virtualized items, like our table.

The following example uses a simple TooltipWrapperComponent that renders the portal as a descendent of document.body.

Before

before

After

after

// should not render the tooltip inside of the main div\
const mainContainer = container.querySelector('#main');
expect(
mainContainer.querySelector("[data-testid='tooltip-custom-body']")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a cool part about react-testing-library

// should render the tooltip inside of the portal
const portalContainer = container.querySelector('#portal-id');
expect(
portalContainer.querySelector("[data-testid='tooltip-custom-body']")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@@ -51,6 +59,14 @@ class Tooltip extends React.Component {
}
return null;
},
PopperWrapperComponent: (props, propName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 aren't we leaking implementation details with this name? The fact that we use popper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 yeah makes sense.

How about TooltipWrapperComponent?

@montezume montezume changed the title feat(tooltip): add option for popper wrapper feat(tooltip): add option for tooltip wrapper Feb 21, 2019
Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Nice one! 👌

@@ -180,7 +196,8 @@ class Tooltip extends React.Component {

const WrapperComponent = this.props.components.WrapperComponent || Wrapper;
const BodyComponent = this.props.components.BodyComponent || Body;

const TooltipWrapper =
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: to keep it consistent with the other variable names

  • rename variable TooltipWrapper --> TooltipWrapperComponent
  • rename component TooltipWrapperComponent --> TooltipWrapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Contributor

@qmateub qmateub left a comment

Choose a reason for hiding this comment

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

Amazing stuff 🥇

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Nicey nice. Thanks for the renaming.

@montezume montezume merged commit 4f5ff38 into master Feb 21, 2019
@montezume montezume deleted the ml-tooltip-with-table branch February 21, 2019 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants