-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
// should not render the tooltip inside of the main div\ | ||
const mainContainer = container.querySelector('#main'); | ||
expect( | ||
mainContainer.querySelector("[data-testid='tooltip-custom-body']") |
There was a problem hiding this comment.
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']") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
src/components/tooltip/tooltip.js
Outdated
@@ -51,6 +59,14 @@ class Tooltip extends React.Component { | |||
} | |||
return null; | |||
}, | |||
PopperWrapperComponent: (props, propName) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! 👌
src/components/tooltip/tooltip.js
Outdated
@@ -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 = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing stuff 🥇
There was a problem hiding this 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.
Summary
Adds another
component
prop to theTooltip
component,TooltipWrapperComponent
. This can be used along withReactDOM.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 ofdocument.body
.Before
After